Created
April 4, 2014 02:22
-
-
Save peterhpchen/9966907 to your computer and use it in GitHub Desktop.
RTCPeerConnection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webRTCHub = $.connection.rtcHub; | |
webRTCHub.client.sendMessage = sendMessage; | |
$.connection.hub.start(startHub); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<video id="videoLocal" autoplay></video> | |
<video id="videoRemote" autoplay></video> | |
<button id="startBtn" disabled="disabled">Start Call</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="Scripts/adapter.js"></script> | |
<script src="Scripts/jquery-1.6.4.js"></script> | |
<script src="Scripts/jquery.signalR-2.0.3.js"></script> | |
<script src="signalr/hubs"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendMessage(data) { | |
var message = JSON.parse(data); | |
var connection = localPeerConnection || initialRTCPeerConnectionAPI(); | |
// An SDP message contains connection and media information, and is either an 'offer' or an 'answer' | |
if (message.sdp) { | |
connection.setRemoteDescription(new RTCSessionDescription(message.sdp), function () { | |
if (connection.remoteDescription.type == 'offer') { | |
trace('received offer, sending answer...'); | |
// Add our stream to the connection to be shared | |
connection.addStream(localMediaStream); | |
// Create an SDP response | |
connection.createAnswer(function (desc) { | |
// Which becomes our local session description | |
connection.setLocalDescription(desc, function () { | |
// And send it to the originator, where it will become their RemoteDescription | |
webRTCHub.server.send(JSON.stringify({ 'sdp': connection.localDescription })); | |
}); | |
}, function (error) { trace('Error creating session description: ' + error); }); | |
} else if (connection.remoteDescription.type == 'answer') { | |
trace('got an answer'); | |
} | |
}); | |
} else if (message.candidate) { | |
trace('adding ice candidate...'); | |
connection.addIceCandidate(new RTCIceCandidate(message.candidate)); | |
} | |
localPeerConnection = connection; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web; | |
using Microsoft.AspNet.SignalR; | |
namespace WebRTCDemoWithSignalR | |
{ | |
public class rtcHub : Hub | |
{ | |
public void Send(string message) | |
{ | |
// Call the sendMessage method to update clients. | |
Clients.Others.sendMessage(message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment