-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35444f3
commit 4bf5471
Showing
12 changed files
with
42 additions
and
835 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,21 @@ | ||
# Examples | ||
|
||
## client | ||
* You can use client example project to test WebRTC Data Channels with WebSocket signaling. | ||
## client-server | ||
* You can use client-server example project to test WebRTC Data Channels with WebSocket signaling. | ||
* It uses same logic of [libdatachannel/examples/client](https://github.com/paullouisageneau/libdatachannel/tree/master/examples) project. | ||
|
||
## web | ||
* Copied from [libdatachannel/examples/web](https://github.com/paullouisageneau/libdatachannel/tree/master/examples) | ||
* Contains an equivalent implementation for web browsers and a node.js signaling server | ||
* Contains an equivalent implementation for a node.js signaling server | ||
|
||
## How to Use? | ||
* Start ws signaling server; | ||
* cd examples/web | ||
* npm i | ||
* node server.js | ||
* Start answerer; | ||
* Prepare Project | ||
* cd examples/client | ||
* npm i | ||
* Start ws signaling server; | ||
* node signaling-server.js | ||
* Start answerer (On a new Console); | ||
* node client.js | ||
* Note local ID | ||
* Start Offerer; | ||
* cd examples/client | ||
* npm i | ||
* Start Offerer (On a new Console); | ||
* node client.js | ||
* Enter answerer ID | ||
* Enter answerer ID | ||
|
||
> You can also use [libdatachannel/examples/client](https://github.com/paullouisageneau/libdatachannel/tree/master/examples) project's client & signaling server |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const WebSocket = require('ws'); | ||
|
||
const clients = {}; | ||
|
||
const wss = new WebSocket.Server({ port: 8000 }); | ||
|
||
wss.on('connection', (ws, req) => { | ||
const id = req.url.replace('/', '') | ||
console.log(`New Connection from ${id}`); | ||
|
||
clients[id] = ws; | ||
ws.on('message', (buffer) => { | ||
let msg = JSON.parse(buffer); | ||
let peerId = msg.id; | ||
let peerWs = clients[peerId]; | ||
|
||
console.log(`Message from ${id} to ${peerId} : ${buffer}`); | ||
if (!peerWs) | ||
return console.error(`Can not find peer with ID ${peerId}`); | ||
|
||
msg.id = id; | ||
peerWs.send(JSON.stringify(msg)); | ||
|
||
}); | ||
|
||
ws.on('close', () => { | ||
console.log(`${id} disconected`); | ||
delete clients[id]; | ||
}); | ||
}); | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.