Skip to content

Commit

Permalink
Enabling REST API for streaming-in/streaming-out/recording
Browse files Browse the repository at this point in the history
Change-Id: Iab2421a489de936dee077c24b3d936c2b61e22b0
Reviewed-on: https://git-amr-3.devtools.intel.com/gerrit/154960
Reviewed-by: Zhu, Jianjun <jianjun.zhu@intel.com>
Reviewed-by: Duan, Xiande <xiande.duan@intel.com>
Tested-by: Duan, Xiande <xiande.duan@intel.com>
  • Loading branch information
Xiande Duan committed Dec 29, 2017
1 parent 62d9bfe commit 209a3ed
Show file tree
Hide file tree
Showing 11 changed files with 2,462 additions and 506 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dist/
release*.zip
node_modules/
src/samples/conference/nuve.js
src/samples/conference/icsREST.js
36 changes: 32 additions & 4 deletions scripts/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ module.exports = function(grunt) {
'../src/sdk/nuve/N.API.js'
];

var icsRESTFiles = [
'../src/sdk/icsREST/xmlhttprequest.js',
'../src/sdk/icsREST/hmac-sha256.js',
'../src/sdk/icsREST/Base64.js',
'../src/sdk/icsREST/API.js'
];

// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
Expand Down Expand Up @@ -122,6 +129,24 @@ window.L = L;\n\
},
nonull: true
},
icsREST: {
src: icsRESTFiles,
dest: '../dist/sdk/icsREST.js',
options:{
footer:'module.exports = ICS_REST;',
process: true
},
nonull: true
},
icsREST_debug: {
src: icsRESTFiles,
dest: '../dist/sdk-debug/icsREST.debug.js',
options:{
footer:'module.exports = ICS_REST;',
process: true
},
nonull: true
},
merge: {
src: '../dist/sdk/<%= pkg.name %>.js',
dest: '../dist/sdk/<%= pkg.name %>.js',
Expand Down Expand Up @@ -155,7 +180,8 @@ window.L = L;\n\
dist: {
files: {
'../dist/sdk/<%= pkg.name %>.js': ['../dist/sdk/<%= pkg.name %>.js'],
'../dist/sdk/nuve.js': ['../dist/sdk/nuve.js']
'../dist/sdk/nuve.js': ['../dist/sdk/nuve.js'],
'../dist/sdk/icsREST.js': ['../dist/sdk/icsREST.js']
},
options: {
banner: '<%= meta.banner %>'
Expand Down Expand Up @@ -183,7 +209,9 @@ window.L = L;\n\
{expand: true,cwd:'../dist/sdk/',src:['woogeen.sdk.ui.js'],dest:'../dist/samples/conference/public/',flatten:false},
{expand: true,cwd:'../dist/sdk/',src:['woogeen.sdk.ui.js'],dest:'../dist/samples/sipgw/public/',flatten:false},
{expand: true,cwd:'../dist/sdk/',src:['nuve.js'],dest:'../dist/samples/conference/',flatten:false},
{expand: true,cwd:'../dist/sdk/',src:['nuve.js'],dest:'../src/samples/conference/',flatten:false}
{expand: true,cwd:'../dist/sdk/',src:['nuve.js'],dest:'../src/samples/conference/',flatten:false},
{expand: true,cwd:'../dist/sdk/',src:['icsREST.js'],dest:'../dist/samples/conference/',flatten:false},
{expand: true,cwd:'../dist/sdk/',src:['icsREST.js'],dest:'../src/samples/conference/',flatten:false}
]
}
},
Expand Down Expand Up @@ -257,11 +285,11 @@ window.L = L;\n\
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-eslint');

grunt.registerTask('build', ['eslint:src', 'concat:dist', 'concat:ui_dist', 'concat:nuve','jshint:dist', 'concat:merge', 'uglify:dist','copy:dist','string-replace','compress:dist']);
grunt.registerTask('build', ['eslint:src', 'concat:dist', 'concat:ui_dist', 'concat:nuve', 'concat:icsREST', 'jshint:dist', 'concat:merge', 'uglify:dist','copy:dist','string-replace','compress:dist']);

// Default task is an alias for 'build'.
grunt.registerTask('default', ['build']);

