diff --git a/couple.js b/couple.js index 290b7b3..1c98a95 100644 --- a/couple.js +++ b/couple.js @@ -90,6 +90,11 @@ function couple(pc, targetId, signaller, opts) { signaller.removeListener('sdp', handleSdp); signaller.removeListener('candidate', handleCandidate); signaller.removeListener('negotiate', handleNegotiateRequest); + + // remove listeners (version >= 5) + signaller.removeListener('message:sdp', handleSdp); + signaller.removeListener('message:candidate', handleCandidate); + signaller.removeListener('message:negotiate', handleNegotiateRequest); } function handleCandidate(data) { @@ -195,9 +200,14 @@ function couple(pc, targetId, signaller, opts) { signaller.on('sdp', handleSdp); signaller.on('candidate', handleCandidate); + // listeners (signaller >= 5) + signaller.on('message:sdp', handleSdp); + signaller.on('message:candidate', handleCandidate); + // if this is a master connection, listen for negotiate events if (isMaster) { signaller.on('negotiate', handleNegotiateRequest); + signaller.on('message:negotiate', handleNegotiateRequest); // signaller >= 5 } // when the connection closes, remove event handlers diff --git a/package.json b/package.json index 9880703..8884122 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,9 @@ "messenger-memory": "^1.2.0", "peerpair": "^1.0.0", "rtc-media": "^1", - "rtc-signaller": "^3.1.1", - "rtc-switchboard": "^1.2.1", + "rtc-signaller": "^5.0.0", + "rtc-switchboard": "^2.0.0", + "rtc-switchboard-messenger": "^1.0.0", "tape": "^3.0.1", "testling": "^1", "uuid": "^2.0.1", @@ -46,4 +47,4 @@ "files": "test/all.js", "server": "test/server.js" } -} \ No newline at end of file +} diff --git a/test/capture-close-localonly.js b/test/capture-close-localonly.js index 38195da..9990ecb 100644 --- a/test/capture-close-localonly.js +++ b/test/capture-close-localonly.js @@ -1,5 +1,6 @@ var couple = require('../couple'); var signaller = require('rtc-signaller'); +var messenger = require('./helpers/messenger'); var test = require('tape'); var rtc = require('..'); var conns = []; @@ -22,8 +23,8 @@ test('create peer connections', function(t) { test('create signallers', function(t) { t.plan(2); - t.ok(signallers[0] = signaller(location.origin), 'created signaller a'); - t.ok(signallers[1] = signaller(location.origin), 'created signaller b'); + t.ok(signallers[0] = signaller(messenger), 'created signaller a'); + t.ok(signallers[1] = signaller(messenger), 'created signaller b'); }); test('announce signallers', function(t) { @@ -93,4 +94,4 @@ test('release references', function(t) { monitors = []; dcs = []; t.pass('done'); -}); \ No newline at end of file +}); diff --git a/test/capture-close-signaller.js b/test/capture-close-signaller.js index 3e50d33..bc33f5c 100644 --- a/test/capture-close-signaller.js +++ b/test/capture-close-signaller.js @@ -1,6 +1,7 @@ var couple = require('../couple'); var cleanup = require('../cleanup'); var signaller = require('rtc-signaller'); +var messenger = require('./helpers/messenger'); var test = require('tape'); var rtc = require('..'); var conns = []; @@ -24,10 +25,10 @@ module.exports = function(suiteName, ids) { test(suiteName + ': create signallers', function(t) { t.plan(4); - t.ok(signallers[0] = signaller(location.origin, { id: ids[0] }), 'created signaller a'); + t.ok(signallers[0] = signaller(messenger, { id: ids[0] }), 'created signaller a'); t.equal(signallers[0].id, ids[0], 'id assigned'); - t.ok(signallers[1] = signaller(location.origin, { id: ids[1] }), 'created signaller b'); + t.ok(signallers[1] = signaller(messenger, { id: ids[1] }), 'created signaller b'); t.equal(signallers[1].id, ids[1], 'id assigned'); }); @@ -113,4 +114,4 @@ module.exports = function(suiteName, ids) { dcs = []; t.pass('done'); }); -}; \ No newline at end of file +}; diff --git a/test/capture-close.js b/test/capture-close.js index ce5f0d1..c3320d4 100644 --- a/test/capture-close.js +++ b/test/capture-close.js @@ -1,5 +1,6 @@ var couple = require('../couple'); var signaller = require('rtc-signaller'); +var messenger = require('./helpers/messenger'); var test = require('tape'); var rtc = require('..'); var conns = []; @@ -22,8 +23,8 @@ test('create peer connections', function(t) { test('create signallers', function(t) { t.plan(2); - t.ok(signallers[0] = signaller(location.origin), 'created signaller a'); - t.ok(signallers[1] = signaller(location.origin), 'created signaller b'); + t.ok(signallers[0] = signaller(messenger), 'created signaller a'); + t.ok(signallers[1] = signaller(messenger), 'created signaller b'); }); test('announce signallers', function(t) { @@ -92,4 +93,4 @@ test('release references', function(t) { monitors = []; dcs = []; t.pass('done'); -}); \ No newline at end of file +}); diff --git a/test/coupling-constraints.js b/test/coupling-constraints.js index bff5a83..b0ba5d0 100644 --- a/test/coupling-constraints.js +++ b/test/coupling-constraints.js @@ -1,5 +1,6 @@ var couple = require('../couple'); var signaller = require('rtc-signaller'); +var messenger = require('./helpers/messenger'); var test = require('tape'); var rtc = require('..'); var conns = []; @@ -22,8 +23,8 @@ test('create peer connections', function(t) { test('create signallers', function(t) { t.plan(2); - t.ok(signallers[0] = signaller(location.origin), 'created signaller a'); - t.ok(signallers[1] = signaller(location.origin), 'created signaller b'); + t.ok(signallers[0] = signaller(messenger), 'created signaller a'); + t.ok(signallers[1] = signaller(messenger), 'created signaller b'); }); test('announce signallers', function(t) { @@ -95,4 +96,4 @@ test('release references', function(t) { monitors = []; dcs = []; t.pass('done'); -}); \ No newline at end of file +}); diff --git a/test/coupling-customid.js b/test/coupling-customid.js index 9dc80e0..bad0f1b 100644 --- a/test/coupling-customid.js +++ b/test/coupling-customid.js @@ -1,5 +1,6 @@ var couple = require('../couple'); var signaller = require('rtc-signaller'); +var messenger = require('./helpers/messenger'); var test = require('tape'); var rtc = require('..'); var conns = []; @@ -22,10 +23,10 @@ test('create peer connections', function(t) { test('create signallers (using custom ids)', function(t) { t.plan(4); - t.ok(signallers[0] = signaller(location.origin, { id: 1 }), 'created signaller a (id = 1)'); + t.ok(signallers[0] = signaller(messenger, { id: 1 }), 'created signaller a (id = 1)'); t.equal(signallers[0].id, 1, 'id === 1'); - t.ok(signallers[1] = signaller(location.origin, { id: 2 }), 'created signaller b'); + t.ok(signallers[1] = signaller(messenger, { id: 2 }), 'created signaller b'); t.equal(signallers[1].id, 2, 'id === 2'); }); diff --git a/test/coupling-reactive-doubleanswer.js b/test/coupling-reactive-doubleanswer.js index ef6efbf..fe117a0 100644 --- a/test/coupling-reactive-doubleanswer.js +++ b/test/coupling-reactive-doubleanswer.js @@ -1,5 +1,6 @@ var couple = require('../couple'); var signaller = require('rtc-signaller'); +var messenger = require('./helpers/messenger'); var test = require('tape'); var rtc = require('..'); var conns = []; @@ -22,8 +23,8 @@ test('create peer connections', function(t) { test('create signallers', function(t) { t.plan(2); - t.ok(signallers[0] = signaller(location.origin), 'created signaller a'); - t.ok(signallers[1] = signaller(location.origin), 'created signaller b'); + t.ok(signallers[0] = signaller(messenger), 'created signaller a'); + t.ok(signallers[1] = signaller(messenger), 'created signaller b'); }); test('announce signallers', function(t) { diff --git a/test/coupling-reactive-randomdelay.js b/test/coupling-reactive-randomdelay.js index 8140e15..d46c1b3 100644 --- a/test/coupling-reactive-randomdelay.js +++ b/test/coupling-reactive-randomdelay.js @@ -1,5 +1,6 @@ var couple = require('../couple'); var signaller = require('rtc-signaller'); +var messenger = require('./helpers/messenger'); var test = require('tape'); var rtc = require('..'); var conns = []; @@ -9,13 +10,10 @@ var scope = []; var messengers = []; var dcs = []; var roomId = require('uuid').v4(); -var messenger = require('messenger-memory'); +var messenger = require('./helpers/messenger'); var times = require('whisk/times'); var scope = []; -var messengers = [ - messenger({ delay: Math.random() * 500, scope: scope }), - messenger({ delay: Math.random() * 500, scope: scope }) -]; +var messengers = [ messenger, messenger ]; // require('cog/logger').enable('*'); diff --git a/test/coupling.js b/test/coupling.js index 3c15be9..56febc5 100644 --- a/test/coupling.js +++ b/test/coupling.js @@ -1,5 +1,6 @@ var couple = require('../couple'); var signaller = require('rtc-signaller'); +var messenger = require('./helpers/messenger'); var test = require('tape'); var rtc = require('..'); var conns = []; @@ -22,8 +23,8 @@ test('create peer connections', function(t) { test('create signallers', function(t) { t.plan(2); - t.ok(signallers[0] = signaller(location.origin), 'created signaller a'); - t.ok(signallers[1] = signaller(location.origin), 'created signaller b'); + t.ok(signallers[0] = signaller(messenger), 'created signaller a'); + t.ok(signallers[1] = signaller(messenger), 'created signaller b'); }); test('announce signallers', function(t) { diff --git a/test/helpers/messenger.js b/test/helpers/messenger.js new file mode 100644 index 0000000..cd3d5e9 --- /dev/null +++ b/test/helpers/messenger.js @@ -0,0 +1 @@ +module.exports = require('rtc-switchboard-messenger')(location.origin); diff --git a/test/subtest-reactive-randomdelay-streams.js b/test/subtest-reactive-randomdelay-streams.js index addbbb7..5524c16 100644 --- a/test/subtest-reactive-randomdelay-streams.js +++ b/test/subtest-reactive-randomdelay-streams.js @@ -1,9 +1,9 @@ var couple = require('../couple'); var signaller = require('rtc-signaller'); +var messenger = require('./helpers/messenger'); var MediaStream = require('../detect')('MediaStream'); var test = require('tape'); var rtc = require('..'); -var messenger = require('messenger-memory'); var times = require('whisk/times'); module.exports = function(name, contexts, opts) { @@ -11,7 +11,6 @@ module.exports = function(name, contexts, opts) { var signallers = []; var monitors = []; var scope = []; - var messengers = []; var dcs = []; var scope = []; @@ -22,17 +21,10 @@ module.exports = function(name, contexts, opts) { var maxDelay = ((opts || {}).maxDelay || 500) - minDelay; var streamCount = (opts || {}).streamCount || 10; - var messengers = [ - messenger({ delay: randomDelay, scope: scope }), - messenger({ delay: randomDelay, scope: scope }) - ]; - function randomDelay() { return minDelay + (Math.random() * maxDelay); } - require('cog/logger').enable('rtc-validator'); - test(name + ': create peer connections', function(t) { t.plan(2); @@ -42,7 +34,9 @@ module.exports = function(name, contexts, opts) { test(name + ': create signallers', function(t) { t.plan(2); - signallers = messengers.map(signaller); + signallers = times(2).map(function() { + return signaller(messenger); + }); t.ok(signallers[0], 'created signaller a'); t.ok(signallers[1], 'created signaller b'); }); diff --git a/test/subtest-reactive.js b/test/subtest-reactive.js index 8a044b0..d1ac319 100644 --- a/test/subtest-reactive.js +++ b/test/subtest-reactive.js @@ -1,5 +1,6 @@ var couple = require('../couple'); var signaller = require('rtc-signaller'); +var messenger = require('./helpers/messenger'); var test = require('tape'); var rtc = require('..'); var times = require('whisk/times'); @@ -33,8 +34,8 @@ module.exports = function(name, opts) { test(name + ': create signallers', function(t) { t.plan(2); - t.ok(signallers[0] = signaller(location.origin), 'created signaller a'); - t.ok(signallers[1] = signaller(location.origin), 'created signaller b'); + t.ok(signallers[0] = signaller(messenger), 'created signaller a'); + t.ok(signallers[1] = signaller(messenger), 'created signaller b'); }); test(name + ': announce signallers', function(t) {