mirror of
https://github.com/andreili/camera-streamer.git
synced 2025-08-23 19:34:07 +02:00
Previously, there was no way to detect if WebRTC clients were still connected to the stream. This lead to the RTC streams being kept open indefinitely when clients focibly closed the stream. This can happen with Chrome, Edge, Safari, etc when the tab is closed or on mobile devices when the screen is locked or browser closed. This change adds a data channel to the stream and requires users to respond to ping requests. While sending a frame the ping might be sent to the client. If clients do not respond to these ping requests before the timeout duration the stream is closed and the client is removed from the server. This causes the client to reinitiate the connection. The timeout defaults to 30 seconds. The client needs to send `keepAlive: true` as part of webrtc request. On the received `ping` send back the `pong` over data-channel.