ITADN

Revision 0.8.5

#26Pull Requestsinclairzx81 创建于 2024-08-11已合并
S
sinclairzx81commented
This PR adds a hub terminate message that can be used to terminate the local and remote RTCPeerConnection in instances where the RTCPeerConnection enters into an inconsistent state. Inconsistent connection states can be observed in Firefox where data channels created locally may not observed by the remote RTCPeerConnection. In smoke, this is usually detected by protocol handlers not receiving responses from the remote channel in instances where the local channel has opened. Once a peer connection has entered into a inconsistent state, no more connections can be created and the only recourse is to signal peer connection termination via the Hub. This PR also implements better timeout handling in `fetch` specifically, additional timeout handling might be good for other protocol handlers, but will defer for a subsequent PR. ### Handling Firefox Issues The following shows how to terminate connections in case of error. ```typescript import { Network } from '@sinclair/smoke' const { Http, WebRtc } = new Network({ hub: ... }) // Assume we have a listener on localhost Http.listen({ port: 5000 }, response => new Response('hello')) // In Firefox, it is possible for the following to fail in instance the connection has become unstable. try { const message = await Http.fetch('http://localhost:5000/index.html').then((x) => x.text()) console.log(message) } catch (error) { console.log('error') // terminate local and remote peer connections await WebRtc.terminate('localhost') } ``` The above should allow subsequent fetches to work as smoke will reconstruct local and remote peers on next fetch. Implementations may wrap the above in a retry loop.
合并状态:已合并 合并于 2024-08-11 关闭于 2024-08-11 0 条评论