This application allows users to share their screens through a web interface. It consists of two main components: the Sender and the Receiver. The Sender initiates the screen sharing, and the Receiver views the shared screen.
- Screen Sharing: The Sender can share their screen by clicking a button.
- WebRTC Connection: Establishes a WebRTC connection between the Sender and Receiver to transmit the screen stream.
- WebSocket Signaling: Uses WebSocket for signaling messages to establish and manage the WebRTC connection.
- Node.js installed
- A WebSocket server for signaling
-
Clone the repository:
git clone https://github.com/YumeAyai/webrtc.git cd webrtc
-
Install dependencies:
npm install
-
Run:
npm run server # run ws server npm run dev # run demo
- Open the application in a browser.
- The Sender should click the "Start Screen Sharing" button to initiate screen sharing.
- The Sender then clicks the "Send Screen" button to send the screen stream to the Receiver.
- The Receiver will automatically display the shared screen once it receives the stream.
- startScreenSharing: Requests access to the user's screen and sets the video stream.
- createOffer: Creates an offer to start the WebRTC connection and sends it to the Receiver through WebSocket.
- handleReceiveAnswer: Sets the remote description when an answer is received from the Receiver.
- handleReceiveIceCandidate: Adds ICE candidates to establish the WebRTC connection.
- handleReceiveOffer: Sets the remote description and creates an answer when an offer is received from the Sender.
- handleReceiveIceCandidate: Adds ICE candidates to establish the WebRTC connection.
- ontrack: Sets the received video stream to the video element.
This project is licensed under the MIT License.
该应用程序允许用户通过网络界面共享他们的屏幕。它包含两个主要组件:发送端和接收端。发送端发起屏幕共享,接收端查看共享的屏幕。
- 屏幕共享: 发送端可以通过点击按钮共享他们的屏幕。
- WebRTC 连接: 建立发送端和接收端之间的 WebRTC 连接,以传输屏幕流。
- WebSocket 信令: 使用 WebSocket 进行信令消息的传递,以建立和管理 WebRTC 连接。
- 已安装 Node.js
- 一个用于信令的 WebSocket 服务器
-
克隆仓库:
git clone https://github.com/YumeAyai/webrtc.git cd webrtc
-
安装依赖:
npm install
-
运行:
npm run server # 启动信令服务器 npm run dev # 启动演示
- 在浏览器中打开应用程序。
- 发送端点击“开始屏幕共享”按钮以启动屏幕共享。
- 发送端点击“发送屏幕”按钮将屏幕流发送到接收端。
- 接收端接收到流后将自动显示共享的屏幕。
- startScreenSharing: 请求访问用户的屏幕并设置视频流。
- createOffer: 创建一个 offer 以启动 WebRTC 连接,并通过 WebSocket 将其发送到接收端。
- handleReceiveAnswer: 接收到来自接收端的 answer 时,设置远程描述。
- handleReceiveIceCandidate: 添加 ICE 候选者以建立 WebRTC 连接。
- handleReceiveOffer: 接收到来自发送端的 offer 时,设置远程描述并创建 answer。
- handleReceiveIceCandidate: 添加 ICE 候选者以建立 WebRTC 连接。
- ontrack: 将接收到的视频流设置到视频元素。
该项目是根据 MIT 许可证授权的。