2016-10-13 18:08:32 +03:00
|
|
|
// TODO(fancycode): Should load through AMD if possible.
|
2016-10-18 17:40:09 +03:00
|
|
|
/* global OC, OCA */
|
2016-10-13 18:08:32 +03:00
|
|
|
|
2016-10-18 17:40:09 +03:00
|
|
|
(function(OCA, OC, $) {
|
|
|
|
'use strict';
|
2016-09-05 00:54:11 +03:00
|
|
|
|
|
|
|
OCA.SpreedMe = OCA.SpreedMe || {};
|
2016-10-18 17:40:09 +03:00
|
|
|
|
2017-07-06 13:09:14 +03:00
|
|
|
var signaling;
|
|
|
|
|
2017-07-06 17:24:07 +03:00
|
|
|
function initCalls(signaling_connection) {
|
2017-07-06 13:09:14 +03:00
|
|
|
signaling = signaling_connection;
|
2016-10-18 17:40:09 +03:00
|
|
|
|
|
|
|
var editRoomname = $('#edit-roomname');
|
2016-10-19 13:00:17 +03:00
|
|
|
editRoomname.keyup(function () {
|
2016-10-18 17:40:09 +03:00
|
|
|
editRoomname.tooltip('hide');
|
|
|
|
editRoomname.removeClass('error');
|
|
|
|
});
|
2017-07-06 17:24:07 +03:00
|
|
|
|
2017-07-13 12:37:24 +03:00
|
|
|
OCA.SpreedMe.Calls.leaveAllCalls();
|
2016-10-19 13:00:17 +03:00
|
|
|
}
|
2016-10-18 17:40:09 +03:00
|
|
|
|
2016-11-14 12:21:58 +03:00
|
|
|
Backbone.Radio.channel('rooms');
|
2016-09-05 00:54:11 +03:00
|
|
|
|
2017-07-06 17:24:07 +03:00
|
|
|
OCA.SpreedMe.Calls = {
|
2016-10-19 13:00:17 +03:00
|
|
|
showCamera: function() {
|
|
|
|
$('.videoView').removeClass('hidden');
|
|
|
|
},
|
2017-07-12 16:57:18 +03:00
|
|
|
_createCallSuccessHandle: function(ocsResponse) {
|
|
|
|
var token = ocsResponse.ocs.data.token;
|
2017-04-11 11:40:02 +03:00
|
|
|
OC.Util.History.pushState({
|
2017-07-06 13:09:14 +03:00
|
|
|
token: token
|
|
|
|
}, OC.generateUrl('/call/' + token));
|
|
|
|
this.join(token);
|
2017-04-11 11:40:02 +03:00
|
|
|
},
|
2016-10-19 13:00:17 +03:00
|
|
|
createOneToOneVideoCall: function(recipientUserId) {
|
2017-07-06 13:09:14 +03:00
|
|
|
console.log("Creating one-to-one video call", recipientUserId);
|
2017-07-12 16:57:18 +03:00
|
|
|
$.ajax({
|
|
|
|
url: OC.linkToOCS('apps/spreed/api/v1', 2) + 'room',
|
|
|
|
type: 'POST',
|
|
|
|
data: {
|
|
|
|
invite: recipientUserId,
|
|
|
|
roomType: 1
|
|
|
|
},
|
|
|
|
beforeSend: function (request) {
|
|
|
|
request.setRequestHeader('Accept', 'application/json');
|
|
|
|
},
|
|
|
|
success: _.bind(this._createCallSuccessHandle, this)
|
|
|
|
});
|
2016-10-19 13:00:17 +03:00
|
|
|
},
|
2016-11-11 16:25:30 +03:00
|
|
|
createGroupVideoCall: function(groupId) {
|
2017-07-06 13:09:14 +03:00
|
|
|
console.log("Creating group video call", groupId);
|
2017-07-12 16:57:18 +03:00
|
|
|
$.ajax({
|
|
|
|
url: OC.linkToOCS('apps/spreed/api/v1', 2) + 'room',
|
|
|
|
type: 'POST',
|
|
|
|
data: {
|
|
|
|
invite: groupId,
|
|
|
|
roomType: 2
|
|
|
|
},
|
|
|
|
beforeSend: function (request) {
|
|
|
|
request.setRequestHeader('Accept', 'application/json');
|
|
|
|
},
|
|
|
|
success: _.bind(this._createCallSuccessHandle, this)
|
|
|
|
});
|
2016-11-11 16:25:30 +03:00
|
|
|
},
|
2016-11-23 17:23:26 +03:00
|
|
|
createPublicVideoCall: function() {
|
|
|
|
console.log("Creating a new public room.");
|
2017-07-12 16:57:18 +03:00
|
|
|
$.ajax({
|
|
|
|
url: OC.linkToOCS('apps/spreed/api/v1', 2) + 'room',
|
|
|
|
type: 'POST',
|
|
|
|
data: {
|
|
|
|
roomType: 3
|
|
|
|
},
|
|
|
|
beforeSend: function (request) {
|
|
|
|
request.setRequestHeader('Accept', 'application/json');
|
|
|
|
},
|
|
|
|
success: _.bind(this._createCallSuccessHandle, this)
|
|
|
|
});
|
2016-11-23 17:23:26 +03:00
|
|
|
},
|
2017-03-14 17:46:10 +03:00
|
|
|
join: function(token) {
|
2017-07-06 17:24:07 +03:00
|
|
|
if (signaling.currentCallToken === token) {
|
2016-11-17 20:19:28 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-19 13:00:17 +03:00
|
|
|
$('#emptycontent').hide();
|
|
|
|
$('.videoView').addClass('hidden');
|
|
|
|
$('#app-content').addClass('icon-loading');
|
2016-09-21 17:39:14 +03:00
|
|
|
|
2016-11-11 16:47:54 +03:00
|
|
|
OCA.SpreedMe.webrtc.leaveRoom();
|
2017-03-14 17:46:10 +03:00
|
|
|
OCA.SpreedMe.webrtc.joinRoom(token);
|
2016-10-19 13:00:17 +03:00
|
|
|
},
|
2017-07-06 17:24:07 +03:00
|
|
|
leaveCurrentCall: function(deleter) {
|
2016-12-14 19:33:19 +03:00
|
|
|
OCA.SpreedMe.webrtc.leaveRoom();
|
2017-05-18 16:34:24 +03:00
|
|
|
OC.Util.History.pushState({}, OC.generateUrl('/apps/spreed'));
|
|
|
|
$('#app-content').removeClass('incall');
|
2017-07-06 17:24:07 +03:00
|
|
|
this.showRoomDeletedMessage(deleter);
|
2016-11-17 08:17:24 +03:00
|
|
|
},
|
2017-07-13 12:37:24 +03:00
|
|
|
leaveAllCalls: function() {
|
2017-07-12 16:57:18 +03:00
|
|
|
if (signaling) {
|
2017-07-13 17:57:52 +03:00
|
|
|
// We currently only support a single active call.
|
|
|
|
signaling.leaveCurrentCall();
|
2017-07-12 16:57:18 +03:00
|
|
|
}
|
2016-11-17 08:17:24 +03:00
|
|
|
},
|
2016-12-15 13:34:05 +03:00
|
|
|
showRoomDeletedMessage: function(deleter) {
|
2016-12-15 18:58:44 +03:00
|
|
|
if (deleter) {
|
2017-03-07 20:15:27 +03:00
|
|
|
OCA.SpreedMe.app.setEmptyContentMessage(
|
|
|
|
'icon-video',
|
|
|
|
t('spreed', 'Looking great today! :)'),
|
|
|
|
t('spreed', 'Time to call your friends')
|
|
|
|
);
|
2016-12-15 18:58:44 +03:00
|
|
|
} else {
|
2017-03-07 20:15:27 +03:00
|
|
|
OCA.SpreedMe.app.setEmptyContentMessage(
|
|
|
|
'icon-video-off',
|
|
|
|
t('spreed', 'This call has ended')
|
|
|
|
);
|
2016-12-15 18:58:44 +03:00
|
|
|
}
|
2016-12-15 13:34:05 +03:00
|
|
|
}
|
2016-10-19 13:00:17 +03:00
|
|
|
};
|
2016-10-11 15:44:46 +03:00
|
|
|
|
2017-07-06 17:24:07 +03:00
|
|
|
OCA.SpreedMe.initCalls = initCalls;
|
2016-10-18 17:40:09 +03:00
|
|
|
|
|
|
|
})(OCA, OC, $);
|