Redirecting a SIP call to a stream (SIP as Stream function)¶
Overview¶
A SIP call made through the WCS server can be captured into a stream on the server when the call is created. Then this call can be played in a browser using any method supported by WCS.
The stream captured from a SIP call can be republished to an RTMP server using the REST query /push/startup
, just like any media stream on the WCS server.
Operation flowchart¶
- The browser starts a call using the
/call/startup
REST query - WCS connects to the SIP server
- The SIP server sends the RTP stream of the call to WCS
- The second browser requests playback of the call stream
- The second browser receives the WebRTC stream
Quick manual on testing¶
-
For this test we use:
- two SIP accounts;
- the softphone to answer the call;
- the REST-client in Chrome browser;
- the Player web application to play the stream.
-
Open the REST client. Send the
/call/startup
query to the WCS server and specify the following as query parameters:- parameters of your SIP account the call will be made from;
- the stream name to republish the call to (the
toStream
parameter), for example,call_stream1
; - the name of your second SIP account the call will be made to
-
Receive and answer the incoming call on the softphone:
-
Open the Player web application and in the
Stream
field specify the name of the stream the call is redirected to (in our example:call_stream1
):
-
Click
Play
. The stream starts playing:
-
To terminate the call, send
/call/terminate
from the REST client to the WCS server and pass the call id in the parameters:
Call flow¶
Below is the call flow when using the SIP as RTMP example to create the call and the Player example to play it
-
Sending the REST query
/call/startup
:
sendREST()
code
function startCall() { ... var url = field("restUrl") + "/call/startup"; callId = generateCallID(); ... var RESTCall = {}; RESTCall.toStream = field("rtmpStream"); RESTCall.hasAudio = field("hasAudio"); RESTCall.hasVideo = field("hasVideo"); RESTCall.callId = callId; RESTCall.sipLogin = field("sipLogin"); RESTCall.sipAuthenticationName = field("sipAuthenticationName"); RESTCall.sipPassword = field("sipPassword"); RESTCall.sipPort = field("sipPort"); RESTCall.sipDomain = field("sipDomain"); RESTCall.sipOutboundProxy = field("sipOutboundProxy"); RESTCall.appKey = field("appKey"); RESTCall.sipRegisterRequired = field("sipRegisterRequired"); for (var key in RESTCall) { setCookie(key, RESTCall[key]); } RESTCall.callee = field("callee"); var data = JSON.stringify(RESTCall); sendREST(url, data); startCheckCallStatus(); }
-
Establishing a connection to the SIP server
-
Receiving a confirmation from the SIP server
-
The RTP stream of the call is sent to the WCS server
-
The browser establishes connection to the server:
Flashphoner.createSession()
code
Flashphoner.createSession({urlServer: url}).on(SESSION_STATUS.ESTABLISHED, function(session){ setStatus(session.status()); //session connected, start playback playStream(session); }).on(SESSION_STATUS.DISCONNECTED, function(){ setStatus(SESSION_STATUS.DISCONNECTED); onStopped(); }).on(SESSION_STATUS.FAILED, function(){ setStatus(SESSION_STATUS.FAILED); onStopped(); });
-
Receiving from the server an event confirming successful connection:
CONNECTION_STATUS.ESTABLISHED
code
-
Request to play the stream:
Stream.play()
code
stream = session.createStream(options).on(STREAM_STATUS.PENDING, function(stream) { var video = document.getElementById(stream.id()); if (!video.hasListeners) { video.hasListeners = true; video.addEventListener('playing', function () { $("#preloader").hide(); }); video.addEventListener('resize', function (event) { var streamResolution = stream.videoResolution(); if (Object.keys(streamResolution).length === 0) { resizeVideo(event.target); } else { // Change aspect ratio to prevent video stretching var ratio = streamResolution.width / streamResolution.height; var newHeight = Math.floor(options.playWidth / ratio); resizeVideo(event.target, options.playWidth, newHeight); } }); } ... }); stream.play();
-
Receiving an event from the server confirming successful playing of the stream:
STREAM_STATUS.PLAYING
code
-
Sending audio and video stream via WebRTC
-
Stopping playing the stream:
Stream.stop()
code
-
Receiving an event from the server confirming unpublishing of the stream:
STREAM_STATUS.STOPPED
code
stream = session.createStream(options).on(STREAM_STATUS.PENDING, function(stream) { ... }).on(STREAM_STATUS.PLAYING, function(stream) { ... }).on(STREAM_STATUS.STOPPED, function() { setStatus(STREAM_STATUS.STOPPED); onStopped(); }).on(STREAM_STATUS.FAILED, function(stream) { ... }).on(STREAM_STATUS.NOT_ENOUGH_BANDWIDTH, function(stream){ ... }); stream.play();
-
Sending the
/call/terminate
REST query:
sendREST()
code
-
Sending the command to the SIP server
-
Receiving confirmation from the SIP server
SIP as stream recording¶
All streams captured from SIP calls can be recorded on server. To do this, set the following parameters in flashphoner.properties file:
The following codecs are supported:
- Video: H264
- Audio: opus, PCMA (alaw), PCMU (ulaw)
Stream recording is described here in details.
Known issues¶
1. Stream captured from SIP call can not be played, if RTP session is not initialized for this stream¶
Symptoms
SIP stream is published on server, but can not be played
2. Freezes may occur, audio may be out of sync with video when republishing a SIP call stream as RTMP¶
Symptoms
Freezes and audio/video out of sync are observed while playing an RTMP stream republished by /push/startup
REST query from a SIP call
Solution
a) in WCS builds before 5.2.1541 add the delay to audio/video generator start
b) update WCS to build 5.2.1541 where the issue was fixed
3. RTP traffic buffering should be enabled in some cases when republishing SIP as Stream or SIP as RTMP¶
Symptoms
Audio and video may be out of sync when playing a SIP call stream