This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
A few BUGFIXES and new tests to cover those scenarios + multiple signalling servers! #89
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,9 +1,10 @@ | ||
'use strict' | ||
|
||
const gulp = require('gulp') | ||
const parallel = require('async/parallel') | ||
const sigServer = require('./src/sig-server') | ||
|
||
let sigS | ||
let sigS, sigS2 | ||
|
||
gulp.task('test:node:before', boot) | ||
gulp.task('test:node:after', stop) | ||
|
@@ -15,19 +16,47 @@ function boot (done) { | |
port: 15555, | ||
host: '127.0.0.1' | ||
} | ||
const options2 = { | ||
port: 15556, | ||
host: '127.0.0.1' | ||
} | ||
|
||
sigServer.start(options, (err, server) => { | ||
if (err) { | ||
throw err | ||
} | ||
sigS = server | ||
console.log('signalling on:', server.info.uri) | ||
done() | ||
}) | ||
parallel([ | ||
first, | ||
second | ||
], done) | ||
function first (cb) { | ||
sigServer.start(options, (err, server) => { | ||
if (err) { | ||
throw err | ||
} | ||
sigS = server | ||
console.log('signalling on:', server.info.uri) | ||
cb() | ||
}) | ||
} | ||
function second (cb) { | ||
sigServer.start(options2, (err, server) => { | ||
if (err) { | ||
throw err | ||
} | ||
sigS2 = server | ||
console.log('signalling 2 on:', server.info.uri) | ||
cb() | ||
}) | ||
} | ||
} | ||
|
||
function stop (done) { | ||
sigS.stop(done) | ||
parallel([ | ||
first, | ||
second | ||
], done) | ||
function first (cb) { | ||
sigS.stop(() => cb()) | ||
} | ||
function second (cb) { | ||
sigS2.stop(() => cb()) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be simpler async.forEach([first, second], (server) => server.stop(cb), done) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
|
||
require('aegir/gulp')(gulp) |
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 |
---|---|---|
|
@@ -40,8 +40,6 @@ function cleanUrlSIO (ma) { | |
|
||
class WebRTCStar { | ||
constructor () { | ||
this.maSelf = undefined | ||
|
||
this.sioOptions = { | ||
transports: ['websocket'], | ||
'force new connection': true | ||
|
@@ -60,7 +58,11 @@ class WebRTCStar { | |
callback = callback ? once(callback) : noop | ||
|
||
const intentId = (~~(Math.random() * 1e9)).toString(36) + Date.now() | ||
const sioClient = this.listenersRefs[Object.keys(this.listenersRefs)[0]].io | ||
const keys = Object.keys(this.listenersRefs) | ||
.filter((key) => cleanUrlSIO(ma) === cleanUrlSIO(multiaddr(key))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation here looks a tad weird, might reconsider making it more readable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
const listener = this.listenersRefs[keys[0]] | ||
if (!listener) return callback(new Error('signalling server not connected')) | ||
const sioClient = listener.io | ||
|
||
const spOptions = { | ||
initiator: true, | ||
|
@@ -73,11 +75,10 @@ class WebRTCStar { | |
|
||
const conn = new Connection(toPull.duplex(channel)) | ||
let connected = false | ||
|
||
channel.on('signal', (signal) => { | ||
sioClient.emit('ss-handshake', { | ||
intentId: intentId, | ||
srcMultiaddr: this.maSelf.toString(), | ||
srcMultiaddr: listener.ma.toString(), | ||
dstMultiaddr: ma.toString(), | ||
signal: signal | ||
}) | ||
|
@@ -130,13 +131,12 @@ class WebRTCStar { | |
listener.listen = (ma, callback) => { | ||
callback = callback ? once(callback) : noop | ||
|
||
this.maSelf = ma | ||
|
||
const sioUrl = cleanUrlSIO(ma) | ||
|
||
log('Dialing to Signalling Server on: ' + sioUrl) | ||
|
||
listener.io = io.connect(sioUrl, sioOptions) | ||
listener.ma = ma | ||
|
||
listener.io.once('connect_error', callback) | ||
listener.io.once('error', (err) => { | ||
|
@@ -148,10 +148,26 @@ class WebRTCStar { | |
listener.io.emit('ss-join', ma.toString()) | ||
listener.io.on('ws-handshake', incommingDial) | ||
listener.io.on('ws-peer', this._peerDiscovered) | ||
this.listenersRefs[ma.toString()] = listener | ||
listener.emit('listening') | ||
callback() | ||
}) | ||
|
||
listener.close = (callback) => { | ||
callback = callback ? once(callback) : noop | ||
|
||
listener.io.emit('ss-leave', ma.toString()) | ||
setImmediate(() => { | ||
listener.io.disconnect() | ||
listener.emit('close') | ||
callback() | ||
delete this.listenersRefs[ma.toString()] | ||
}) | ||
} | ||
listener.getAddrs = (callback) => { | ||
setImmediate(() => callback(null, [ma])) | ||
} | ||
|
||
function incommingDial (offer) { | ||
if (offer.answer || offer.err) { | ||
return | ||
|
@@ -188,22 +204,6 @@ class WebRTCStar { | |
} | ||
} | ||
|
||
listener.close = (callback) => { | ||
callback = callback ? once(callback) : noop | ||
|
||
listener.io.emit('ss-leave') | ||
|
||
setImmediate(() => { | ||
listener.emit('close') | ||
callback() | ||
}) | ||
} | ||
|
||
listener.getAddrs = (callback) => { | ||
setImmediate(() => callback(null, [this.maSelf])) | ||
} | ||
|
||
this.listenersRefs[multiaddr.toString()] = listener | ||
return listener | ||
} | ||
|
||
|
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these two functions could be one, taking the options as a parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done