Skip to content

Commit

Permalink
Fixed #293 Now passing extra-data over onstreamended and onleave
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Nov 30, 2016
1 parent 30068fd commit 60c1861
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 19 deletions.
3 changes: 2 additions & 1 deletion dev/MultiPeersHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
function MultiPeers(connection) {
var self = this;

var skipPeers = ['getAllParticipants', 'getLength', 'selectFirst', 'streams', 'send', 'forEach'];
var skipPeers = ['getAllParticipants', 'getLength', 'selectFirst', 'streams', 'send', 'forEach', 'backup'];
connection.peers = {
backup: {},
getLength: function() {
var numberOfPeers = 0;
for (var peer in this) {
Expand Down
18 changes: 16 additions & 2 deletions dev/RTCMultiConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ function RTCMultiConnection(roomid, forceOptions) {
};
}

if (connection.peers.backup[streamEvent.userid]) {
streamEvent.extra = connection.peers.backup[streamEvent.userid].extra;
}

connection.onstreamended(streamEvent);

delete connection.streamEvents[stream.streamid];
Expand Down Expand Up @@ -254,10 +258,16 @@ function RTCMultiConnection(roomid, forceOptions) {
return;
}

connection.onleave({
var eventObject = {
userid: remoteUserId,
extra: connection.peers[remoteUserId] ? connection.peers[remoteUserId].extra : {}
});
};

if (connection.peers.backup[eventObject.userid]) {
eventObject.extra = connection.peers.backup[eventObject.userid].extra;
}

connection.onleave(eventObject);

if (!!connection.peers[remoteUserId]) {
connection.peers[remoteUserId].streams.forEach(function(stream) {
Expand Down Expand Up @@ -1133,6 +1143,10 @@ function RTCMultiConnection(roomid, forceOptions) {
return;
}

if (connection.peers.backup[streamEvent.userid]) {
streamEvent.extra = connection.peers.backup[streamEvent.userid].extra;
}

connection.onstreamended(streamEvent);

delete connection.streamEvents[stream.streamid];
Expand Down
22 changes: 20 additions & 2 deletions dev/SocketConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ function SocketConnection(connection, connectCallback) {
userid: remoteUserId,
extra: extra
});

if (!connection.peers.backup[remoteUserId]) {
connection.peers.backup[remoteUserId] = {
userid: remoteUserId,
extra: {}
};
}

connection.peers.backup[remoteUserId].extra = extra;
});

connection.socket.on(connection.socketMessageEvent, function(message) {
Expand All @@ -78,6 +87,9 @@ function SocketConnection(connection, connectCallback) {
var action = message.message.action;

if (action === 'ended' || action === 'inactive' || action === 'stream-removed') {
if (connection.peers.backup[stream.userid]) {
stream.extra = connection.peers.backup[stream.userid].extra;
}
connection.onstreamended(stream);
return;
}
Expand Down Expand Up @@ -229,10 +241,16 @@ function SocketConnection(connection, connectCallback) {
extra: connection.peers[userid] ? connection.peers[userid].extra || {} : {}
});

connection.onleave({
var eventObject = {
userid: userid,
extra: {}
});
};

if (connection.peers.backup[eventObject.userid]) {
eventObject.extra = connection.peers.backup[eventObject.userid].extra;
}

connection.onleave(eventObject);
});

var alreadyConnected = false;
Expand Down
49 changes: 41 additions & 8 deletions dist/RTCMultiConnection.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Last time updated: 2016-11-25 6:09:38 PM UTC
// Last time updated: 2016-11-30 11:33:03 AM UTC

// _________________________
// RTCMultiConnection v3.4.2
// RTCMultiConnection v3.4.3

// Open-Sourced: /~https://github.com/muaz-khan/RTCMultiConnection

Expand Down Expand Up @@ -104,6 +104,10 @@
};
}

if (connection.peers.backup[streamEvent.userid]) {
streamEvent.extra = connection.peers.backup[streamEvent.userid].extra;
}

connection.onstreamended(streamEvent);

delete connection.streamEvents[stream.streamid];
Expand Down Expand Up @@ -270,10 +274,16 @@
return;
}

connection.onleave({
var eventObject = {
userid: remoteUserId,
extra: connection.peers[remoteUserId] ? connection.peers[remoteUserId].extra : {}
});
};

if (connection.peers.backup[eventObject.userid]) {
eventObject.extra = connection.peers.backup[eventObject.userid].extra;
}

connection.onleave(eventObject);

if (!!connection.peers[remoteUserId]) {
connection.peers[remoteUserId].streams.forEach(function(stream) {
Expand Down Expand Up @@ -1149,6 +1159,10 @@
return;
}

if (connection.peers.backup[streamEvent.userid]) {
streamEvent.extra = connection.peers.backup[streamEvent.userid].extra;
}

connection.onstreamended(streamEvent);

delete connection.streamEvents[stream.streamid];
Expand Down Expand Up @@ -1601,7 +1615,7 @@
};

connection.trickleIce = true;
connection.version = '3.4.2';
connection.version = '3.4.3';

connection.onSettingLocalDescription = function(event) {
if (connection.enableLogs) {
Expand Down Expand Up @@ -1668,6 +1682,15 @@
userid: remoteUserId,
extra: extra
});

if (!connection.peers.backup[remoteUserId]) {
connection.peers.backup[remoteUserId] = {
userid: remoteUserId,
extra: {}
};
}

connection.peers.backup[remoteUserId].extra = extra;
});

connection.socket.on(connection.socketMessageEvent, function(message) {
Expand All @@ -1690,6 +1713,9 @@
var action = message.message.action;

if (action === 'ended' || action === 'inactive' || action === 'stream-removed') {
if (connection.peers.backup[stream.userid]) {
stream.extra = connection.peers.backup[stream.userid].extra;
}
connection.onstreamended(stream);
return;
}
Expand Down Expand Up @@ -1841,10 +1867,16 @@
extra: connection.peers[userid] ? connection.peers[userid].extra || {} : {}
});

connection.onleave({
var eventObject = {
userid: userid,
extra: {}
});
};

if (connection.peers.backup[eventObject.userid]) {
eventObject.extra = connection.peers.backup[eventObject.userid].extra;
}

connection.onleave(eventObject);
});

var alreadyConnected = false;
Expand Down Expand Up @@ -1951,8 +1983,9 @@
function MultiPeers(connection) {
var self = this;

var skipPeers = ['getAllParticipants', 'getLength', 'selectFirst', 'streams', 'send', 'forEach'];
var skipPeers = ['getAllParticipants', 'getLength', 'selectFirst', 'streams', 'send', 'forEach', 'backup'];
connection.peers = {
backup: {},
getLength: function() {
var numberOfPeers = 0;
for (var peer in this) {
Expand Down
12 changes: 6 additions & 6 deletions dist/RTCMultiConnection.min.js

Large diffs are not rendered by default.

0 comments on commit 60c1861

Please sign in to comment.