Skip to content

Commit

Permalink
new signaling server
Browse files Browse the repository at this point in the history
  • Loading branch information
murat-dogan committed Jul 28, 2020
1 parent 35444f3 commit 4bf5471
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 835 deletions.
26 changes: 11 additions & 15 deletions examples/README.md
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.
31 changes: 31 additions & 0 deletions examples/client-server/signaling-server.js
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];
});
});

339 changes: 0 additions & 339 deletions examples/web/LICENSE

This file was deleted.

23 changes: 0 additions & 23 deletions examples/web/index.html

This file was deleted.

119 changes: 0 additions & 119 deletions examples/web/package-lock.json

This file was deleted.

23 changes: 0 additions & 23 deletions examples/web/package.json

This file was deleted.

Loading

0 comments on commit 4bf5471

Please sign in to comment.