Skip to content

Commit

Permalink
Added [email protected] Fixed #121
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Apr 10, 2016
1 parent f1a01d0 commit b906e2f
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 96 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,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.98/rmc3.min.js"></script>
<script src="https://github.com/muaz-khan/RTCMultiConnection/releases/download/3.2.99/rmc3.min.js"></script>
```

If you're sharing files, you also need to link:
Expand All @@ -148,7 +148,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.98/rmc3.fbr.min.js"></script>
<script src="https://github.com/muaz-khan/RTCMultiConnection/releases/download/3.2.99/rmc3.fbr.min.js"></script>
```

> You can link multiple files from `dev` directory. Order doesn't matters.
Expand Down
10 changes: 9 additions & 1 deletion RTCMultiConnection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated: 2016-03-31 1:23:45 PM UTC
// Last time updated: 2016-04-10 12:38:30 PM UTC

// _____________________
// RTCMultiConnection-v3
Expand Down Expand Up @@ -350,6 +350,13 @@
}

options = options || {};

var cb = function() {};
if (typeof options === 'function') {
cb = options;
options = {};
}

if (typeof options.localPeerSdpConstraints !== 'undefined') {
localPeerSdpConstraints = options.localPeerSdpConstraints;
}
Expand Down Expand Up @@ -386,6 +393,7 @@
}

mPeer.onNegotiationNeeded(connectionDescription);
cb();
});

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

Large diffs are not rendered by default.

11 changes: 1 addition & 10 deletions demos/Firebase-Demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ <h1>Firebase Video Conferencing Demo using RTCMultiConnection-v3.0</h1>
<input type="text" id="room-id" value="abcdef">
<button id="open-room">Open Room</button>
<button id="join-room">Join Room</button>
<button id="open-or-join-room">Auto Open Or Join Room</button>

<br><br>
<input type="text" id="input-text-chat" placeholder="Enter Text Chat" disabled>
Expand All @@ -80,10 +79,6 @@ <h1>Firebase Video Conferencing Demo using RTCMultiConnection-v3.0</h1>
<!-- <script src="/dev/FileBufferReader.js"></script> -->
<script src="https://cdn.webrtc-experiment.com:443/rmc3.fbr.min.js"></script>

<!-- socket.io for signaling
<script src="/socket.io/socket.io.js"></script>
-->

<script src="https://cdn.webrtc-experiment.com/firebase.js"></script>
<script src="../dev/globals.js"></script>
<script src="../dev/FirebaseConnection.js"></script>
Expand All @@ -103,11 +98,6 @@ <h1>Firebase Video Conferencing Demo using RTCMultiConnection-v3.0</h1>
connection.join(document.getElementById('room-id').value);
};

document.getElementById('open-or-join-room').onclick = function() {
this.disabled = true;
connection.openOrJoin(document.getElementById('room-id').value);
};

// ......................................................
// ................FileSharing/TextChat Code.............
// ......................................................
Expand Down Expand Up @@ -163,6 +153,7 @@ <h1>Firebase Video Conferencing Demo using RTCMultiConnection-v3.0</h1>
connection.socketMessageEvent = 'firebase-demo';

connection.setCustomSocketHandler(FirebaseConnection);
connection.firebase = 'webrtc-experiment';

connection.enableFileSharing = true; // by default, it is "false".

Expand Down
10 changes: 0 additions & 10 deletions demos/PubNub-Demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ <h1>PubNub Video Conferencing Demo using RTCMultiConnection-v3.0</h1>
<input type="text" id="room-id" value="abcdef">
<button id="open-room">Open Room</button>
<button id="join-room">Join Room</button>
<button id="open-or-join-room">Auto Open Or Join Room</button>

<br><br>
<input type="text" id="input-text-chat" placeholder="Enter Text Chat" disabled>
Expand All @@ -78,10 +77,6 @@ <h1>PubNub Video Conferencing Demo using RTCMultiConnection-v3.0</h1>
<!-- <script src="/dev/FileBufferReader.js"></script> -->
<script src="https://cdn.webrtc-experiment.com:443/rmc3.fbr.min.js"></script>

<!-- socket.io for signaling
<script src="/socket.io/socket.io.js"></script>
-->

<script src="https://cdn.webrtc-experiment.com/view/websocket.js"></script>
<script src="../dev/globals.js"></script>
<script src="../dev/PubNubConnection.js"></script>
Expand All @@ -101,11 +96,6 @@ <h1>PubNub Video Conferencing Demo using RTCMultiConnection-v3.0</h1>
connection.join(document.getElementById('room-id').value);
};

