...
To analyze the code get firewall-traversal-streaming.js file version with hash c306c1bbf49bfcbd8e24be927ae95f63b7dbaaba hash 66cc393 that can be found here and and is available to download in build 0.5.28.27472753.133.
1. API initializing.
Flashphoner.init() code
Code Block | ||||
---|---|---|---|---|
| ||||
Flashphoner.init({flashMediaProviderSwfLocation: '../../../../media-provider.swf'}); |
...
Flashphoner.createSession() code
These parameters are passed to createSession() method:
...
Code Block | ||||
---|---|---|---|---|
| ||||
Flashphoner.createSession(var options = { urlServer: url, mediaOptions: { "iceServers": [ { 'url': $('#urlTurnServer').val(), 'username': $('#usernameTurnServer').val(), 'credential': $('#credentialTurnServer').val() } ] } }; if ($("#forceRelay").is(':checked')) { options.mediaOptions.iceTransportPolicy = "relay"; } Flashphoner.createSession(options).on(SESSION_STATUS.ESTABLISHED, function (session) { ... }); |
3. Receiving the event confirming successful connection
ConnectionStatusEvent 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 () { ... }); |
...
session.createStream(), publish() code
These parameters are passed to createStream() method:
...
StreamStatusEvent PUBLISHING code
Code Block | ||||
---|---|---|---|---|
| ||||
session.createStream({ name: streamName, ... display: localVideo, cacheLocalResources: true, receiveVideo: false, receiveAudio: false }).on(STREAM_STATUS.PUBLISHING, function (stream) { setStatus("#publishStatus", STREAM_STATUS.PUBLISHING); onPublishing(stream); }).on(STREAM_STATUS.UNPUBLISHED, function () { ... }).on(STREAM_STATUS.FAILED, function () { ... }).publish(); |
...
session.createStream(), play() code
These parameters are passed to createStream() method:
...
StreamStatusEvent PLAYING code
Code Block | ||||
---|---|---|---|---|
| ||||
session.createStream({ name: streamName, display: remoteVideo... }).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); } |
...
StreamStatusEvent 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); } |
...
StreamStatusEvent UNPUBLISHED code
Code Block | ||||
---|---|---|---|---|
| ||||
session.createStream({ name: streamName, display: localVideo, cacheLocalResources: true, receiveVideo: false, receiveAudio: false... }).on(STREAM_STATUS.PUBLISHING, function (stream) { ... }).on(STREAM_STATUS.UNPUBLISHED, function () { setStatus("#publishStatus", STREAM_STATUS.UNPUBLISHED); onUnpublished(); }).on(STREAM_STATUS.FAILED, function () { ... }).publish(); |