Skip to content

Commit 5ce6e6b

Browse files
committed
Listen for peer:update events and handle accordingly to properly reconnect already known peers - ref #20
1 parent 6e4949f commit 5ce6e6b

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

docs/events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Events
22

3-
The following events are emitted from the signalling object created by calling `quickconnect()`:
3+
The following events are emitted from the signalling object created by calling `quickconnect()`. Additionally, any of the underlying [signaller events](https://github.com/rtc-io/rtc-signaller#signaller-events) can also be used.
44

55
### Call Level Events
66

index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ module.exports = function(signalhost, opts) {
259259
}, 500);
260260
}
261261

262+
function handleLocalAnnounce(data) {
263+
// if we send an announce with an updated room then update our local room name
264+
if (data && typeof data.room != 'undefined') {
265+
room = data.room;
266+
}
267+
}
268+
262269
function handlePeerAnnounce(data) {
263270
var pc;
264271
var monitor;
@@ -321,6 +328,18 @@ module.exports = function(signalhost, opts) {
321328
}
322329
}
323330

331+
function handlePeerUpdate(data) {
332+
var id = data && data.id;
333+
var activeCall = id && calls.get(id);
334+
335+
// if we have received an update for a peer that has no active calls,
336+
// then pass this onto the announce handler
337+
if (id && (! activeCall)) {
338+
debug('received peer update from peer ' + id + ', no active calls');
339+
return handlePeerAnnounce(data);
340+
}
341+
}
342+
324343
function receiveRemoteStream(id) {
325344
var call = calls.get(id);
326345

@@ -352,6 +371,7 @@ module.exports = function(signalhost, opts) {
352371
}
353372

354373
signaller.on('peer:announce', handlePeerAnnounce);
374+
signaller.on('peer:update', handlePeerUpdate);
355375
signaller.on('peer:leave', callEnd);
356376

357377
// announce ourselves to our new friend
@@ -626,6 +646,9 @@ module.exports = function(signalhost, opts) {
626646
});
627647
};
628648

649+
// respond to local announce messages
650+
signaller.on('local:announce', handleLocalAnnounce);
651+
629652
// pass the signaller on
630653
return signaller;
631654
};

test/all.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require('./datachannel');
1515
// require('./heartbeat-disconnect');
1616
require('./custom-id');
1717
require('./request-stream');
18+
require('./reconnect');
1819

1920
if (! detect.moz) {
2021
require('./reactive');

0 commit comments

Comments
 (0)