grunt.registerTask('debug', ['concat:dist_debug', 'concat:ui_dist_debug', 'concat:nuve_debug']);
grunt.registerTask('debug', ['concat:dist_debug', 'concat:ui_dist_debug', 'concat:nuve_debug', 'concat:icsREST_debug']);

};
10 changes: 1 addition & 9 deletions src/samples/conference/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<script src="sdk/ui/VideoPlayer.js" type="text/javascript"></script>
<script src="sdk/ui/ui.js" type="text/javascript"></script>
<script src="script2.js" type="text/javascript"></script>
<script src="script3.js" type="text/javascript"></script>
<script language="JavaScript">
function getParameterByName(name) {
name = name.replace(/[\[]/, '\\\[').replace(/[\]]/, '\\\]');
Expand All @@ -47,14 +46,7 @@
/\+/g, ' '));
}

var sampleMode = getParameterByName('mode') || 'socketio';
if (sampleMode === 'rest') {
console.log('Run REST sample!!');
runRestSample();
} else {
console.log('Run SocketIO sample!!');
runSocketIOSample();
}
runSocketIOSample();
</script>
</body>

Expand Down
277 changes: 259 additions & 18 deletions src/samples/conference/public/script2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,262 @@

var send = function (method, entity, body, onRes) {
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState === 4) {
onRes(req.responseText);
}
};
req.open(method, entity, true);
req.setRequestHeader('Content-Type', 'application/json');
if (body !== undefined) {
req.send(JSON.stringify(body));
} else {
req.send();
}
};

var onResponse = function(result) {
if (result) {
try {
L.Logger.info('Result:', JSON.parse(result));
} catch (e) {
L.Logger.info('Result:', result);
}
} else {
L.Logger.info('Null');
}
};

var listRooms = function() {
send('GET', '/rooms/', undefined, onResponse);
};

var getRoom = function(room) {
send('GET', '/rooms/' + room + '/', undefined, onResponse);
};

var createRoom = function() {
send('POST', '/rooms/', {name: 'testNewRoom', options: undefined}, onResponse);
};

var deleteRoom = function(room) {
send('DELETE', '/rooms/' + room + '/', undefined, onResponse);
};

var updateRoom = function(room, config) {
send('PUT', '/rooms/' + room + '/', config, onResponse);
};

var listParticipants = function(room) {
send('GET', '/rooms/' + room + '/participants/', undefined, onResponse);
};

var getParticipant = function(room, participant) {
send('GET', '/rooms/' + room + '/participants/' + participant + '/', undefined, onResponse);
};

var forbidSub = function(room, participant) {
var jsonPatch = [{
op: 'replace',
path: '/permission/subscribe',
value: false
}];
send('PATCH', '/rooms/' + room + '/participants/' + participant + '/', jsonPatch, onResponse);
};

var forbidPub = function(room, participant) {
var jsonPatch = [{
op: 'replace',
path: '/permission/publish',
value: false
}];
send('PATCH', '/rooms/' + room + '/participants/' + participant + '/', jsonPatch, onResponse);
};

var dropParticipant = function(room, participant) {
send('DELETE', '/rooms/' + room + '/participants/' + participant + '/', undefined, onResponse);
};

var listStreams = function(room) {
send('GET', '/rooms/' + room + '/streams/', undefined, onResponse);
};

var getStream = function(room, stream) {
send('GET', '/rooms/' + room + '/streams/' + stream, undefined, onResponse);
};

var mixStream = function(room, stream, view) {
var jsonPatch = [{
op: 'add',
path: '/info/inViews',
value: view
}];
send('PATCH', '/rooms/' + room + '/streams/' + stream, jsonPatch, onResponse);
};

var unmixStream = function(room, stream, view) {
var jsonPatch = [{
op: 'remove',
path: '/info/inViews',
value: view
}];
send('PATCH', '/rooms/' + room + '/streams/' + stream, jsonPatch, onResponse);
};

var setRegion = function(room, stream, region, subStream) {
var jsonPatch = [{
op: 'replace',
path: '/info/layout/0/stream',
value: subStream
}];
send('PATCH', '/rooms/' + room + '/streams/' + stream, jsonPatch, onResponse);
};

