Skip to content

Commit

Permalink
Added: [email protected] Fixed #83
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Jan 14, 2016
1 parent 64a0f99 commit 0eac1fb
Show file tree
Hide file tree
Showing 12 changed files with 282 additions and 1,140 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ All files from `/dist` directory are available on CDN: `https://cdn.webrtc-exper
<script src="https://cdn.webrtc-experiment.com:443/rmc3.min.js"></script>

<!-- or specific version -->
<script src="https://github.com/muaz-khan/RTCMultiConnection/releases/download/3.2.82/rmc3.min.js"></script>
<script src="https://github.com/muaz-khan/RTCMultiConnection/releases/download/3.2.83/rmc3.min.js"></script>
```

If you're sharing files, you also need to link:
Expand All @@ -76,7 +76,7 @@ If you're sharing files, you also need to link:
<script src="https://cdn.webrtc-experiment.com:443/rmc3.fbr.min.js"></script>

<!-- or specific version -->
<script src="https://github.com/muaz-khan/RTCMultiConnection/releases/download/3.2.82/rmc3.fbr.min.js"></script>
<script src="https://github.com/muaz-khan/RTCMultiConnection/releases/download/3.2.83/rmc3.fbr.min.js"></script>
```

> You can link multiple files from `dev` directory. Order doesn't matters.
Expand Down
123 changes: 89 additions & 34 deletions RTCMultiConnection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated at Wednesday, January 13th, 2016, 7:18:18 PM
// Last time updated at Thursday, January 14th, 2016, 5:11:33 PM

// ______________________________
// RTCMultiConnection-v3.0 (Beta)
Expand Down Expand Up @@ -48,6 +48,8 @@

connection.onstream(connection.streamEvents[stream.streamid]);
});

connection.observers.all();
};

mPeer.onGettingRemoteMedia = function(stream, remoteUserId) {
Expand Down Expand Up @@ -379,6 +381,8 @@
};

connection.getUserMedia = connection.captureUserMedia = function(callback, session) {
connection.observers.all();

session = session || connection.session;

if (connection.dontCaptureUserMedia || isData(session)) {
Expand Down Expand Up @@ -497,12 +501,44 @@
socket.emit('changed-uuid', connection.userid);
};

connection.observers = {
extra: function() {
observeObject(connection.extra, function(changes) {
socket.emit('extra-data-updated', connection.extra);
});
},
attachStreams: function() {
observeObject(connection.attachStreams, function(changes) {
changes.forEach(function(change) {
if (change.type === 'add') {
setStreamEndHandler(change.object[change.name]);
}

if (change.type === 'remove' || change.type === 'delete') {
if (connection.removeStreams.indexOf(change.object[change.name]) === -1) {
connection.removeStreams.push(change.object[change.name]);
}
}

connection.attachStreams = removeNullEntries(connection.attachStreams);
connection.removeStreams = removeNullEntries(connection.removeStreams);
connection.observers.all();
});
});
},
all: function() {
this.extra();
this.attachStreams();

if (socket) {
socket.emit('extra-data-updated', connection.extra);
}
}
};
connection.extra = {};
if (Object.observe) {
Object.observe(connection.extra, function(changes) {
socket.emit('extra-data-updated', connection.extra);
});
}
connection.attachStreams = [];
connection.removeStreams = [];
connection.observers.all();

connection.session = {
audio: true,
Expand Down Expand Up @@ -643,8 +679,6 @@
};

connection.direction = 'many-to-many';
connection.attachStreams = [];
connection.removeStreams = [];

Array.prototype.getStreamById = function(streamid) {
var stream;
Expand Down Expand Up @@ -885,6 +919,7 @@

connection.attachStreams = removeNullEntries(connection.attachStreams);
connection.removeStreams = removeNullEntries(connection.removeStreams);
connection.observers.all();

// connection.renegotiate();

Expand All @@ -905,25 +940,6 @@
}, false);
}

if (Object.observe) {
Object.observe(connection.attachStreams, function(changes) {
changes.forEach(function(change) {
if (change.type === 'add') {
setStreamEndHandler(change.object[change.name]);
}

if (change.type === 'remove' || change.type === 'delete') {
if (connection.removeStreams.indexOf(change.object[change.name]) === -1) {
connection.removeStreams.push(change.object[change.name]);
}
}

connection.attachStreams = removeNullEntries(connection.attachStreams);
connection.removeStreams = removeNullEntries(connection.removeStreams);
});
});
}

connection.onMediaError = function(error) {
if (!!connection.enableLogs) {
console.error(error);
Expand Down Expand Up @@ -1233,7 +1249,30 @@
connection.checkIfChromeExtensionAvailable = isFirefoxExtensionAvailable;
}

connection.getScreenConstraints = getScreenConstraints;
if (typeof getChromeExtensionStatus !== 'undefined') {
connection.getChromeExtensionStatus = getChromeExtensionStatus;
}

connection.getScreenConstraints = function(callback) {
getScreenConstraints(function(error, screen_constraints) {
if (!error) {
screen_constraints = connection.modifyScreenConstraints(screen_constraints);
callback(error, screen_constraints);
}
});
};

connection.modifyScreenConstraints = function(screen_constraints) {
return screen_constraints;
};

connection.onPeerStateChanged = function(state) {
if (connection.enableLogs) {
if (state.iceConnectionState.search(/disconnected|closed|failed/gi) !== -1) {
console.error('Peer connection is closed between you & ', state.userid, state.extra, 'state:', state.iceConnectionState);
}
}
};
}

function SocketConnection(connection, connectCallback) {
Expand Down Expand Up @@ -1953,14 +1992,11 @@
extra: connection.peers[remoteUserId] ? connection.peers[remoteUserId].extra : {},
channel: channel
});
connection.observers.all();
};

this.onPeerStateChanged = function(state) {
if (connection.enableLogs) {
if (state.iceConnectionState.search(/disconnected|closed|failed/gi) !== -1) {
console.error('Peer connection is closed between you & ', state.userid, state.extra, 'state:', state.iceConnectionState);
}
}
connection.onPeerStateChanged(state);
};

this.onNegotiationStarted = function(remoteUserId, states) {};
Expand Down Expand Up @@ -2189,6 +2225,20 @@
};
}

var lastChanges = '';

function observeObject(obj, callback) {
if (!Object.observe) return;

Object.observe(obj, function(changes) {
var jsonStringified = JSON.stringify(changes);
if (lastChanges == jsonStringified) return;
lastChanges = jsonStringified;

callback(changes);
});
}

// Last time updated at Feb 08, 2015, 08:32:23

// Latest file can be found here: https://cdn.webrtc-experiment.com/Plugin.EveryWhere.js
Expand Down Expand Up @@ -2557,11 +2607,16 @@
});

peer.oniceconnectionstatechange = peer.onsignalingstatechange = function() {
var extra = that.extra;
if (config.rtcMultiConnection.peers[that.remoteUserId]) {
extra = config.rtcMultiConnection.peers[that.remoteUserId].extra || extra;
}

config.onPeerStateChanged({
iceConnectionState: peer.iceConnectionState,
iceGatheringState: peer.iceGatheringState,
signalingState: peer.signalingState,
extra: that.extra,
extra: extra,
userid: that.remoteUserId
});

Expand Down
10 changes: 5 additions & 5 deletions RTCMultiConnection.min.js

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions dev/MultiPeersHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,11 @@ function MultiPeers(connection) {
extra: connection.peers[remoteUserId] ? connection.peers[remoteUserId].extra : {},
channel: channel
});
connection.observers.all();
};

this.onPeerStateChanged = function(state) {
if (connection.enableLogs) {
if (state.iceConnectionState.search(/disconnected|closed|failed/gi) !== -1) {
console.error('Peer connection is closed between you & ', state.userid, state.extra, 'state:', state.iceConnectionState);
}
}
connection.onPeerStateChanged(state);
};

this.onNegotiationStarted = function(remoteUserId, states) {};
Expand Down
93 changes: 66 additions & 27 deletions dev/RTCMultiConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ function RTCMultiConnection(roomid) {

connection.onstream(connection.streamEvents[stream.streamid]);
});

connection.observers.all();
};

mPeer.onGettingRemoteMedia = function(stream, remoteUserId) {
Expand Down Expand Up @@ -370,6 +372,8 @@ function RTCMultiConnection(roomid) {
};

connection.getUserMedia = connection.captureUserMedia = function(callback, session) {
connection.observers.all();

session = session || connection.session;

if (connection.dontCaptureUserMedia || isData(session)) {
Expand Down Expand Up @@ -488,12 +492,44 @@ function RTCMultiConnection(roomid) {
socket.emit('changed-uuid', connection.userid);
};

connection.observers = {
extra: function() {
observeObject(connection.extra, function(changes) {
socket.emit('extra-data-updated', connection.extra);
});
},
attachStreams: function() {
observeObject(connection.attachStreams, function(changes) {
changes.forEach(function(change) {
if (change.type === 'add') {
setStreamEndHandler(change.object[change.name]);
}

if (change.type === 'remove' || change.type === 'delete') {
if (connection.removeStreams.indexOf(change.object[change.name]) === -1) {
connection.removeStreams.push(change.object[change.name]);
}
}

connection.attachStreams = removeNullEntries(connection.attachStreams);
connection.removeStreams = removeNullEntries(connection.removeStreams);
connection.observers.all();
});
});
},
all: function() {
this.extra();
this.attachStreams();

if (socket) {
socket.emit('extra-data-updated', connection.extra);
}
}
};
connection.extra = {};
if (Object.observe) {
Object.observe(connection.extra, function(changes) {
socket.emit('extra-data-updated', connection.extra);
});
}
connection.attachStreams = [];
connection.removeStreams = [];
connection.observers.all();

connection.session = {
audio: true,
Expand Down Expand Up @@ -634,8 +670,6 @@ function RTCMultiConnection(roomid) {
};

connection.direction = 'many-to-many';
connection.attachStreams = [];
connection.removeStreams = [];

Array.prototype.getStreamById = function(streamid) {
var stream;
Expand Down Expand Up @@ -876,6 +910,7 @@ function RTCMultiConnection(roomid) {

connection.attachStreams = removeNullEntries(connection.attachStreams);
connection.removeStreams = removeNullEntries(connection.removeStreams);
connection.observers.all();

// connection.renegotiate();

Expand All @@ -896,25 +931,6 @@ function RTCMultiConnection(roomid) {
}, false);
}

if (Object.observe) {
Object.observe(connection.attachStreams, function(changes) {
changes.forEach(function(change) {
if (change.type === 'add') {
setStreamEndHandler(change.object[change.name]);
}

if (change.type === 'remove' || change.type === 'delete') {
if (connection.removeStreams.indexOf(change.object[change.name]) === -1) {
connection.removeStreams.push(change.object[change.name]);
}
}

connection.attachStreams = removeNullEntries(connection.attachStreams);
connection.removeStreams = removeNullEntries(connection.removeStreams);
});
});
}

connection.onMediaError = function(error) {
if (!!connection.enableLogs) {
console.error(error);
Expand Down Expand Up @@ -1224,5 +1240,28 @@ function RTCMultiConnection(roomid) {
connection.checkIfChromeExtensionAvailable = isFirefoxExtensionAvailable;
}

connection.getScreenConstraints = getScreenConstraints;
if (typeof getChromeExtensionStatus !== 'undefined') {
connection.getChromeExtensionStatus = getChromeExtensionStatus;
}

connection.getScreenConstraints = function(callback) {
getScreenConstraints(function(error, screen_constraints) {
if (!error) {
screen_constraints = connection.modifyScreenConstraints(screen_constraints);
callback(error, screen_constraints);
}
});
};

connection.modifyScreenConstraints = function(screen_constraints) {
return screen_constraints;
};

connection.onPeerStateChanged = function(state) {
if (connection.enableLogs) {
if (state.iceConnectionState.search(/disconnected|closed|failed/gi) !== -1) {
console.error('Peer connection is closed between you & ', state.userid, state.extra, 'state:', state.iceConnectionState);
}
}
};
}
7 changes: 6 additions & 1 deletion dev/RTCPeerConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,16 @@ function PeerInitiator(config) {
});

peer.oniceconnectionstatechange = peer.onsignalingstatechange = function() {
var extra = that.extra;
if (config.rtcMultiConnection.peers[that.remoteUserId]) {
extra = config.rtcMultiConnection.peers[that.remoteUserId].extra || extra;
}

config.onPeerStateChanged({
iceConnectionState: peer.iceConnectionState,
iceGatheringState: peer.iceGatheringState,
signalingState: peer.signalingState,
extra: that.extra,
extra: extra,
userid: that.remoteUserId
});

Expand Down
Loading

0 comments on commit 0eac1fb

Please sign in to comment.