Last active
August 29, 2015 14:02
-
-
Save tkbremnes/6b4e61ff6a79e6265a9a to your computer and use it in GitHub Desktop.
Appear.in embedding with webRTC feature detection
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
<html> | |
<body> | |
<h1>My awesome service</h1> | |
<p>Is appear.in compatible? <span id="compatibility-test-result">Maybe</span></p> | |
<button id="create-room-button">Create room</button> | |
<iframe id="appearin-room"></iframe> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script src="http://iswebrtcready.appear.in/apiv2.js"></script> | |
<script> | |
document.getElementById('create-room-button').onclick = function () { | |
// create the room on button press | |
var randomRoomNameGenerator = function () { | |
// predefine the alphabet used. | |
var alphabet = 'qwertyuiopasdfghjklzxcvbnm1234567890'; | |
// set the length of the room name | |
var roomNameLength = 30; | |
// initialize the room name as an empty string | |
var roomName = ''; | |
// repeat this 30 times | |
for (var i=0; i<roomNameLength; i++) { | |
// get a random character from the alphabet | |
var character = alphabet[Math.round(Math.random()*(alphabet.length-1))]; | |
// add the character to the roomName | |
roomName = roomName + character; | |
} | |
// pre- and append appear.in URL elements | |
roomName = 'https://appear.in/' + roomName + '?lite'; | |
// return the result | |
return roomName; | |
} | |
// setting a room name. Pair this with the random room generator code above for real power | |
var roomName = randomRoomNameGenerator(); | |
// set the iframe source to load the room | |
var iframe = document.getElementById('appearin-room'); | |
iframe.setAttribute('src', roomName); | |
} | |
API.isAppearinCompatible(function (data) { | |
if (data.isSupported) { | |
document.getElementById('compatibility-test-result').innerHTML = 'Yes'; | |
} | |
else { | |
document.getElementById('compatibility-test-result').innerHTML = 'No'; | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment