Examples to use WebRTC with rtc-socket-connector-client and rtc-socket-connector-server.
Examples
- WebRTC Connection
- Data Channel (Chat)
- Media Stream (Video chat)
- File Transfer
- Install dependencies
yarn
- Start server
yarn start:server
- Start Example Page
yarn start:<PAGE NAME>
Establish connection using RTCPeerConnection.
See change of connection status in console.
Run project
yarn start:web-rtc-connections
-
Open two browsers.
-
Access http://localhost:1234
-
Check socket id on the web page.
-
Put socket id of the other browser to input box beside "Target ID"
Open console to see the change of state.
You can see the messages below if the socket id is valid to connect.
connectionstatechange::: socket id:<SOCKET ID> state:connecting
connectionstatechange::: socket id:<SOCKET ID> state:connected
Close or refresh one of opened browsers to close connection. You can see the state change when the connection is lost in console.
connectionstatechange::: socket id:<SOCKET ID> state:disconnected
connectionstatechange::: socket id:<SOCKET ID> state:failed
Chat with DataChannel.
Run project
yarn start:data-channel
-
Open two browsers.
-
Access http://localhost:1234
-
Check socket id on the web page.
-
Put socket id of the other browser to input box beside "Target ID"
-
Click CONNECT button. And then SEND button will be enabled to click.
-
Put message and click SEND button to send messages.
Video chat with WebRTC.
Run project
yarn start:media-stream
-
Open two browsers.
-
Access http://localhost:1234
-
Check socket id on the web page.
-
Put socket id of the other browser to input box beside "Target ID"
-
Click CONNECT button. And then you will see the screen from the other browser on the video element on the right side.
Connect two browser with WebRTC.
Upload files and download uploaded files.
Run project
yarn start:file-transfer
-
Open two browsers.
-
Access http://localhost:1234
-
Check socket id on the web page.
-
Put socket id of the other browser to input box beside "Target ID"
-
Click CONNECT button. And then you will see the screen from the other browser on the video element on the right side.
-
Choose file to upload and click UPLOAD button to upload file.
-
Click DOWNLOAD button to download a file in File List.