diff --git a/examples/slave.js b/examples/slave.js index da229a9..94942a5 100644 --- a/examples/slave.js +++ b/examples/slave.js @@ -18,11 +18,11 @@ new enslavism.Slave('ws://localhost:8081', { slave.on('connection', clCo => { clCo.on('datachannel', dc => { console.log('new dataChannel'); - dc.addEventListener('open', ev => { + dc.on('open', ev => { console.log('data channel open', ev); dc.send('hallo welt'); }); - dc.addEventListener('message', msg => { + dc.on('message', msg => { console.log('Received message:', msg.data); }); }); diff --git a/package.json b/package.json index 496d659..a4fc104 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "game" ], "dependencies": { - "wrtc": "0.0.x", + "electron-webrtc": "0.2.x", "ws": "1.x", "ipaddr.js": "1.x", "cookie": "0.x", diff --git a/readme.md b/readme.md index bc8753b..b309c19 100644 --- a/readme.md +++ b/readme.md @@ -20,13 +20,13 @@ Basically, you have: ## The point -* transmiting encrypted data without having to register a SSL certificate (unlike secure WebSockets) +* transmitting encrypted data without having to register a SSL certificate (unlike secure WebSockets) * configurable reliability (unreliable is fast!) * configurable delivery ordering (unordered is fast!) * an architecture that allows browser clients to choose which independent server to connect to (useful for games) -## Examples +## Try the examples ```sh $ npm install @@ -34,6 +34,8 @@ $ node example/master.js $ node example/slave.js # in a different terminal ``` +Enslavism depends [on](https://github.com/mappum/electron-webrtc/pull/91) [patches](https://github.com/mappum/electron-webrtc/pull/92) that aren't yet merged into [electron-webrtc](https://github.com/mappum/electron-webrtc). + Now open your browser at `http://localhost:8081/`. @@ -276,11 +278,11 @@ Triggered each time a client creates a datachannel. clientCo.on('datachannel', dc => { console.log('new dataChannel', dc); - dc.addEventListener('open', ev => { // triggered once the datachannel is open + dc.on('open', ev => { // triggered once the datachannel is open console.log('data channel open', ev); dc.send('hallo welt'); }); - dc.addEventListener('message', msg => { // triggered when receiving a message from a client + dc.on('message', msg => { // triggered when receiving a message from a client console.log(msg); }); }); diff --git a/server/client_connection.js b/server/client_connection.js index cc3a2be..c9ab2c6 100644 --- a/server/client_connection.js +++ b/server/client_connection.js @@ -1,7 +1,7 @@ import * as proto from '../shared/proto.js'; const EventEmitter = require('events'), - webrtc = require('wrtc'); + webrtc = require('electron-webrtc')(); export default class ClientConnection extends EventEmitter { constructor(id, sdp, slave) { @@ -12,13 +12,13 @@ export default class ClientConnection extends EventEmitter { this.dataChannels = {}; this.clientCon = new webrtc.RTCPeerConnection(); - this.clientCon.onicecandidate = (iceEv) => { + this.clientCon.on('icecandidate', iceEv => { if (!iceEv.candidate) return; this.slave.ws.send(proto.iceCandidateToClient.serialize(id, iceEv.candidate)); - }; - this.clientCon.ondatachannel = ev => { + }); + this.clientCon.on('datachannel', ev => { this.emit('datachannel', ev.channel); - }; + }); let desc = new webrtc.RTCSessionDescription({ type: 'offer', diff --git a/server/slave.js b/server/slave.js index 211fa38..f346e5a 100644 --- a/server/slave.js +++ b/server/slave.js @@ -3,7 +3,7 @@ import * as convert from './convert.js'; import ClientConnection from './client_connection.js'; const EventEmitter = require('events'), - webrtc = require('wrtc'), + webrtc = require('electron-webrtc')(), WebSocket = require('ws'), cookie = require('cookie'); @@ -50,8 +50,7 @@ export default class Slave extends EventEmitter { let {id, sdpMid, sdpMLineIndex, candidate} = proto.iceCandidateFromClient.deserialize(msg); let receiver = this.findClient(id); if (receiver !== undefined) { - receiver.clientCon.addIceCandidate(new webrtc.RTCIceCandidate({candidate, sdpMid, sdpMLineIndex})) - .catch(e => { + receiver.clientCon.addIceCandidate(new webrtc.RTCIceCandidate({candidate, sdpMid, sdpMLineIndex})).catch(e => { console.error('adding ICE candidate: failure', e, id, sdpMid, sdpMLineIndex, candidate); }); }