Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
Last active August 29, 2015 14:20
Show Gist options
  • Save kwhinnery/41925d39f5eb6f023f2c to your computer and use it in GitHub Desktop.
Save kwhinnery/41925d39f5eb6f023f2c to your computer and use it in GitHub Desktop.
This is a fictional API I would have designed for Video.
<html>
<head>
<title>Fantasy Video API</title>
</head>
<body>
<video id="me"></video>
<video id="you"></video>
<button id="invite">Invite you@twilio.com</button>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="//cdn.twilio.com/sdks/conversations/0.0.1/conversations.min.js"></script>
<script>
// Init with key you can copy/paste from account portal
// and a unique identifier for the client
var me = twilio.init('APP123ABC', 'me@twilio.com');
// Listen for incoming invitations
me.on('invite', function(conversation) {
// Join the conversation (accepting the invitation)
// and show your feed in video#me
conversation.join('#me');
// Show the first participant in the conversation
// in the other video tag
conversation.participants[0].show('#you');
});
// Listen for any error - this could be initialization error
// Or any other local error
me.on('error', function(err) {
console.log(err.message);
console.log(err.code);
// HTML page with error code guidance like REST API
console.log(err.moreInfo);
});
// Initiate a conversation
$('#invite').on('click', function() {
// Create a conversation with a unique ID
var conversation = twilio.conversation('partytime');
// Immediately join the conversation yourself, showing
// your local video feed
conversation.join('#me');
// Invite a known client to the conversation
var you = conversation.invite('you@twilio.com', '#you');
// In the happy path, no more code is necessary, when
// you@twilio.com joins, they show up in the #you
// video and ppl can start talking
// However, you might care about events, so...
// Fire when this participant joins...
you.on('join', function() {});
// Fire if they decline to join...
you.on('decline', function() {});
// Fire if there's a problem with their stream...
you.on('error', function(err) {
console.log(err.message);
console.log(err.code);
console.log(err.moreInfo);
});
// Fire when anyone joins the conversation...
conversation.on('join', function(participant) {
console.log(participant.id);
});
// Fire on any error for this conversation
conversation.on('error', function(err) {
console.log(err.message);
console.log(err.code);
console.log(err.moreInfo);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment