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

Commit 21a74a6

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

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-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: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,86 @@ 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 of IPCamera.
866+
* @param {string} connection.mode -SRT connection mode, "listener" or "caller", "listener" by default.
867+
* @param {number} connection.latency -The SRT latency 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 = 'rtsp://10.239.44.7:554/rtsp_tunnel%3Fh26x=4%26line=1';
876+
var transport = {
877+
url = 'srt://10.239.44.7:1234',
878+
mode: 'listener',
879+
latency: 100
880+
};
881+
var media = {
882+
audio: 'auto',
883+
video: true
884+
};
885+
886+
OWT_REST.API.startStreamingIn(roomId, url, transport, media, function(stream) {
887+
console.log('Streaming-In:', stream);
888+
}, function(status, error) {
889+
// HTTP status and error
890+
console.log(status, error);
891+
});
892+
*/
893+
var startStreamingInSRT = function(room, url, options, media, callback, callbackError) {
894+
console.log("Send streaming in srt request");
895+
var pub_req = {
896+
connection: {
897+
url: url,
898+
mode: options.mode,
899+
latency: options.latency
900+
},
901+
media: media
902+
};
903+
send('POST', 'rooms/' + room + '/streaming-ins-srt/', pub_req, function(streamRtn) {
904+
var st = JSON.parse(streamRtn);
905+
callback(st);
906+
}, callbackError);
907+
};
908+
909+
910+
/**
911+
* @function stopStreamingInSRT
912+
* @desc This function stops the specified external streaming-in in the specified room.
913+
* @memberOf OWT_REST.API
914+
* @param {string} room -Room ID
915+
* @param {string} stream -Stream ID
916+
* @param {function} callback -Callback function on success
917+
* @param {function} callbackError -Callback function on error
918+
* @example
919+
var roomId = '51c10d86909ad1f939000001';
920+
var streamID = '878889273471677';
921+
OWT_REST.API.stopStreamingIn(roomId, streamID, function(result) {
922+
console.log('External streaming-in:', streamID, 'in room:', roomId, 'stopped');
923+
}, function(status, error) {
924+
// HTTP status and error
925+
console.log(status, error);
926+
});
927+
*/
928+
var stopStreamingInSRT = function(room, stream, callback, callbackError) {
929+
if (typeof stream !== 'string' || stream.trim().length === 0) {
930+
return callbackError('Invalid stream ID');
931+
}
932+
send('DELETE', 'rooms/' + room + '/streaming-ins-srt/' + stream, undefined, function(result) {
933+
callback(result);
934+
}, callbackError);
935+
};
936+
937+
858938
/*
859939
* * @callback onStreamingOutList
860940
* * @param {Array.<id: string, protocol: string, url: string, parameters: Object, media: Object>} streamingOutList -The list of streaming-outs.
@@ -1476,6 +1556,8 @@ OWT_REST.API = (function(OWT_REST) {
14761556
//Streaming-ins management.
14771557
startStreamingIn: startStreamingIn,
14781558
stopStreamingIn: stopStreamingIn,
1559+
startStreamingInSRT: startStreamingInSRT,
1560+
stopStreamingInSRT: stopStreamingInSRT,
14791561

14801562
//Streaming-outs management
14811563
getStreamingOuts: getStreamingOuts,

0 commit comments

Comments
 (0)