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

Commit e209138

Browse files
committed
Add SRT restful API
1 parent 8fae8a8 commit e209138

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

src/samples/conference/samplertcservice.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,31 @@ app.delete('/rooms/:room/streaming-ins/:id', function(req, res) {
376376
});
377377
});
378378

379+
app.post('/rooms/:room/streaming-ins-srt', function(req, res) {
380+
'use strict';
381+
var room = req.params.room,
382+
url = req.body.url,
383+
transport = req.body.transport,
384+
media = req.body.media;
385+
386+
icsREST.API.startStreamingInSRT(room, url, transport, media, function(result) {
387+
res.send(result);
388+
}, function(err) {
389+
res.send(err);
390+
});
391+
});
392+
393+
app.delete('/rooms/:room/streaming-ins-srt/:id', function(req, res) {
394+
'use strict';
395+
var room = req.params.room,
396+
stream_id = req.params.id;
397+
icsREST.API.stopStreamingInSRT(room, stream_id, function(result) {
398+
res.send(result);
399+
}, function(err) {
400+
res.send(err);
401+
});
402+
});
403+
379404
app.get('/rooms/:room/streaming-outs', function(req, res) {
380405
'use strict';
381406
var room = req.params.room;

src/sdk/rest/API.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,85 @@ OWT_REST.API = (function(OWT_REST) {
855855
}, callbackError);
856856
};
857857

858+
/**
859+
***
860+
* @function startStreamingInSRT
861+
* @desc This function adds an external SRT stream to the specified room.
862+
* @memberOf OWT_REST.API
863+
* @param {string} room -Room ID
864+
* @param {Object} connection -Transport parameters.
865+
* @param {string} connection.url -URL of the streaming source, e.g. the source URL.
866+
* @param {string} connection.mode -SRT connection mode, "listener" or "caller", "listener" by default.
867+
* @param {number} connection.latency -Timestamp-based Packet Delivery Delay with microseconds.
868+
* @param {Object} media Media requirements.
869+
* @param {string='auto' | boolean} media.video -If video is required, "auto" or true or false, "auto" by default.
870+
* @param {string='auto' | boolean} media.audio -If audio is required, "auto" or true or false, "auto" by default.
871+
* @param {onStartingStreamingInOK} callback -Callback function on success
872+
* @param {function} callbackError -Callback function on error
873+
* @example
874+
var roomId = '51c10d86909ad1f939000001';
875+
var url = 'srt://10.239.44.7:1234';
876+
var transport = {
877+
mode: 'caller',
878+
latency: 100000
879+
};
880+
var media = {
881+
audio: 'auto',
882+
video: true
883+
};
884+
885+
OWT_REST.API.startStreamingInSRT(roomId, url, transport, media, function(response) {
886+
console.log('Start SRT streaming-In response:', response);
887+
}, function(status, error) {
888+
// HTTP status and error
889+
console.log(status, error);
890+
});
891+
*/
892+
var startStreamingInSRT = function(room, url, options, media, callback, callbackError) {
893+
console.log("Send streaming in srt request");
894+
var pub_req = {
895+
connection: {
896+
url: url,
897+
mode: options.mode,
898+
latency: options.latency
899+
},
900+
media: media
901+
};
902+
send('POST', 'rooms/' + room + '/streaming-ins-srt/', pub_req, function(streamRtn) {
903+
var st = JSON.parse(streamRtn);
904+
callback(st);
905+
}, callbackError);
906+
};
907+
908+
909+
/**
910+
* @function stopStreamingInSRT
911+
* @desc This function stops the specified external streaming-in in the specified room.
912+
* @memberOf OWT_REST.API
913+
* @param {string} room -Room ID
914+
* @param {string} stream -Stream ID
915+
* @param {function} callback -Callback function on success
916+
* @param {function} callbackError -Callback function on error
917+
* @example
918+
var roomId = '51c10d86909ad1f939000001';
919+
var streamID = '878889273471677';
920+
OWT_REST.API.stopStreamingInSRT(roomId, streamID, function(result) {
921+
console.log('External streaming-in:', streamID, 'in room:', roomId, 'stopped');
922+
}, function(status, error) {
923+
// HTTP status and error
924+
console.log(status, error);
925+
});
926+
*/
927+
var stopStreamingInSRT = function(room, stream, callback, callbackError) {
928+
if (typeof stream !== 'string' || stream.trim().length === 0) {
929+
return callbackError('Invalid stream ID');
930+
}
931+
send('DELETE', 'rooms/' + room + '/streaming-ins-srt/' + stream, undefined, function(result) {
932+
callback(result);
933+
}, callbackError);
934+
};
935+
936+
858937
/*
859938
* * @callback onStreamingOutList
860939
* * @param {Array.<id: string, protocol: string, url: string, parameters: Object, media: Object>} streamingOutList -The list of streaming-outs.
@@ -1476,6 +1555,8 @@ OWT_REST.API = (function(OWT_REST) {
14761555
//Streaming-ins management.
14771556
startStreamingIn: startStreamingIn,
14781557
stopStreamingIn: stopStreamingIn,
1558+
startStreamingInSRT: startStreamingInSRT,
1559+
stopStreamingInSRT: stopStreamingInSRT,
14791560

14801561
//Streaming-outs management
14811562
getStreamingOuts: getStreamingOuts,

0 commit comments

Comments
 (0)