socket.io/index.html
Private ?? #123456789 Start Transmitting Yourself!
// http://www.webrtc-experiment.com/socket.io/PeerConnection.js
var peer = new **PeerConnection** (' **http://domain:port**');
peer. **onStreamAdded** = function(e) {
document.body.appendChild(e.mediaElement);
};
// the easiest method of "manual" peers connection is
// call "sendParticipationRequest" and pass user-id of the target user
peer. **sendParticipationRequest** (userid);
//otherwise, call "startBroadcasting"
// (behind the scene) this function will be invoked
// recursively until a participant found
peer. **startBroadcasting** ();
var offerer = new **PeerConnection** (' **http://domain:port**', ' **message**', ' **offerer**');
offerer. **onStreamAdded** = function(e) {
document.body.appendChild(e.mediaElement);
};
var answerer = new **PeerConnection** (' **http://domain:port**', ' **message**', ' **answerer**');
answerer. **onStreamAdded** = function(e) {
document.body.appendChild(e.mediaElement);
};
answerer. **sendParticipationRequest** ( **'offerer'** );
It is upto you to decide when to capture the stream; how to capture; and the quality of the stream.
function getUserMedia(callback) {
var hints = {
audio: true,
video: {
optional: [],
// capture super-hd stream!
mandatory: {
minWidth: 1280,
minHeight: 720,
maxWidth: 1920,
maxHeight: 1080,
minAspectRatio: 1.77
}
}
};
navigator.getUserMedia(hints, function (stream) {
// you can use "peer.addStream" to attach stream
// peer.addStream(stream);
// or peer.MediaStream = stream;
callback(stream);
// preview local video
var video = document.createElement('video');
video.srcObject = stream;
video.controls = true;
video.muted = true;
peer.onStreamAdded({
mediaElement: video,
userid: 'self',
stream: stream
});
});
}
var channel = location.href.replace(/\/|:|#|%|\.|\[|\]/g, '');
var sender = Math.round(Math.random() * 999999999) + 999999999;
// var SIGNALING_SERVER = 'https://socketio-over-nodejs2.herokuapp.com:443/';
var SIGNALING_SERVER = 'https://webrtcweb.com:9559/';
io.connect(SIGNALING_SERVER).emit('new-channel', {
channel: channel,
sender: sender
});
var socket = io.connect(SIGNALING_SERVER + channel);
socket.send = function (message) {
socket.emit('message', {
sender: sender,
data: message
});
};
// pass "socket" object over the constructor instead of URL
var peer = new PeerConnection(socket);
Check other signaling examples.
Send MessageEnter your email too; if you want "direct" reply!