Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 117 lines (98 sloc) 3.54 KB
<!--
> Muaz Khan - github.com/muaz-khan
> MIT License - www.webrtc-experiment.com/licence
> Documentation - www.RTCMultiConnection.org
-->
<script>
if(!location.hash.replace('#', '').length) {
location.href = location.href.split('#')[0] + '#' + (Math.random() * 100).toString().replace('.', '');
location.reload();
}
</script>
<title>OneWay Screen & Two-Way Audio using RTCMultiConnection</title>
<link rel="stylesheet" href="//cdn.webrtc-experiment.com/style.css">
<style>
video {
vertical-align: top;
width: 60%;
}
audio {
float: right;
}
</style>
<h1>OneWay Screen & Two-Way Audio using <a href="http://www.rtcmulticonnection.org/">RTCMultiConnection</a></h1>
<br><br>
<blockquote style="background: #f3b7b7;border: 5px solid black;border-radius: 5px; padding: 10px;">
This demo is <span style="border: 1px dotted red; background: yellow; padding: 2px 5px;">out-dated i.e. deprecated (written in 2013)</span>.
<br><br>
Please try other demos: <a href="https://github.com/muaz-khan/RTCMultiConnection">https://github.com/muaz-khan/RTCMultiConnection</a>
</blockquote>
<br />
<br />
<button id="share-screen-and-audio">Share Screen + Audio</button>
<hr />
<div id="container"></div>
<script src="https://cdn.webrtc-experiment.com/socket.io.js"></script>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
<script src="https://cdn.webrtc-experiment.com/CodecsHandler.js"></script>
<script src="https://cdn.webrtc-experiment.com/IceServersHandler.js"></script>
<script src="https://cdn.webrtc-experiment.com/RTCMultiConnection.js"></script>
<script>
var connection = new RTCMultiConnection();
// https://github.com/muaz-khan/WebRTC-Experiment/tree/master/socketio-over-nodejs
var SIGNALING_SERVER = 'https://socketio-over-nodejs2.herokuapp.com:443/';
connection.openSignalingChannel = function(config) {
var channel = config.channel || connection.channel || 'default-namespace';
var sender = Math.round(Math.random() * 9999999999) + 9999999999;
io.connect(SIGNALING_SERVER).emit('new-channel', {
channel: channel,
sender: sender
});
var socket = io.connect(SIGNALING_SERVER + channel);
socket.channel = channel;
socket.on('connect', function() {
if (config.callback) config.callback(socket);
});
socket.send = function(message) {
socket.emit('message', {
sender: sender,
data: message
});
};
socket.on('message', config.onmessage);
};
connection.session = {
audio: true,
screen: true
};
var sessions = {};
connection.onNewSession = function(session) {
// if room is not transmitted once;
// "onNewSession" will be called multiple times for same session;
// we need to store session-id in an object.
if (sessions[session.sessionid]) return;
sessions[session.sessionid] = session;
session.join({
audio: true
});
};
connection.onstream = function(e) {
document.querySelector('div#container').appendChild(e.mediaElement);
};
connection.connect();
document.querySelector('#share-screen-and-audio').onclick = function() {
this.disabled = true;
connection.open();
};
</script>
<p>This demo uses <a href="http://www.RTCMultiConnection.org/docs/">RTCMultiConnection.js</a> to:</p>
<ol>
<li>Share screen in one-way.</li>
<li>Share audio in two-way; among all users.</li>
</ol>
<pre>
// initiator's session initiator.session = { audio: true, screen: true };
participant.onNewSession = function (session) {
session.join(<strong>{ audio: true }</strong> );
};
</pre>