Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#151 added SignalRConnection.js, WebSyncConnection.js and
XHRConnection.js Also fixed audio+screen capturing bugs.
  • Loading branch information
muaz-khan committed May 15, 2016
1 parent 940598f commit d127a39
Show file tree
Hide file tree
Showing 21 changed files with 1,467 additions and 94 deletions.
2 changes: 2 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ module.exports = function(grunt) {
dist: {
src: [
'dev/head.js',
// 'dev/amd.js',

'dev/RTCMultiConnection.js',
'dev/SocketConnection.js', // You can replace it with: FirebaseConnection.js || PubNubConnection.js
'dev/MultiPeersHandler.js',
Expand Down
88 changes: 53 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,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.3.4/rmc3.min.js"></script>
<script src="https://github.com/muaz-khan/RTCMultiConnection/releases/download/3.3.5/rmc3.min.js"></script>
```

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

> You can link multiple files from `dev` directory. Order doesn't matters.
Expand Down Expand Up @@ -675,14 +675,63 @@ connection.maxParticipantsAllowed = 1;

## `setCustomSocketHandler`

This method allows you skip Socket.io and force Firebase or PubNub or WebSockets or PHP/ASPNET whatever.
This method allows you skip Socket.io and force custom signaling implementations e.g. SIP-signaling, XHR-signaling, SignalR/WebSync signaling, Firebase/PubNub signaling etc.

```javascript
Here is Firebase example:

```html
<script src="/dev/globals.js"></script>
<script src="/dev/FirebaseConnection.js"></script>
<script>
var connection = new RTCMultiConnection();
connection.firebase = 'your-firebase-account';
// below line replaces FirebaseConnection
connection.setCustomSocketHandler(FirebaseConnection);
</script>
```

Here is PubNub example:

```html
<script src="/dev/globals.js"></script>
<script src="/dev/PubNubConnection.js"></script>
<script>
var connection = new RTCMultiConnection();
// below line replaces PubNubConnection
connection.setCustomSocketHandler(PubNubConnection);
</script>
```

SIP/SignalR/WebSync/XHR signaling:

```javascript
// please don't forget linking /dev/globals.js

var connection = new RTCMultiConnection();

// SignalR (requires /dev/SignalRConnection.js)
connection.setCustomSocketHandler(SignalRConnection);

// WebSync (requires /dev/WebSyncConnection.js)
connection.setCustomSocketHandler(WebSyncConnection);

// XHR (requires /dev/XHRConnection.js)
connection.setCustomSocketHandler(XHRConnection);

// Sip (requires /dev/SipConnection.js)
connection.setCustomSocketHandler(SipConnection);
```

Please check [`FirebaseConnection`](https://github.com/muaz-khan/RTCMultiConnection/tree/master/dev/FirebaseConnection.js) or [`PubNubConnection.js`](https://github.com/muaz-khan/RTCMultiConnection/tree/master/dev/PubNubConnection.js) to understand how it works.

For more information:

* https://rtcmulticonnection.herokuapp.com/demos/Audio+Video+TextChat+FileSharing.html#comment-2670178473
* https://rtcmulticonnection.herokuapp.com/demos/Audio+Video+TextChat+FileSharing.html#comment-2670182313

## `enableLogs`

By default, logs are enabled.
Expand Down Expand Up @@ -1264,37 +1313,6 @@ connection.getScreenConstraints = function(callback) {
</script>
```

## Firebase?

If you are willing to use Firebase instead of Socket.io there, open [GruntFile.js](https://github.com/muaz-khan/RTCMultiConnection/blob/master/Gruntfile.js#L26) and replace `SocketConnection.js` with `FirebaseConnection.js`.

Then use `grunt` to recompile RTCMultiConnection.js.

**Otherwise** if you don't want to modify RTCMultiConnection:

```html
<script src="/dev/globals.js"></script>
<script src="/dev/FirebaseConnection.js"></script>
<script>
var connection = new RTCMultiConnection();
connection.firebase = 'your-firebase-account';
// below line replaces FirebaseConnection
connection.setCustomSocketHandler(FirebaseConnection);
</script>
```

Demo: [https://rtcmulticonnection.herokuapp.com/demos/Firebase-Demo.html](https://rtcmulticonnection.herokuapp.com/demos/Firebase-Demo.html)

## PubNub?

Follow above all "firebase" steps and use `PubNubConnection.js` instead.

Please don't forget to use your own PubNub keys.

Demo: [https://rtcmulticonnection.herokuapp.com/demos/PubNub-Demo.html](https://rtcmulticonnection.herokuapp.com/demos/PubNub-Demo.html)

## Scalable Broadcasting

v3 now supports WebRTC scalable broadcasting. Two new API are introduced: `enableScalableBroadcast` and `singleBroadcastAttendees`.
Expand Down
29 changes: 15 additions & 14 deletions RTCMultiConnection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated: 2016-05-03 8:03:49 AM UTC
// Last time updated: 2016-05-15 4:12:35 AM UTC

// _____________________
// RTCMultiConnection-v3
Expand Down Expand Up @@ -416,13 +416,12 @@
});
};

connection.getUserMedia = connection.captureUserMedia = function(callback, session) {
session = session || connection.session;
connection.getUserMedia = connection.captureUserMedia = function(callback, sessionForced) {
callback = callback || function() {};
var session = sessionForced || connection.session;

if (connection.dontCaptureUserMedia || isData(session)) {
if (callback) {
callback();
}
callback();
return;
}

Expand All @@ -437,20 +436,22 @@
audio: isAudioPlusTab(connection) ? getAudioScreenConstraints(screen_constraints) : false,
video: screen_constraints,
isScreen: true
}, function() {
}, function(stream) {
if ((session.audio || session.video) && !isAudioPlusTab(connection)) {
var nonScreenSession = {};
for (var s in session) {
if (s !== 'screen') {
nonScreenSession[s] = session[s];
}
}
connection.invokeGetUserMedia(null, null, nonScreenSession);
connection.invokeGetUserMedia(sessionForced, callback, nonScreenSession);
return;
}
callback(stream);
});
});
} else if (session.audio || session.video) {
connection.invokeGetUserMedia();
connection.invokeGetUserMedia(sessionForced, callback, session);
}
}
};
Expand Down Expand Up @@ -853,13 +854,13 @@
session = connection.session;
}

if (localMediaConstraints instanceof MediaStream) {
throw localMediaConstraints;
if (!localMediaConstraints) {
localMediaConstraints = connection.mediaConstraints;
}

getUserMediaHandler({
onGettingLocalMedia: function(stream) {
var videoConstraints = localMediaConstraints ? localMediaConstraints.video : connection.mediaConstraints;
var videoConstraints = localMediaConstraints.video;
if (videoConstraints) {
if (videoConstraints.mediaSource || videoConstraints.mozMediaSource) {
stream.isScreen = true;
Expand All @@ -883,8 +884,8 @@
mPeer.onLocalMediaError(error, constraints);
},
localMediaConstraints: localMediaConstraints || {
audio: session.audio ? connection.mediaConstraints.audio : false,
video: session.video ? connection.mediaConstraints.video : false
audio: session.audio ? localMediaConstraints.audio : false,
video: session.video ? localMediaConstraints.video : false
}
});
};
Expand Down
10 changes: 5 additions & 5 deletions RTCMultiConnection.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "rtcmulticonnection",
"description": "RTCMultiConnection is a WebRTC JavaScript wrapper library runs top over RTCPeerConnection API to provide multi-session establishment scenarios.",
"version": "3.3.4",
"version": "3.3.5",
"authors": [
{
"name": "Muaz Khan",
"email": "[email protected]",
"homepage": "http://www.muazkhan.com/"
}
],
"main": "server.js",
"main": "RTCMultiConnection.js",
"keywords": [
"webrtc",
"rtcmulticonnection",
Expand Down
12 changes: 12 additions & 0 deletions demos/Files-Scalable-Broadcast.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ <h1><a href="https://github.com/muaz-khan/WebRTC-Scalable-Broadcast">WebRTC Scal

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

var broadcastId = '';
if(localStorage.getItem('rmc-broadcast-id')) {
broadcastId = localStorage.getItem('rmc-broadcast-id');
}
else {
broadcastId = connection.token();
}
document.getElementById('broadcast-id').value = broadcastId;
document.getElementById('broadcast-id').onkeyup = function() {
localStorage.setItem('rmc-broadcast-id', this.value);
};

connection.enableScalableBroadcast = true;
connection.maxRelayLimitPerUser = 1;

Expand Down
12 changes: 12 additions & 0 deletions demos/Scalable-Broadcast.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ <h1><a href="https://github.com/muaz-khan/WebRTC-Scalable-Broadcast">WebRTC Scal

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

var broadcastId = '';
if(localStorage.getItem('rmc-broadcast-id')) {
broadcastId = localStorage.getItem('rmc-broadcast-id');
}
else {
broadcastId = connection.token();
}
document.getElementById('broadcast-id').value = broadcastId;
document.getElementById('broadcast-id').onkeyup = function() {
localStorage.setItem('rmc-broadcast-id', this.value);
};

// document.getElementById('broadcast-id').value = connection.userid;

// user need to connect server, so that others can reach him.
Expand Down
16 changes: 14 additions & 2 deletions demos/Scalable-Screen-Broadcast.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ <h1><a href="https://github.com/muaz-khan/WebRTC-Scalable-Broadcast">WebRTC Scal

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

var broadcastId = '';
if(localStorage.getItem('rmc-broadcast-id')) {
broadcastId = localStorage.getItem('rmc-broadcast-id');
}
else {
broadcastId = connection.token();
}
document.getElementById('broadcast-id').value = broadcastId;
document.getElementById('broadcast-id').onkeyup = function() {
localStorage.setItem('rmc-broadcast-id', this.value);
};

// document.getElementById('broadcast-id').value = connection.userid;

// user need to connect server, so that others can reach him.
Expand All @@ -167,8 +179,8 @@ <h1><a href="https://github.com/muaz-khan/WebRTC-Scalable-Broadcast">WebRTC Scal

connection.session = hintsToJoinBroadcast.typeOfStreams;
connection.sdpConstraints.mandatory = {
OfferToReceiveVideo: !!connection.session.video,
OfferToReceiveAudio: !!connection.session.audio
OfferToReceiveVideo: true,
OfferToReceiveAudio: false
};
connection.join(hintsToJoinBroadcast.userid);
});
Expand Down
Loading

0 comments on commit d127a39

Please sign in to comment.