Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
Add SRT restful API
Browse files Browse the repository at this point in the history
  • Loading branch information
qwu16 committed Aug 28, 2020
1 parent 8fae8a8 commit 21a74a6
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/samples/conference/samplertcservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,31 @@ app.delete('/rooms/:room/streaming-ins/:id', function(req, res) {
});
});

app.post('/rooms/:room/streaming-ins-srt', function(req, res) {
'use strict';
var room = req.params.room,
url = req.body.url,
transport = req.body.transport,
media = req.body.media;

icsREST.API.startStreamingInSRT(room, url, transport, media, function(result) {
res.send(result);
}, function(err) {
res.send(err);
});
});

app.delete('/rooms/:room/streaming-ins-srt/:id', function(req, res) {
'use strict';
var room = req.params.room,
stream_id = req.params.id;
icsREST.API.stopStreamingInSRT(room, stream_id, function(result) {
res.send(result);
}, function(err) {
res.send(err);
});
});

app.get('/rooms/:room/streaming-outs', function(req, res) {
'use strict';
var room = req.params.room;
Expand Down
82 changes: 82 additions & 0 deletions src/sdk/rest/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,86 @@ OWT_REST.API = (function(OWT_REST) {
}, callbackError);
};

/**
***
* @function startStreamingInSRT
* @desc This function adds an external SRT stream to the specified room.
* @memberOf OWT_REST.API
* @param {string} room -Room ID
* @param {Object} connection -Transport parameters.
* @param {string} connection.url -URL of the streaming source, e.g. the source URL of IPCamera.
* @param {string} connection.mode -SRT connection mode, "listener" or "caller", "listener" by default.
* @param {number} connection.latency -The SRT latency with microseconds.
* @param {Object} media Media requirements.
* @param {string='auto' | boolean} media.video -If video is required, "auto" or true or false, "auto" by default.
* @param {string='auto' | boolean} media.audio -If audio is required, "auto" or true or false, "auto" by default.
* @param {onStartingStreamingInOK} callback -Callback function on success
* @param {function} callbackError -Callback function on error
* @example
var roomId = '51c10d86909ad1f939000001';
var url = 'rtsp://10.239.44.7:554/rtsp_tunnel%3Fh26x=4%26line=1';
var transport = {
url = 'srt://10.239.44.7:1234',
mode: 'listener',
latency: 100
};
var media = {
audio: 'auto',
video: true
};
OWT_REST.API.startStreamingIn(roomId, url, transport, media, function(stream) {
console.log('Streaming-In:', stream);
}, function(status, error) {
// HTTP status and error
console.log(status, error);
});
*/
var startStreamingInSRT = function(room, url, options, media, callback, callbackError) {
console.log("Send streaming in srt request");
var pub_req = {
connection: {
url: url,
mode: options.mode,
latency: options.latency
},
media: media
};
send('POST', 'rooms/' + room + '/streaming-ins-srt/', pub_req, function(streamRtn) {
var st = JSON.parse(streamRtn);
callback(st);
}, callbackError);
};


/**
* @function stopStreamingInSRT
* @desc This function stops the specified external streaming-in in the specified room.
* @memberOf OWT_REST.API
* @param {string} room -Room ID
* @param {string} stream -Stream ID
* @param {function} callback -Callback function on success
* @param {function} callbackError -Callback function on error
* @example
var roomId = '51c10d86909ad1f939000001';
var streamID = '878889273471677';
OWT_REST.API.stopStreamingIn(roomId, streamID, function(result) {
console.log('External streaming-in:', streamID, 'in room:', roomId, 'stopped');
}, function(status, error) {
// HTTP status and error
console.log(status, error);
});
*/
var stopStreamingInSRT = function(room, stream, callback, callbackError) {
if (typeof stream !== 'string' || stream.trim().length === 0) {
return callbackError('Invalid stream ID');
}
send('DELETE', 'rooms/' + room + '/streaming-ins-srt/' + stream, undefined, function(result) {
callback(result);
}, callbackError);
};


/*
* * @callback onStreamingOutList
* * @param {Array.<id: string, protocol: string, url: string, parameters: Object, media: Object>} streamingOutList -The list of streaming-outs.
Expand Down Expand Up @@ -1476,6 +1556,8 @@ OWT_REST.API = (function(OWT_REST) {
//Streaming-ins management.
startStreamingIn: startStreamingIn,
stopStreamingIn: stopStreamingIn,
startStreamingInSRT: startStreamingInSRT,
stopStreamingInSRT: stopStreamingInSRT,

//Streaming-outs management
getStreamingOuts: getStreamingOuts,
Expand Down

0 comments on commit 21a74a6

Please sign in to comment.