Skip to content

Commit 0a98090

Browse files
authored
Merge pull request #126 from aiham/fix/update-js-samples
Update JS samples
2 parents 78bb496 + eeb87a0 commit 0a98090

File tree

6 files changed

+77
-47
lines changed

6 files changed

+77
-47
lines changed

sample/Archiving/public/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: 19 additions & 8 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" });
13-
});
17+
session.subscribe(event.stream, 'subscribers', {
18+
insertMode : 'append'
19+
}, function(error) {
20+
if (error) {
21+
console.error('Failed to subscribe', error);
22+
}
23+
});
24+
});

sample/Archiving/src/main/resources/com/example/freemarker/host.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<#include "header.ftl">
22

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

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

sample/Archiving/src/main/resources/com/example/freemarker/participant.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<#include "header.ftl">
2-
<script src="//static.opentok.com/webrtc/v2.2/js/opentok.min.js"></script>
2+
<script src="https://static.opentok.com/v2/js/opentok.min.js"></script>
33

44
<div class="container bump-me">
55

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
// Initialize an OpenTok Session object
2-
var session = OT.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 = OT.initPublisher(apiKey, 'publisher');
5+
var publisher = OT.initPublisher('publisher');
66

77
// Attach an event handler for when the session dispatches the 'streamCreated' event.
88
session.on('streamCreated', function(event) {
9-
// This function runs when another client publishes a stream (eg. session.publish())
9+
// This function runs when another client publishes a stream (eg. session.publish())
1010

11-
// Subscribe to the stream that caused this event, put it inside the DOM element with id='subscribers'
12-
session.subscribe(event.stream, 'subscribers', {
13-
insertMode: 'append'
14-
});
11+
// Subscribe to the stream that caused this event, put it inside the DOM element with id='subscribers'
12+
session.subscribe(event.stream, 'subscribers', {
13+
insertMode: 'append'
14+
}, function(error) {
15+
if (error) {
16+
console.error('Failed to subscribe', error);
17+
}
18+
});
1519
});
1620

1721
// Connect to the Session using the 'apiKey' of the application and a 'token' for permission
18-
session.connect(apiKey, token, function(error) {
19-
// This function runs when session.connect() asynchronously completes
20-
21-
// Handle connection errors
22-
if (error) {
23-
return console.error(error);
24-
}
22+
session.connect(token, function(error) {
23+
// This function runs when session.connect() asynchronously completes
2524

25+
// Handle connection errors
26+
if (error) {
27+
console.error('Failed to connect', error);
28+
} else {
2629
// Publish the publisher we initialzed earlier (this will trigger 'streamCreated' on other
2730
// clients)
28-
session.publish(publisher);
31+
session.publish(publisher, function(error) {
32+
if (error) {
33+
console.error('Failed to publish', error);
34+
}
35+
});
36+
}
2937
});

sample/HelloWorld/src/main/resources/com/example/freemarker/index.ftl

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 = '${ apiKey }';
99
var sessionId = '${ sessionId }';

0 commit comments

Comments
 (0)