开发者

WebSockets API - Persist connections or resource/socket identification possible?

开发者 https://www.devze.com 2023-02-26 10:57 出处:网络
Does anybody know if it is possible to capture something like a resource or connection id using the HTML WebSocket specification so that you can re-use or reopen a connection from a previous page.Use

Does anybody know if it is possible to capture something like a resource or connection id using the HTML WebSocket specification so that you can re-use or reopen a connection from a previous page. Use case would be I establish a web socket connection while on one page, then the user navigates to a separate page but I don't want to re-establish a new connection but rather use the previous one. You may be asking 'why let the user completely refresh the page?' and it's a legitimate question but not for this use case :) 开发者_C百科

Thanks.


If you open a new tab in your browser context and the original is still connected you can use for example HTML5 storage to pass messages between tabs. With this approach only the first tab will be connected with server through WebSockets and communication can be stored to local storage. Other tabs would handle storage events and thus they don't need to be connected.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号