Skip to content

Commit 971ab2d

Browse files
authored
Merge pull request #108 from aiham/fix/update-js-samples
Update JS samples
2 parents c895b68 + 3f23602 commit 971ab2d

File tree

6 files changed

+70
-36
lines changed

6 files changed

+70
-36
lines changed

sample/Archiving/static/js/host.js

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,61 @@
1-
var session = OT.initSession(sessionId),
2-
publisher = OT.initPublisher("publisher"),
1+
var session = OT.initSession(apiKey, sessionId),
2+
publisher = OT.initPublisher('publisher'),
33
archiveID = null;
44

5-
session.connect(apiKey, token, function(err, info) {
6-
if(err) {
7-
alert(err.message || err);
5+
session.connect(token, function(error, info) {
6+
if (error) {
7+
console.error('Failed to connect', error);
8+
} else {
9+
session.publish(publisher, function(error) {
10+
if (error) {
11+
console.error('Failed to publish', error);
12+
}
13+
});
814
}
9-
session.publish(publisher);
1015
});
1116

1217
session.on('streamCreated', function(event) {
13-
session.subscribe(event.stream, "subscribers", { insertMode: "append" });
18+
session.subscribe(event.stream, 'subscribers', {
19+
insertMode: 'append'
20+
}, function(error) {
21+
if (error) {
22+
console.error('Failed to subscribe', error);
23+
}
24+
});
1425
});
1526

1627
session.on('archiveStarted', function(event) {
1728
archiveID = event.id;
18-
console.log("ARCHIVE STARTED");
19-
$(".start").hide();
20-
$(".stop").show();
29+
console.log('ARCHIVE STARTED');
30+
$('.start').hide();
31+
$('.stop').show();
2132
disableForm();
2233
});
2334

2435
session.on('archiveStopped', function(event) {
2536
archiveID = null;
26-
console.log("ARCHIVE STOPPED");
27-
$(".start").show();
28-
$(".stop").hide();
37+
console.log('ARCHIVE STOPPED');
38+
$('.start').show();
39+
$('.stop').hide();
2940
enableForm();
3041
});
3142

3243
$(document).ready(function() {
33-
$(".start").click(function (event) {
34-
var options = $(".archive-options").serialize();
44+
$('.start').click(function (event) {
45+
var options = $('.archive-options').serialize();
3546
disableForm();
36-
$.post("/start", options).fail(enableForm);
47+
$.post('/start', options).fail(enableForm);
3748
}).show();
38-
$(".stop").click(function(event){
39-
$.get("stop/" + archiveID);
49+
$('.stop').click(function(event){
50+
$.get('stop/' + archiveID);
4051
}).hide();
4152
});
4253

4354

4455
function disableForm() {
45-
$(".archive-options-fields").attr('disabled', 'disabled');
56+
$('.archive-options-fields').attr('disabled', 'disabled');
4657
}
4758

4859
function enableForm() {
49-
$(".archive-options-fields").removeAttr('disabled');
50-
}
60+
$('.archive-options-fields').removeAttr('disabled');
61+
}
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
var session = OT.initSession(sessionId),
2-
publisher = OT.initPublisher("publisher");
1+
var session = OT.initSession(apiKey, sessionId),
2+
publisher = OT.initPublisher('publisher');
33

4-
session.connect(apiKey, token, function(err, info) {
5-
if(err) {
6-
alert(err.message || err);
4+
session.connect(token, function(error, info) {
5+
if (error) {
6+
console.error('Failed to connect', error);
7+
} else {
8+
session.publish(publisher, function(error) {
9+
if (error) {
10+
console.error('Failed to publish', error);
11+
}
12+
});
713
}
8-
session.publish(publisher);
914
});
1015

1116
session.on('streamCreated', function(event) {
12-
session.subscribe(event.stream, "subscribers", { insertMode : "append" });
17+
session.subscribe(event.stream, 'subscribers', {
18+
insertMode : 'append'
19+
}, function(error) {
20+
if (error) {
21+
console.error('Failed to subscribe', error);
22+
}
23+
});
1324
});

sample/Archiving/templates/host.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends "base.html" %}
22
{% block content %}
33

4-
<script src="//static.opentok.com/webrtc/v2.2/js/opentok.min.js"></script>
4+
<script src="https://static.opentok.com/v2/js/opentok.min.js"></script>
55

66
<div class="container bump-me">
77

sample/Archiving/templates/participant.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends "base.html" %}
22
{% block content %}
33

4-
<script src="//static.opentok.com/webrtc/v2.2/js/opentok.min.js"></script>
4+
<script src="https://static.opentok.com/v2/js/opentok.min.js"></script>
55

66
<div class="container bump-me">
77

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Initialize an OpenTok Session object
2-
var session = TB.initSession(sessionId);
2+
var session = OT.initSession(apiKey, sessionId);
33

44
// Initialize a Publisher, and place it into the element with id="publisher"
5-
var publisher = TB.initPublisher(apiKey, 'publisher');
5+
var publisher = OT.initPublisher('publisher');
66

77
// Attach event handlers
88
session.on({
@@ -11,7 +11,11 @@ session.on({
1111
sessionConnected: function(event) {
1212
// Publish the publisher we initialzed earlier (this will trigger 'streamCreated' on other
1313
// clients)
14-
session.publish(publisher);
14+
session.publish(publisher, function(error) {
15+
if (error) {
16+
console.error('Failed to publish', error);
17+
}
18+
});
1519
},
1620

1721
// This function runs when another client publishes a stream (eg. session.publish())
@@ -23,10 +27,18 @@ session.on({
2327
document.getElementById('subscribers').appendChild(subContainer);
2428

2529
// Subscribe to the stream that caused this event, put it inside the container we just made
26-
session.subscribe(event.stream, subContainer);
30+
session.subscribe(event.stream, subContainer, function(error) {
31+
if (error) {
32+
console.error('Failed to subscribe', error);
33+
}
34+
});
2735
}
2836

2937
});
3038

3139
// Connect to the Session using the 'apiKey' of the application and a 'token' for permission
32-
session.connect(apiKey, token);
40+
session.connect(token, function(error) {
41+
if (error) {
42+
console.error('Failed to connect', error);
43+
}
44+
});

sample/HelloWorld/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8" />
55
<title>OpenTok Hello World</title>
6-
<script src="//static.opentok.com/webrtc/v2.2/js/TB.min.js"></script>
6+
<script src="https://static.opentok.com/v2/js/opentok.min.js"></script>
77
<script type="text/javascript">
88
var apiKey = '{{ api_key }}';
99
var sessionId = '{{ session_id }}';

0 commit comments

Comments
 (0)