Skip to content

Instantly share code, notes, and snippets.

@domadev812
Forked from GleasonK/01.html
Last active October 30, 2017 02:54
Show Gist options
  • Save domadev812/a087bb68757b1fa614a4f16663960d3e to your computer and use it in GitHub Desktop.
Save domadev812/a087bb68757b1fa614a4f16663960d3e to your computer and use it in GitHub Desktop.
SimpleRTC Demo Code
<div id="vid-box"></div>
<form name="loginForm" id="login" action="#" onsubmit="return login(this);">
<input type="text" name="username" id="username" placeholder="Pick a username!" />
<input type="submit" name="login_submit" value="Log In">
</form>
<form name="callForm" id="call" action="#" onsubmit="return makeCall(this);">
<input type="text" name="number" placeholder="Enter user to dial!" />
<input type="submit" value="Call"/>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.17.0.js"></script>
<script src="https://cdn.pubnub.com/webrtc/webrtc.js"></script>
var video_out = document.getElementById("vid-box");
function login(form) {
var phone = window.phone = PHONE({
number : form.username.value || "Anonymous", // listen on username line else Anonymous
publish_key : 'your_pub_key',
subscribe_key : 'your_sub_key',
});
phone.ready(function(){ form.username.style.background="#55ff5b"; });
phone.receive(function(session){
session.connected(function(session) { video_out.appendChild(session.video); });
session.ended(function(session) { video_out.innerHTML=''; });
});
return false; // So the form does not submit.
}
function makeCall(form){
if (!window.phone) alert("Login First!");
else phone.dial(form.number.value);
return false;
}
cd <project-dir>
# Python 2
python -m SimpleHTTPServer <portNo>
# Python 3
python -m http.server <portNo>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment