|
1 | | -var session = OT.initSession(sessionId); |
2 | | -session.on("streamCreated", function (event) { |
| 1 | +var session = OT.initSession(apiKey, sessionId); |
| 2 | +session.on('streamCreated', function(event) { |
3 | 3 | var tokenData = event.stream.connection.data; |
4 | | - if (tokenData && tokenData.includes("sip=true")) { |
5 | | - var element = "sipPublisherContainer"; |
| 4 | + if (tokenData && tokenData.includes('sip=true')) { |
| 5 | + var element = 'sipPublisherContainer'; |
6 | 6 | } else { |
7 | | - var element = "webrtcPublisherContainer"; |
| 7 | + var element = 'webrtcPublisherContainer'; |
8 | 8 | } |
9 | | - session.subscribe(event.stream, element, { insertMode: "append" }); |
| 9 | + session.subscribe(event.stream, element, { |
| 10 | + insertMode: 'append' |
| 11 | + }, function(error) { |
| 12 | + if (error) { |
| 13 | + console.error('Failed to subscribe', error); |
| 14 | + } |
| 15 | + }); |
10 | 16 | }) |
11 | | -.connect(apiKey, token, function (err) { |
12 | | - if (err) return; |
13 | | - session.publish("selfPublisherContainer", { |
14 | | - insertMode: "append", |
15 | | - height: "120px", |
16 | | - width: "160px" |
| 17 | +.connect(token, function(error) { |
| 18 | + if (error) { |
| 19 | + console.error('Failed to connect', error); |
| 20 | + return; |
| 21 | + } |
| 22 | + session.publish('selfPublisherContainer', { |
| 23 | + insertMode: 'append', |
| 24 | + height: '120px', |
| 25 | + width: '160px' |
| 26 | + }, function(error) { |
| 27 | + if (error) { |
| 28 | + console.error('Failed to publish', error); |
| 29 | + } |
17 | 30 | }); |
18 | 31 | }); |
19 | | -$('#startSip').click(function (event) { |
| 32 | +$('#startSip').click(function(event) { |
20 | 33 | $.post('/sip/start', {sessionId: sessionId, apiKey: apiKey}) |
21 | | - .fail(function () { |
| 34 | + .fail(function() { |
22 | 35 | console.log('Failed to start SIP call - sample app server returned error.'); |
23 | 36 | }); |
24 | 37 | }); |
25 | | -$('#stopSip').click(function (event) { |
26 | | - OT.subscribers.where().forEach(function (subscriber) { |
| 38 | +$('#stopSip').click(function(event) { |
| 39 | + OT.subscribers.where().forEach(function(subscriber) { |
27 | 40 | var connection = subscriber.stream.connection; |
28 | | - if (connection.data && connection.data.includes("sip=true")) { |
| 41 | + if (connection.data && connection.data.includes('sip=true')) { |
29 | 42 | session.forceDisconnect(connection.connectionId); |
30 | 43 | } |
31 | 44 | }); |
|
0 commit comments