Given two devices, A and B, for enabling the sharing of streaming video from device A to device B. Let A be the host user who will share its video with client device B.
To solve this problem, we use WebRTC combined with WebSocket as the key to this implementation.
As shown in figure systematic of wertc, we define the steps of connectivity and streaming as belows:
- Hosts and clients connect to the WebSocket server.
- The host sends an offer to share streaming data with clients via the WebSocket server.
- The WebSocket server notifies all connected clients of available offers.
- Subsequently, when a client accepts to display streaming data, it sends an answer offer to the WebSocket server to establish a peer-to-peer connection and begins displaying the streaming data.
To handle the supportive server, we design a local websocket server listens on port 8282 with as below events:
- Host:
-
Install envs: This code was test on Nodejs v20.11.1
-
Run local server npm run start
-
Change address of host and client const ws = new WebSocket('ws://[your ip address]:8282'); example: const ws = new WebSocket('ws://192.168.55.106:8282');
-
Open host on: http://[your ip address]:8282/index.html
-
Open client on: http://[your ip address]:8282/indexs.html