var pauseStream = function(room, stream, track) {
var jsonPatch = [];
if (track === 'audio' || track === 'av') {
jsonPatch.push({
op: 'replace',
path: '/media/audio/status',
value: 'inactive'
});
}

if (track === 'video' || track === 'av') {
jsonPatch.push({
op: 'replace',
path: '/media/video/status',
value: 'inactive'
});
}
send('PATCH', '/rooms/' + room + '/streams/' + stream, jsonPatch, onResponse);
};

var playStream = function(room, stream, track) {
var jsonPatch = [];
if (track === 'audio' || track === 'av') {
jsonPatch.push({
op: 'replace',
path: '/media/audio/status',
value: 'active'
});
}

if (track === 'video' || track === 'av') {
jsonPatch.push({
op: 'replace',
path: '/media/video/status',
value: 'active'
});
}
send('PATCH', '/rooms/' + room + '/streams/' + stream, jsonPatch, onResponse);
};

var dropStream = function(room, stream) {
send('DELETE', '/rooms/' + room + '/streams/' + stream, undefined, onResponse);
};

var startStreamingIn = function(room, url) {
var options = {
url: url,
media: {
audio: 'auto',
video: true
},
transport: {
protocol: 'udp',
bufferSize: 2048
}
};
send('POST', '/rooms/' + room + '/streaming-ins', options, onResponse);
};

var stopStreamingIn = function(room, stream) {
send('DELETE', '/rooms/' + room + '/streaming-ins/' + stream, undefined, onResponse);
};

var listRecordings = function(room) {
send('GET', '/rooms/' + room + '/recordings/', undefined, onResponse);
};

var startRecording = function(room, audioFrom, videoFrom, container) {
var options = {
media: {
audio: {
from: audioFrom
},
video: {
from: videoFrom
}
},
container: (container ? container : 'auto')
};
send('POST', '/rooms/' + room + '/recordings', options, onResponse);
};

var stopRecording = function(room, id) {
send('DELETE', '/rooms/' + room + '/recordings/' + id, undefined, onResponse);
};

var updateRecording = function(room, id, audioFrom, videoFrom) {
var jsonPatch = [{
op: 'replace',
path: '/media/audio/from',
value: audioFrom
}, {
op: 'replace',
path: '/media/video/from',
value: videoFrom
}];
send('PATCH', '/rooms/' + room + '/recordings/' + id, jsonPatch, onResponse);
};

var listStreamingOuts = function(room) {
send('GET', '/rooms/' + room + '/streaming-outs/', undefined, onResponse);
};

var startStreamingOut = function(room, url, audioFrom, videoFrom) {
var options = {
media: {
audio: {
from: audioFrom
},
video: {
from: videoFrom
}
},
url: url
};
send('POST', '/rooms/' + room + '/streaming-outs', options, onResponse);
};

var stopStreamingOut = function(room, id) {
send('DELETE', '/rooms/' + room + '/streaming-outs/' + id, undefined, onResponse);
};

var updateStreamingOut = function(room, id, audioFrom, videoFrom) {
var jsonPatch = [{
op: 'replace',
path: '/media/audio/from',
value: audioFrom
}, {
op: 'replace',
path: '/media/video/from',
value: videoFrom
}];
send('PATCH', '/rooms/' + room + '/streaming-outs/' + id, jsonPatch, onResponse);
};


var createToken = function(room, user, role, callback) {
var body = {
room: room,
user: user,
role: role
};
send('POST', '/tokens/', body, callback);
};

var runSocketIOSample = function() {
'use strict';
var localStream;
Expand All @@ -14,24 +273,6 @@ var runSocketIOSample = function() {

var subscribeMix = getParameterByName('mix') || 'true';

function createToken(room, userName, role, callback) {
var req = new XMLHttpRequest();
var url = '/createToken/';
var body = {
room: room,
username: userName,
role: role
};
req.onreadystatechange = function() {
if (req.readyState === 4) {
callback(req.responseText);
}
};
req.open('POST', url, true);
req.setRequestHeader('Content-Type', 'application/json');
req.send(JSON.stringify(body));
}

var conference = Woogeen.ConferenceClient.create({});

function displayStream(stream, resolution) {
Expand Down
Loading

0 comments on commit 209a3ed

Please sign in to comment.