{"id":22229580,"url":"https://github.com/msusman1/webrtc-server","last_synced_at":"2026-04-14T06:33:46.820Z","repository":{"id":259869856,"uuid":"874609766","full_name":"msusman1/webrtc-server","owner":"msusman1","description":"WebRTC Signaling server Implemented using Nodejs Socket io","archived":false,"fork":false,"pushed_at":"2025-02-12T13:51:38.000Z","size":41,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-04T20:43:19.061Z","etag":null,"topics":["socket-io","webrtc","webrtc-signaling","webrtc-video","websocket"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/msusman1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-18T06:26:40.000Z","updated_at":"2025-02-12T13:51:42.000Z","dependencies_parsed_at":"2024-10-28T14:45:25.757Z","dependency_job_id":"d970e847-aebb-474f-8e26-e67ea01248ed","html_url":"https://github.com/msusman1/webrtc-server","commit_stats":null,"previous_names":["msusman1/webrtc-server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/msusman1/webrtc-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msusman1%2Fwebrtc-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msusman1%2Fwebrtc-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msusman1%2Fwebrtc-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msusman1%2Fwebrtc-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msusman1","download_url":"https://codeload.github.com/msusman1/webrtc-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msusman1%2Fwebrtc-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31785677,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T02:24:21.117Z","status":"ssl_error","status_checked_at":"2026-04-14T02:24:20.627Z","response_time":153,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["socket-io","webrtc","webrtc-signaling","webrtc-video","websocket"],"created_at":"2024-12-03T01:10:53.412Z","updated_at":"2026-04-14T06:33:46.805Z","avatar_url":"https://github.com/msusman1.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebRTC Server Demo \n\nThis is a signaling protocol implementation for a WebRTC client app. It allows users to join rooms, exchange video/audio streams, and send real-time chat messages through WebRTC and Socket.IO.\n\nYou can check the webrtc client demo implemented using Reactjs: [WebRTC Client Repo](https://github.com/msusman1/webrtc-client).\n\n## Features\n\n- Create and join rooms for WebRTC video/audio sessions\n- Real-time messaging within rooms\n- Handling WebRTC signaling for peer connection setup and media streaming\n\n## Tech Stack\n\n- **Node.js**\n- **Socket.IO**\n- **TypeScript**\n\n## Prerequisites\n\n1. Clone this repository and install dependencies:\n\n   ```bash\n   git clone https://github.com/your-username/webrtc-server.git\n   cd webrtc-server\n   npm install\n   ```\n\n2. Start the server:\n\n   ```bash\n   npm run start\n   ```\n\n3. Configure the client application to use this server as its signaling server (e.g., `SERVER_URL` in your client).\n\n## WebRTC Flow with Socket.IO\n\nThe signaling server facilitates the WebRTC peer-to-peer (P2P) connection setup by managing events for joining, messaging, leaving, and signaling (offers, answers, and ICE candidates). Here’s an overview of the events and flows in this server:\n\n### 1. Connection\n\nEach time a user connects to the server, a unique socket ID is assigned:\n\n```javascript\nio.on(\"connection\", (socket: Socket) =\u003e {\n    console.log(`Connection established: socket ID ${socket.id}`);\n    ...\n});\n```\n\n### 2. Joining a Room\n\nA user can join a room with the `join_room` event, providing their name and the room name. The server then:\n- Joins the user to the specified room.\n- Broadcasts a `user_joined` event to all users in the room to announce the new user.\n\n```javascript\nsocket.on(\"join_room\", (joinRequest: RoomJoinRequest) =\u003e {\n    socket.join(joinRequest.roomName);\n    const roomMessage = {\n        personName: joinRequest.personName,\n        roomName: joinRequest.roomName,\n        socketId: socket.id,\n    };\n    io.to(joinRequest.roomName).emit(\"user_joined\", roomMessage);\n});\n```\n\n### 3. Real-time Messaging\n\nUsers in a room can send messages using the `message` event, containing the sender's name, message content, and timestamp. The server broadcasts the message to all users in the room.\n\n```javascript\nsocket.on(\"message\", (roomMessageRequest: RoomMessageRequest) =\u003e {\n    const chatMessage = {\n        personName: roomMessageRequest.personName,\n        content: roomMessageRequest.content,\n        timestamp: new Date().toUTCString(),\n    };\n    io.to(roomMessageRequest.roomName).emit(\"message\", chatMessage);\n});\n```\n\n### 4. Leaving a Room\n\nWhen a user leaves, the `leave_room` event is triggered:\n- Removes the user from the room.\n- Notifies other users in the room via `user_left`.\n\n```javascript\nsocket.on(\"leave_room\", (roomLeaveRequest: RoomLeaveRequest) =\u003e {\n    socket.leave(roomLeaveRequest.roomName);\n    const roomMessage = {\n        personName: roomLeaveRequest.personName,\n        roomName: roomLeaveRequest.roomName,\n        socketId: socket.id,\n    };\n    socket.to(roomLeaveRequest.roomName).emit(\"user_left\", roomMessage);\n});\n```\n\n### 5. WebRTC Signaling Process\n\nThe signaling events for setting up WebRTC peer connections are handled as follows:\n\n#### Offer\n\nWhen a user initiates a connection, an `offer` is sent to the target peer:\n\n```javascript\nsocket.on(\"offer\", (offer: Offer) =\u003e {\n    socket.to(offer.toPeer).emit(\"offer\", offer);\n});\n```\n\n#### Answer\n\nIn response to an offer, the target peer sends an `answer` back to establish the connection:\n\n```javascript\nsocket.on(\"answer\", (answer: Answer) =\u003e {\n    socket.to(answer.toPeer).emit(\"answer\", answer);\n});\n```\n\n#### ICE Candidates\n\nTo establish the best possible connection path, both peers exchange ICE candidates:\n\n```javascript\nsocket.on(\"ice_candidate\", (iccCandidate: IccCandidate) =\u003e {\n    socket.to(iccCandidate.toPeer).emit(\"ice-candidate\", iccCandidate);\n});\n```\n\n### 6. Disconnect\n\nWhen a user disconnects, the `disconnect` event is logged for cleanup or reconnection handling.\n\n```javascript\nsocket.on(\"disconnect\", () =\u003e {\n    console.log(`Disconnected socket ID: ${socket.id}`);\n});\n```\n\n## Flow for Joining, Messaging, and Leaving\n\n1. **Join Room**:\n    - The client emits `join_room`.\n    - The server adds the client to the room and broadcasts `user_joined`.\n\n2. **Messaging**:\n    - The client emits `message`.\n    - The server broadcasts the message to the room.\n\n3. **Leaving Room**:\n    - The client emits `leave_room`.\n    - The server removes the client and broadcasts `user_left`.\n\n4. **WebRTC Signaling**:\n    - The server facilitates the P2P WebRTC connection by relaying offers, answers, and ICE candidates.\n\n## Current Issues\n\n- Remote video streams may not display in the client UI, despite being received through the `RTCPeerConnection.ontrack` event. Further troubleshooting is ongoing.\n\n## How to Contribute\n\n1. **Fork the repository**\n2. **Create a branch**: `git checkout -b my-new-feature`\n3. **Commit your changes**: `git commit -am 'Add some feature'`\n4. **Push to the branch**: `git push origin my-new-feature`\n5. **Create a new Pull Request**\n\n## License\n\nMIT License © 2023 msusman1\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsusman1%2Fwebrtc-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsusman1%2Fwebrtc-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsusman1%2Fwebrtc-server/lists"}