Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Example of streamer with access to media devices

This streamer can be used to publish the following types of streams on Web Call Server

  • WebRTC
  • RTMFP
  • RTMP

and allows to select media devices and parameters for the published video

  • camera
  • microphone
  • FPS (Frames Per Second)
  • resolution (width, height)

On the screenshot below a stream is being published from the client.


Two videos are played on the page

  • 'Local' - video from the camera
  • 'Preview' - the video as received from the server

Code of the example

The path to the source code of the example on WCS server is:

/usr/local/FlashphonerWebCallServer/client/examples/demo/streaming/media_devices_manager

manager.css - file with styles
media_device_manager.html - page of the streamer
manager.js - script providing functionality for the streamer

This example can be tested using the following address:

https://host:8888/client/examples/demo/streaming/media_devices_manager/media_device_manager.html

Here host is the address of the WCS server.

Work with code of the streamer

To analyze the code, let's take the version of file manager.js with hash cf0daabc6b86e21d5a2f9e4605366c8b7f0d27eb, which is available here and can be downloaded with corresponding build 0.3.18.1894.

1. Initialization of the API. line 10

API is initialized after loading the page. For Flash support, the path to SWF file is passed to the init() method.

 


2. List available media devices. line 16

After API initialization, list of available media devices (cameras and microphones) is requested.

 


If the list of devices is received, drop-down lists on the page are filled.
In case of failure, warning "Failed to get access to media devices" is displayed.

3. Connection to server. line 100

Connection to server is established when Start button is clicked.

 


Session is created with method createSession(). Callback function, which will be called in case of successfully established connection (status SESSION_STATUS.ESTABLISHED), is added.

4. Access to media. line 125

After establishing connection to the server, access to media (audio and video from the selected camera and microphone) is requested.
The following parameters are passed to method Flashphoner.getMediaAccess() used to get the access

  • video constrains
  • localVideo - <div> element, in which video from the selected camera will be displayed
 


In case of failure to get the access, warning "Failed to get access to media " is displayed.
If the access is allowed, new video stream is created with method session.createStream(), and function publish() is called to publish the stream (line 126).
When stream is created, the following parameters are passed

  • streamName - name of the stream
  • localVideo - <div> element, in which video from the camera will be displayed

When stream is created, callback functions for events STREAM_STATUS.PUBLISHING, STREAM_STATUS.UNPUBLISHED, STREAM_STATUS.FAILED can be added.

STREAM_STATUS.PUBLISHING - when this status is received,

  •  function resizeLocalVideo() is called to change resolution of video from the camera in accordance to the specified on the client page and adapt to <div> element localVideo, in which the video will be displayed (line 134)
  • preview video stream is created with method session.createStream(), and function play() is called to start playback of the stream in <div> element remoteVideo (line 141)

When preview stream is created, callback functions for events STREAM_STATUS.PLAYING, STREAM_STATUS.STOPPED, STREAM_STATUS.FAILED are added.

STREAM_STATUS.PLAYING - when this status is received, function resizeVideo() is called, which is used in the examples to adapt resolution to the element, in which the video will be displayed.

STREAM_STATUS.UNPUBLISHED and STREAM_STATUS.FAILED - when one of these statuses is received, function onStopped() of the example is called to make appropriate changes in controls of the interface.

5. Stop of playback. line 67

The following method is called to stop playback of preview video stream

 


After calling the method, status STREAM_STATUS.STOPPED should arrive to confirm stop of playback from the server side.

6. Stop of streaming after stop of preview playback. line 151

The following method is called to stop video streaming

 


After calling the method, status STREAM_STATUS.UNPUBLISHED should arrive to confirm stop of streaming from the server side.

  • No labels