Table of Contents |
---|
Example of TURN server usage
The example of firewall traversal video streaming and playback using TURN server. It works in all browsers except Microsoft Legacy Edge because this browser do not support TURN over TCP.
The code of the example
The source code of the example is on WCS server by this path:
...
where host is your WCS server address.
Analyzing the code
To analyze the code get firewallget firewall-traversal-streaming.js file version with hash 66cc393 hash ecbadc3 that can be found found here and and is available to download in build build 2.0.5.28.2753.133.212.
1. API initializing.
Flashphoner.init() code
Code Block | ||||
---|---|---|---|---|
| ||||
Flashphoner.init({flashMediaProviderSwfLocation: '../../../../media-provider.swf'}); |
2. Connection to the server.
Flashphoner.createSession() code
These parameters are passed to createSession() method:
...
3. Receiving the event confirming successful connection
ConnectionStatusEvent ESTABLISHED ESTABLISHED code
Code Block | ||||
---|---|---|---|---|
| ||||
Flashphoner.createSession(options).on(SESSION_STATUS.ESTABLISHED, function (session) { setStatus("#connectStatus", session.status()); onConnected(session); }).on(SESSION_STATUS.DISCONNECTED, function () { ... }).on(SESSION_STATUS.FAILED, function () { ... }); |
4. Video streaming
session.createStream(), stream.publish() code
These parameters are passed to createStream() method:
...
5.Receiving the event confirming successful streaming
StreamStatusEvent PUBLISHING PUBLISHING code
Code Block | ||||
---|---|---|---|---|
| ||||
session.createStream({ ... }).on(STREAM_STATUS.PUBLISHING, function (stream) { setStatus("#publishStatus", STREAM_STATUS.PUBLISHING); onPublishing(stream); }).on(STREAM_STATUS.UNPUBLISHED, function () { ... }).on(STREAM_STATUS.FAILED, function () { ... }).publish(); |
6. Stream playback
session.createStream(), stream.play() code
These parameters are passed to createStream() method:
...
7. Receiving the event confirming successful stream playback
StreamStatusEvent PLAYING PLAYING code
Code Block | ||||
---|---|---|---|---|
| ||||
session.createStream({ ... }).on(STREAM_STATUS.PLAYING, function (stream) { document.getElementById(stream.id()).addEventListener('resize', function (event) { resizeVideo(event.target); }); setStatus("#playStatus", stream.status()); onPlaying(stream); }).on(STREAM_STATUS.STOPPED, function () { ... }).on(STREAM_STATUS.FAILED, function () { ... }).play(); |
8. Stream playback stop
stream.stop() code
Code Block | ||||
---|---|---|---|---|
| ||||
function onPlaying(stream) { $("#playBtn").text("Stop").off('click').click(function () { $(this).prop('disabled', true); stream.stop(); }).prop('disabled', false); } |
9. Receiving the event confirming successful playback stop
StreamStatusEvent STOPPED STOPPED code
Code Block | ||||
---|---|---|---|---|
| ||||
session.createStream({ name: streamName, display: remoteVideo }).on(STREAM_STATUS.PLAYING, function (stream) { ... }).on(STREAM_STATUS.STOPPED, function () { setStatus("#playStatus", STREAM_STATUS.STOPPED); onStopped(); }).on(STREAM_STATUS.FAILED, function () { ... }).play(); |
10. Streaming stop
stream.stop() code
Code Block | ||||
---|---|---|---|---|
| ||||
function onPublishing(stream) { $("#publishBtn").text("Stop").off('click').click(function () { $(this).prop('disabled', true); stream.stop(); }).prop('disabled', false); } |
11. Receiving the event confirming successful streaming stop
StreamStatusEvent UNPUBLISHED UNPUBLISHED code
Code Block | ||||
---|---|---|---|---|
| ||||
session.createStream({ ... }).on(STREAM_STATUS.PUBLISHING, function (stream) { ... }).on(STREAM_STATUS.UNPUBLISHED, function () { setStatus("#publishStatus", STREAM_STATUS.UNPUBLISHED); onUnpublished(); }).on(STREAM_STATUS.FAILED, function () { ... }).publish(); |