Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1) Fixed user-leave issues
2) Fixed broadcast:true issues
3) If camera fails; v3.0 joins with audio-only.
  • Loading branch information
muaz-khan committed Feb 3, 2016
1 parent 64199d5 commit cdaac70
Show file tree
Hide file tree
Showing 35 changed files with 408 additions and 187 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

[![npm](https://img.shields.io/npm/v/rtcmulticonnection-v3.svg)](https://npmjs.org/package/rtcmulticonnection-v3) [![downloads](https://img.shields.io/npm/dm/rtcmulticonnection-v3.svg)](https://npmjs.org/package/rtcmulticonnection-v3) [![Build Status: Linux](https://travis-ci.org/muaz-khan/RTCMultiConnection.png?branch=master)](https://travis-ci.org/muaz-khan/RTCMultiConnection)

> v3.0 has its own built-in socket.io server. It has pubnub/firebase demos as well; however [reliable-signaler](https://github.com/muaz-khan/Reliable-Signaler/tree/master/rtcmulticonnection-client) or [socketio-over-nodejs](https://github.com/muaz-khan/WebRTC-Experiment/tree/master/socketio-over-nodejs) or similar codes can NOT be used with v3.0. Please use [`Signaling-Server.js`](https://github.com/muaz-khan/RTCMultiConnection/blob/master/Signaling-Server.js) instead.
>
> v3.0 can use XHR/XMPP/etc. signaling implementations as well. Please check [PubNubConnection.js](https://github.com/muaz-khan/RTCMultiConnection/blob/master/dev/PubNubConnection.js) to see how to configure it for 3rd party signaling implementations. You simply have to modify top few lines.
Fetch latest code:

**Download via Github** (as `ZIP` or `.js`): [https://github.com/muaz-khan/RTCMultiConnection/releases](https://github.com/muaz-khan/RTCMultiConnection/releases)
Expand Down Expand Up @@ -64,7 +68,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.88/rmc3.min.js"></script>
<script src="https://github.com/muaz-khan/RTCMultiConnection/releases/download/3.2.90/rmc3.min.js"></script>
```

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

> You can link multiple files from `dev` directory. Order doesn't matters.
Expand Down
120 changes: 73 additions & 47 deletions RTCMultiConnection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated: 2016-02-01 7:46:56 AM UTC
// Last time updated: 2016-02-03 12:35:55 PM UTC

// ______________________________
// RTCMultiConnection-v3.0 (Beta)
Expand Down Expand Up @@ -455,8 +455,15 @@
callback(stream);
}
},
onLocalMediaError: function(error) {
mPeer.onLocalMediaError(error);
onLocalMediaError: function(error, constraints) {
mPeer.onLocalMediaError(error, constraints);

if (constraints.audio && constraints.video && (error.name || '').toString().indexOf('DevicesNotFound') !== -1) {
constraints.video = false;
invokeGetUserMedia(constraints, getUserMedia_callback);
return;
}

if (callback) {
callback();
}
Expand Down Expand Up @@ -864,8 +871,15 @@

connection.renegotiate();
},
onLocalMediaError: function(error) {
mPeer.onLocalMediaError(error);
onLocalMediaError: function(error, constraints) {
mPeer.onLocalMediaError(error, constraints);

if (constraints.audio && constraints.video && (error.name || '').toString().indexOf('DevicesNotFound') !== -1) {
constraints.video = false;
invokeGetUserMedia(constraints, callback);
return;
}

if (callback) {
return callback();
}
Expand Down Expand Up @@ -982,8 +996,14 @@

connection.replaceTrack(stream, remoteUserId, isVideoTrack || session.video || session.screen);
},
onLocalMediaError: function(error) {
mPeer.onLocalMediaError(error);
onLocalMediaError: function(error, constraints) {
mPeer.onLocalMediaError(error, constraints);

if (constraints.audio && constraints.video && (error.name || '').toString().indexOf('DevicesNotFound') !== -1) {
constraints.video = false;
invokeGetUserMedia(constraints, callback);
return;
}

if (callback) {
callback();
Expand Down Expand Up @@ -1080,9 +1100,9 @@
}, false);
}

connection.onMediaError = function(error) {
connection.onMediaError = function(error, constraints) {
if (!!connection.enableLogs) {
console.error(error);
console.error(error, constraints);
}
};

Expand All @@ -1093,7 +1113,7 @@
}, 10 * 1000);
}

if (!connection.session.oneway && connection.direction === 'many-to-many' && connection.broadcasters.indexOf(broadcasterId) === -1) {
if (!connection.session.oneway && !connection.session.broadcast && connection.direction === 'many-to-many' && connection.broadcasters.indexOf(broadcasterId) === -1) {
connection.broadcasters.push(broadcasterId);
keepNextBroadcasterOnServer();
}
Expand All @@ -1104,6 +1124,10 @@
function keepNextBroadcasterOnServer() {
if (!connection.isInitiator) return;

if (connection.session.oneway || connection.session.broadcast || connection.direction !== 'many-to-many') {
return;
}

var firstBroadcaster = connection.broadcasters[0];
var otherBroadcasters = [];
connection.broadcasters.forEach(function(broadcaster) {
Expand Down Expand Up @@ -2029,34 +2053,44 @@
localMediaConstraints.video = connection.mediaConstraints.video;
}

getUserMediaHandler({
onGettingLocalMedia: function(localStream) {
self.onGettingLocalMedia(localStream);

var streamsToShare = {};
connection.attachStreams.forEach(function(stream) {
streamsToShare[stream.streamid] = {
isAudio: !!stream.isAudio,
isVideo: !!stream.isVideo,
isScreen: !!stream.isScreen
};
});
message.userPreferences.streamsToShare = streamsToShare;
function invokeGetUserMedia(mediaConstraints) {
getUserMediaHandler({
onGettingLocalMedia: function(localStream) {
self.onGettingLocalMedia(localStream);

self.onNegotiationNeeded({
readyForOffer: true,
userPreferences: message.userPreferences
}, remoteUserId);
},
onLocalMediaError: function(error) {
self.onLocalMediaError(error);
self.onNegotiationNeeded({
readyForOffer: true,
userPreferences: message.userPreferences
}, remoteUserId);
},
localMediaConstraints: localMediaConstraints
});
var streamsToShare = {};
connection.attachStreams.forEach(function(stream) {
streamsToShare[stream.streamid] = {
isAudio: !!stream.isAudio,
isVideo: !!stream.isVideo,
isScreen: !!stream.isScreen
};
});
message.userPreferences.streamsToShare = streamsToShare;

self.onNegotiationNeeded({
readyForOffer: true,
userPreferences: message.userPreferences
}, remoteUserId);
},
onLocalMediaError: function(error, constraints) {
self.onLocalMediaError(error, constraints);

if (constraints.audio && constraints.video && (error.name || '').toString().indexOf('DevicesNotFound') !== -1) {
constraints.video = false;
invokeGetUserMedia(constraints);
return;
}

self.onNegotiationNeeded({
readyForOffer: true,
userPreferences: message.userPreferences
}, remoteUserId);
},
localMediaConstraints: mediaConstraints
});
}
invokeGetUserMedia(localMediaConstraints);
}

if (message.readyForOffer) {
Expand Down Expand Up @@ -2094,11 +2128,8 @@
this.onGettingRemoteMedia = function(stream, remoteUserId) {};
this.onRemovingRemoteMedia = function(stream, remoteUserId) {};
this.onGettingLocalMedia = function(localStream) {};
this.onLocalMediaError = function(error) {
if (!!connection.enableLogs) {
console.error('onLocalMediaError', JSON.stringify(error, null, '\t'));
}
connection.onMediaError(error);
this.onLocalMediaError = function(error, constraints) {
connection.onMediaError(error, constraints);
};

var fbr;
Expand Down Expand Up @@ -3048,11 +3079,6 @@
return;
}

connection.multiPeersHandler.onNegotiationNeeded({
userLeft: true,
autoCloseEntireSession: !!connection.autoCloseEntireSession
}, that.remoteUserId);

try {
if (peer.iceConnectionState.search(/closed|failed/gi) === -1) {
peer.getRemoteStreams().forEach(function(stream) {
Expand Down
10 changes: 5 additions & 5 deletions RTCMultiConnection.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Scalable-Broadcast.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = exports = function(socket, singleBroadcastAttendees) {
} catch (e) {}
});

socket.on('message', function(message) {
socket.on('scalable-broadcast-message', function(message) {
socket.broadcast.emit('message', message);
});

Expand Down
16 changes: 9 additions & 7 deletions Signaling-Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ module.exports = exports = function(app, socketCallback) {
try {
var message = shiftedModerationControls[socket.userid];

if (message) {
delete shiftedModerationControls[message.userid];
onMessageCallback(message);
}
} catch (e) {}

try {
// inform all connected users
if (listOfUsers[socket.userid]) {
for (var s in listOfUsers[socket.userid].connectedWith) {
Expand All @@ -256,14 +263,9 @@ module.exports = exports = function(app, socketCallback) {
}
}
}

if (message) {
onMessageCallback(message);
delete shiftedModerationControls[message.userid];
}

delete listOfUsers[socket.userid];
} catch (e) {}

delete listOfUsers[socket.userid];
});

if (socketCallback) {
Expand Down
8 changes: 8 additions & 0 deletions demos/Audio+ScreenSharing.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ <h1>Audio + ScreenSharing using RTCMultiConnection-v3.0</h1>

var connection = new RTCMultiConnection();

// by default, socket.io server is assumed to be deployed on your own URL
connection.socketURL = '/';

// comment-out below line if you do not have your own socket.io server
// connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';

connection.socketMessageEvent = 'audio-plus-screen-demo';

document.getElementById('room-id').value = connection.token();

connection.session = {
Expand Down
8 changes: 8 additions & 0 deletions demos/Audio+Video+TextChat+FileSharing.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ <h1>Audio+Video+TextChat+FileSharing using RTCMultiConnection-v3.0</h1>

var connection = new RTCMultiConnection();

// by default, socket.io server is assumed to be deployed on your own URL
connection.socketURL = '/';

// comment-out below line if you do not have your own socket.io server
// connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';

connection.socketMessageEvent = 'audio-video-file-chat-demo';

document.getElementById('room-id').value = connection.token();

connection.enableFileSharing = true; // by default, it is "false".
Expand Down
8 changes: 8 additions & 0 deletions demos/Audio-Conferencing.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ <h1>Audio Conferencing using RTCMultiConnection-v3.0</h1>

var connection = new RTCMultiConnection();

// by default, socket.io server is assumed to be deployed on your own URL
connection.socketURL = '/';

// comment-out below line if you do not have your own socket.io server
// connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';

connection.socketMessageEvent = 'audio-conference-demo';

document.getElementById('room-id').value = connection.token();

connection.session = {
Expand Down
9 changes: 8 additions & 1 deletion demos/Disconnect+Rejoin.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,17 @@ <h1>Disconnect+Rejoin using RTCMultiConnection-v3.0</h1>

var connection = new RTCMultiConnection();

// by default, socket.io server is assumed to be deployed on your own URL
connection.socketURL = '/';

// comment-out below line if you do not have your own socket.io server
// connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';

connection.socketMessageEvent = 'disconnect-rejoin-demo';

document.getElementById('room-id').value = connection.token();

connection.enableFileSharing = true; // by default, it is "false".
connection.autoReDialOnFailure = false; // to support manual rejoin

connection.session = {
audio: true,
Expand Down
10 changes: 9 additions & 1 deletion demos/Files-Scalable-Broadcast.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ <h1><a href="https://github.com/muaz-khan/WebRTC-Scalable-Broadcast">WebRTC Scal

<script>
var connection = new RTCMultiConnection();

// by default, socket.io server is assumed to be deployed on your own URL
connection.socketURL = '/';

// comment-out below line if you do not have your own socket.io server
// connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';

connection.socketMessageEvent = 'files-scalable-broadcast-demo';

connection.enableScalableBroadcast = true;
connection.singleBroadcastAttendees = 1;

Expand All @@ -131,7 +140,6 @@ <h1><a href="https://github.com/muaz-khan/WebRTC-Scalable-Broadcast">WebRTC Scal
OfferToReceiveAudio: false,
OfferToReceiveVideo: false
};
connection.socketMessageEvent = 'main-connection';

connection.onopen = function(event) {
if (connection.isInitiator) {
Expand Down
2 changes: 2 additions & 0 deletions demos/Firebase-Demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ <h1>Firebase Video Conferencing Demo using RTCMultiConnection-v3.0</h1>

document.getElementById('room-id').value = connection.token();

connection.socketMessageEvent = 'firebase-demo';

connection.setCustomSocketHandler(FirebaseConnection);

connection.enableFileSharing = true; // by default, it is "false".
Expand Down
8 changes: 8 additions & 0 deletions demos/Password-Protected-Rooms.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ <h1>Password+Protected+Rooms using RTCMultiConnection-v3.0</h1>

var connection = new RTCMultiConnection();

// by default, socket.io server is assumed to be deployed on your own URL
connection.socketURL = '/';

// comment-out below line if you do not have your own socket.io server
// connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';

connection.socketMessageEvent = 'password-protected-rooms-demo';

document.getElementById('room-id').value = document.getElementById('room-password').value = connection.token();

connection.session = {
Expand Down
2 changes: 2 additions & 0 deletions demos/PubNub-Demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ <h1>PubNub Video Conferencing Demo using RTCMultiConnection-v3.0</h1>

document.getElementById('room-id').value = connection.token();

connection.socketMessageEvent = 'pubnub-demo';

connection.setCustomSocketHandler(PubNubConnection);

connection.enableFileSharing = true; // by default, it is "false".
Expand Down
8 changes: 8 additions & 0 deletions demos/TextChat+FileSharing.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ <h1>TextChat+FileSharing using RTCMultiConnection-v3.0</h1>

var connection = new RTCMultiConnection();

// by default, socket.io server is assumed to be deployed on your own URL
connection.socketURL = '/';

// comment-out below line if you do not have your own socket.io server
// connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';

connection.socketMessageEvent = 'textchat-plus-fileshare-demo';

document.getElementById('room-id').value = connection.token();

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

0 comments on commit cdaac70

Please sign in to comment.