...
1. Initialization of the API. line 8API is initialized after loading the page. For Flash support, the path to SWF file is passed to the
Flashphoner.init() method. code
Code Block | ||||
---|---|---|---|---|
| ||||
Flashphoner.init({flashMediaProviderSwfLocation: '../../../../media-provider.swf'}); |
2. Connection to server. line 57Connection to server is established when Start button is clicked.
Flashphoner.createSession() code
Code Block | ||||
---|---|---|---|---|
| ||||
Flashphoner.createSession({urlServer: url}).on(SESSION_STATUS.ESTABLISHED, function(session){ setStatus(session.status()); //session connected, start playback publishStream(session); }).on(SESSION_STATUS.DISCONNECTED, function(){ setStatus(SESSION_STATUS.DISCONNECTED); onStopped(); }).on(SESSION_STATUS.FAILED, function(){ setStatus(SESSION_STATUS.FAILED); onStopped(); }); |
Session is created with method createSession(). Callback function, which will be called in case of successfully established connection (status SESSION_STATUS.ESTABLISHED), is added.
3. Video streaming. line 73
...
3. Receiving the event confirming successful connection
ConnectionStatusEvent ESTABLISHED code
Code Block | ||||
---|---|---|---|---|
| ||||
Flashphoner.createSession({urlServer: url}).on(SESSION_STATUS.ESTABLISHED, function(session){
setStatus(session.status());
//session connected, start playback
publishStream(session);
}).on(SESSION_STATUS.DISCONNECTED, function(){
...
}).on(SESSION_STATUS.FAILED, function(){
...
}); |
4. Video streaming.
session.createStream(), and function publish() is called to publish the stream. code
When stream is created, the following parameters are passed
- streamName - name of the stream
- localVideo - <div> element, in which video from camera will be displayed
- true for parameter 'record' - to enable stream recording
Code Block | ||||
---|---|---|---|---|
| ||||
session.createStream({
name: streamName,
display: localVideo,
record: true
...
}).publish(); |
5. Receiving the event confirming successful streaming
StreamStatusEvent PUBLISHING code
Code Block | ||||
---|---|---|---|---|
| ||||
session.createStream({ name: streamName, display: localVideo, record: true }).on(STREAM_STATUS.PUBLISHING, function(stream) { setStatus(stream.status()); onStarted(stream); }).on(STREAM_STATUS.UNPUBLISHED, function(stream) { ... }).on(STREAM_STATUS.FAILED, function(stream) { setStatus(stream.status()); showDownloadLink(stream.getRecordInfo()); onStopped();... }).publish(); |
6. Streaming stop
stream.stop() code
Code Block | ||||
---|---|---|---|---|
| ||||
function onStarted(stream) {
$("#publishBtn").text("Stop").off('click').click(function(){
$(this).prop('disabled', true);
stream.stop();
}).prop('disabled', false);
} |
7. Receiving the event confirming successful streaming stop
StreamStatusEvent UNPUBLISHED code
On receiving the event, showDownloadLink() function is called to form the record file download link. The record file name returned by stream.getRecordInfo() method passed to the showDownloadLink() function.
Code Block | ||||
---|---|---|---|---|
| ||||
session.createStream({ name: streamName, display: localVideo, record: true }).on(STREAM_STATUS.PUBLISHING, function(stream) { ... }).on(STREAM_STATUS.FAILEDUNPUBLISHED, function(stream) { setStatus(stream.status()); showDownloadLink(stream.getRecordInfo()); onStopped(); }).publish(); |
...
on(STREAM_STATUS.FAILED |
...
STREAM_STATUS.PUBLISHING - when this status is received, function onStarted() of the example is called to make appropriate changes in controls of the interface.
STREAM_STATUS.UNPUBLISHED and STREAM_STATUS.FAILED - when one of these statuses is received
- function showDownloadLink() of the example is called to form the download link
- function onStopped() of the example is called to make appropriate changes in controls of the interface
When showDownloadLink() is called, the name of the file with the recording is passed to it. To get the file name, method stream.getRecordInfo() is used.
...
, function(stream) {
...
}).publish(); |
8. Download link.
Code Block | ||||
---|---|---|---|---|
| ||||
function showDownloadLink(name) { if (name) { // Set correct path for records. Stream records are saved to WCS_HOME/records directory. // http://flashphoner.com/docs/wcs4/wcs_docs/html/en/wcs-developer-guide/quick_start_recording_streams.htm var link = window.location.protocol + "//" + window.location.host + '/client/records/' + name; $("#link").attr("href", link); $("#recVideo").attr("src", link).attr("controls", true); $("#downloadDiv").show(); } } |
Stream recordings are saved to directory WCS_HOME/client/records.
When the link is formed,:
- window.location.protocol is the protocol being used (HTTP or HTTPS)
- window.location.host is <address of the WCS server>:<port>
- name is name of the file with the recording
5. Stop of streaming. line 24
The following method is called to stop video streaming
Code Block | ||||
---|---|---|---|---|
| ||||
stream.stop(); |
...