document.getElementById('open-or-join-room').onclick = function() {
this.disabled = true;
connection.openOrJoin(document.getElementById('room-id').value);
};

// ......................................................
// ................FileSharing/TextChat Code.............
// ......................................................
Expand Down
52 changes: 24 additions & 28 deletions dev/FirebaseConnection.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
function FirebaseConnection(connection, connectCallback) {
connection.firebase = connection.firebase || 'webrtc-experiment';
var channelId = connection.channel;
var socket = new Firebase('https://' + connection.firebase + '.firebaseio.com/' + channelId);

socket.on('child_added', function(snap) {
connection.socket = new Firebase('https://' + connection.firebase + '.firebaseio.com/' + channelId);

connection.socket.on('child_added', function(snap) {
var data = JSON.parse(snap.val());

if (data.eventName === connection.socketMessageEvent) {
Expand All @@ -13,24 +14,27 @@ function FirebaseConnection(connection, connectCallback) {
snap.ref().remove(); // for socket.io live behavior
});

socket.onDisconnect().remove();
connection.socket.onDisconnect().remove();

connection.socket.emit = function(eventName, data, callback) {
if (eventName === 'changed-uuid') return;
if (data.message && data.message.shiftedModerationControl) return;

socket.emit = function(eventName, data, callback) {
socket.push(JSON.stringify({
connection.socket.push(JSON.stringify({
eventName: eventName,
data: data
}));

if (callback) {
callback();
}
};

var mPeer = connection.multiPeersHandler;

function onMessagesCallback(message) {
if (message.remoteUserId != connection.userid) return;

if (connection.enableLogs) {
console.debug(message.sender, message.message);
}

if (connection.peers[message.sender] && connection.peers[message.sender].extra != message.extra) {
connection.peers[message.sender].extra = message.extra;
connection.onExtraDataUpdated({
Expand All @@ -47,7 +51,7 @@ function FirebaseConnection(connection, connectCallback) {

var action = message.message.action;

if (action === 'ended') {
if (action === 'ended' || action === 'stream-removed') {
connection.onstreamended(stream);
return;
}
Expand All @@ -63,7 +67,7 @@ function FirebaseConnection(connection, connectCallback) {
}

mPeer.onNegotiationNeeded({
allParticipants: connection.peers.getAllParticipants(message.sender)
allParticipants: connection.getAllParticipants(message.sender)
}, message.sender);
return;
}
Expand All @@ -77,11 +81,7 @@ function FirebaseConnection(connection, connectCallback) {
}

if (message.message === 'dropPeerConnection') {
if (connection.peers[message.sender]) {
connection.peers[message.sender].peer.close();
connection.peers[message.sender].peer = null;
delete connection.peers[message.sender];
}
connection.deletePeer(message.sender);
return;
}

Expand Down Expand Up @@ -126,17 +126,13 @@ function FirebaseConnection(connection, connectCallback) {
return;
}

if (message.message.readyForOffer) {
if (message.message.readyForOffer || message.message.addMeAsBroadcaster) {
connection.addNewBroadcaster(message.sender);
}

if (message.message.newParticipationRequest) {
if (message.message.newParticipationRequest && message.sender !== connection.userid) {
if (connection.peers[message.sender]) {
if (connection.peers[message.sender].peer) {
connection.peers[message.sender].peer.close();
connection.peers[message.sender].peer = null;
}
delete connection.peers[message.sender];
connection.deletePeer(message.sender);
}

var userPreferences = {
Expand Down Expand Up @@ -197,11 +193,11 @@ function FirebaseConnection(connection, connectCallback) {

new Firebase('https://' + connection.firebase + '.firebaseio.com/.info/connected').on('value', function(snap) {
if (snap.val()) {
// if connection.enableLogs
console.info('socket.io connection is opened.');
if (connectCallback) connectCallback(socket);
if (connection.enableLogs) {
console.info('Firebase connection is opened.');
}

if (connectCallback) connectCallback(connection.socket);
}
});

return socket;
}
62 changes: 30 additions & 32 deletions dev/PubNubConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ function PubNubConnection(connection, connectCallback) {
var sub = 'sub-c-d0c386c6-7263-11e2-8b02-12313f022c90';

WebSocket = PUBNUB.ws;
var socket = new WebSocket('wss://pubsub.pubnub.com/' + pub + '/' + sub + '/' + channelId);

socket.onmessage = function(e) {
connection.socket = new WebSocket('wss://pubsub.pubnub.com/' + pub + '/' + sub + '/' + channelId);

connection.socket.onmessage = function(e) {
var data = JSON.parse(e.data);

if (data.eventName === connection.socketMessageEvent) {
Expand All @@ -25,41 +26,48 @@ function PubNubConnection(connection, connectCallback) {
}
};

socket.onerror = function() {
connection.socket.onerror = function() {
if (!connection.enableLogs) return;
console.error('Socket connection is failed.');
};

socket.onclose = function() {
connection.socket.onclose = function() {
if (!connection.enableLogs) return;
console.warn('Socket connection is closed.');
};

socket.onopen = function() {
// if connection.enableLogs
console.info('socket.io connection is opened.');
if (connectCallback) connectCallback(socket);
connection.socket.onopen = function() {
if (connection.enableLogs) {
console.info('PubNub connection is opened.');
}

socket.emit('presence', {
connection.socket.emit('presence', {
userid: connection.userid,
isOnline: true
});

if (connectCallback) connectCallback(connection.socket);
};

socket.emit = function(eventName, data, callback) {
socket.send(JSON.stringify({
connection.socket.emit = function(eventName, data, callback) {
if (eventName === 'changed-uuid') return;
if (data.message && data.message.shiftedModerationControl) return;

connection.socket.send(JSON.stringify({
eventName: eventName,
data: data
}));

if (callback) {
callback();
}
};

var mPeer = connection.multiPeersHandler;

function onMessagesCallback(message) {
if (message.remoteUserId != connection.userid) return;

if (connection.enableLogs) {
console.debug(message.sender, message.message);
}

if (connection.peers[message.sender] && connection.peers[message.sender].extra != message.extra) {
connection.peers[message.sender].extra = message.extra;
connection.onExtraDataUpdated({
Expand All @@ -76,7 +84,7 @@ function PubNubConnection(connection, connectCallback) {

var action = message.message.action;

if (action === 'ended') {
if (action === 'ended' || action === 'stream-removed') {
connection.onstreamended(stream);
return;
}
Expand All @@ -92,7 +100,7 @@ function PubNubConnection(connection, connectCallback) {
}

mPeer.onNegotiationNeeded({
allParticipants: connection.peers.getAllParticipants(message.sender)
allParticipants: connection.getAllParticipants(message.sender)
}, message.sender);
return;
}
Expand All @@ -106,11 +114,7 @@ function PubNubConnection(connection, connectCallback) {
}

if (message.message === 'dropPeerConnection') {
if (connection.peers[message.sender]) {
connection.peers[message.sender].peer.close();
connection.peers[message.sender].peer = null;
delete connection.peers[message.sender];
}
connection.deletePeer(message.sender);
return;
}

Expand Down Expand Up @@ -155,17 +159,13 @@ function PubNubConnection(connection, connectCallback) {
return;
}

if (message.message.readyForOffer) {
if (message.message.readyForOffer || message.message.addMeAsBroadcaster) {
connection.addNewBroadcaster(message.sender);
}

if (message.message.newParticipationRequest) {
if (message.message.newParticipationRequest && message.sender !== connection.userid) {
if (connection.peers[message.sender]) {
if (connection.peers[message.sender].peer) {
connection.peers[message.sender].peer.close();
connection.peers[message.sender].peer = null;
}
delete connection.peers[message.sender];
connection.deletePeer(message.sender);
}

var userPreferences = {
Expand Down Expand Up @@ -225,11 +225,9 @@ function PubNubConnection(connection, connectCallback) {
}

window.addEventListener('beforeunload', function() {
socket.emit('presence', {
connection.socket.emit('presence', {
userid: connection.userid,
isOnline: false
});
}, false);

return socket;
}
8 changes: 8 additions & 0 deletions dev/RTCMultiConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ function RTCMultiConnection(roomid, forceOptions) {
}

options = options || {};

var cb = function() {};
if (typeof options === 'function') {
cb = options;
options = {};
}

if (typeof options.localPeerSdpConstraints !== 'undefined') {
localPeerSdpConstraints = options.localPeerSdpConstraints;
}
Expand Down Expand Up @@ -370,6 +377,7 @@ function RTCMultiConnection(roomid, forceOptions) {
}

mPeer.onNegotiationNeeded(connectionDescription);
cb();
});

return connectionDescription;
Expand Down
Loading

0 comments on commit b906e2f

Please sign in to comment.