azure-webpubsub
azure-webpubsub copied to clipboard
Support of ws sockets
At this moment the WebPubSub only supports the wss protocol. This is obviously the best way to setup a secure connection but in my business field there are devices out there that are not able to connect to wss endpoints due to the lack of local certificate stores on board of the devices.
Is there a way to connect to WebPubSub (now or in the future) to also have the ability to connect lightweight devices that are not capable of having a certificate store on board.
var url = client.GetClientAccessUri($"John", Protocol.Ws); var url = client.GetClientAccessUri($"John", Protocol.Wss);
This can be achieved by leveraging App Gateway.
FYI my way to setup the Application Gateway with Web PubSub:
- Create Application Gateway (AG1):
- Follow the steps and create a virtual network for it
- Create a new public IP address
- Add a backend pool, put DNS name of the Web PubSub in the target:
- Add a routing rule:
- Listener:
- Frontend IP: Public
- Others: default
- Backend targets:
- Add new HTTP settings
- Backend protocol: HTTPS
- Use well known CA certificate: yes
- Request time-out (seconds): set a larger number 1.Pay attention to this setting: this is the maximum allowed idle time for the WebSocket connection, that means, if there is no traffic inside your WebSocket connection for the Request time-out seconds, the App Gateway closes the connection 2. So if your app server broadcasts messages to the client every several seconds, you can set this time-out to for example 3600 seconds.
- Override with new host name: yes
- Override with specific domain name:
- And type the xxx.webpubsub.azure.com service name
- Others: default
- Add new HTTP settings
- Backend targets:
- Listener:
- When created, go to the Application Gateway settings, change the health probe path to
api/health
- To validate: open
http://<public-ip-of-AG1>
should return 403 andhttp://<public-ip-of-AG1>/api/health
should return 200
To change to C# server side to use the AG1:
var uriBuilder = new UriBuilder(url);
uriBuilder.Host = "<public-ip-of-AG1>";
uriBuilder.Scheme = "ws";
uriBuilder.Port = 80;
req.HttpContext.Response.Redirect(uriBuilder.Uri);