-
Notifications
You must be signed in to change notification settings - Fork 442
/
Copy pathpublicshareauth.js
212 lines (166 loc) · 6.69 KB
/
publicshareauth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/**
*
* @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com)
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
(function(OCA) {
'use strict';
OCA.Talk = OCA.Talk || {};
OCA.Talk.PublicShareAuth = {
init: function() {
var self = this;
this.setupRequestPasswordButton();
this.setupLayoutForTalkSidebar();
this.setupSignalingEventHandlers();
$('#request-password-button').click(function() {
$('.request-password-wrapper + .error-message').hide();
$('#request-password-button').prop('disabled', 'true');
$('.request-password-wrapper .icon')
.removeClass('icon-confirm-white')
.addClass('icon-loading-small-dark');
self.requestPassword();
});
},
setupRequestPasswordButton: function() {
// "submit-wrapper" is used to mimic the login button and thus get
// automatic colouring of the confirm icon by the Theming app
$('main').append('<div id="submit-wrapper" class="request-password-wrapper">' +
' <input id="request-password-button" class="primary" type="button" value="' + t('spreed', 'Request password') + '" >' +
' <div class="icon icon-confirm-white"></div>' +
'</div>');
},
setupLayoutForTalkSidebar: function() {
$('body').append('<div id="notification-container"><div id="notification"></div></div>');
$('body').append('<div id="content"></div>');
$('#content').append($('.wrapper'));
$('#content').append($('footer'));
$('body').append('<div id="talk-sidebar" class="disappear"></div>');
$('#talk-sidebar').append('<div id="emptycontent"><div id="emptycontent-icon" class="icon-loading"></div><h2></h2><p class="emptycontent-additional"></p></div>');
$('#talk-sidebar').append('<div id="call-container"></div>');
$('#call-container').append('<div id="videos"><div id="localVideoContainer" class="videoView videoContainer"></div></div>');
$('#call-container').append('<div id="screens"></div>');
$('#localVideoContainer').append(
'<video id="localVideo"></video>' +
'<div class="avatar-container hidden">' +
' <div class="avatar"></div>' +
'</div>' +
'<div class="nameIndicator">' +
'</div>');
OCA.SpreedMe.app.mainCallElementSelector = '#talk-sidebar';
OCA.SpreedMe.app._emptyContentView.destroy();
OCA.SpreedMe.app._emptyContentView = new OCA.SpreedMe.Views.EmptyContentView({
el: '#talk-sidebar > #emptycontent'
});
$('#localVideoContainer .nameIndicator').replaceWith(OCA.SpreedMe.app._mediaControlsView.$el);
OCA.SpreedMe.app.registerLocalVideoButtonHandlers();
$('body').addClass('talk-sidebar-enabled');
},
requestPassword: function() {
var self = this;
var shareToken = $('#sharingToken').val();
if (this.hideTalkSidebarTimeout) {
clearTimeout(this.hideTalkSidebarTimeout);
delete this.hideTalkSidebarTimeout;
}
$.ajax({
url: OC.linkToOCS('apps/spreed/api/v1', 2) + 'publicshareauth',
type: 'POST',
data: {
shareToken: shareToken,
},
beforeSend: function(request) {
request.setRequestHeader('Accept', 'application/json');
},
success: function(ocsResponse) {
self.setupRoom(ocsResponse.ocs.data.token);
},
error: function() {
$('.request-password-wrapper .icon')
.removeClass('icon-loading-small-dark')
.addClass('icon-confirm-white');
$('#request-password-button').prop('disabled', '');
var errorMessage = $('.request-password-wrapper + .error-message');
if (errorMessage.length > 0) {
errorMessage.show();
} else {
$('.request-password-wrapper').after('<p class="warning error-message hidden">' + t('spreed', 'Error requesting the password.') + '</p>');
}
}
});
},
setupSignalingEventHandlers: function() {
var self = this;
OCA.SpreedMe.app.signaling.on('joinRoom', function(joinedRoomToken) {
if (OCA.SpreedMe.app.token !== joinedRoomToken) {
return;
}
OCA.SpreedMe.app.signaling.syncRooms().then(function() {
OCA.SpreedMe.app._chatView.$el.appendTo('#talk-sidebar');
OCA.SpreedMe.app._chatView.setTooltipContainer($('body'));
OCA.SpreedMe.app._emptyContentView.setActiveRoom(OCA.SpreedMe.app.activeRoom);
OCA.SpreedMe.app.setPageTitle(OCA.SpreedMe.app.activeRoom.get('displayName'));
OCA.SpreedMe.app._messageCollection.setRoomToken(OCA.SpreedMe.app.activeRoom.get('token'));
OCA.SpreedMe.app._messageCollection.receiveMessages();
// Ensure that the elements are shown, as they could have
// been hidden if the password was already requested and
// that conversation ended in this same page.
$('#videos').show();
$('#screens').show();
self.showTalkSidebar();
OCA.SpreedMe.app.connection.joinCall(joinedRoomToken);
});
});
OCA.SpreedMe.app.signaling.on('leaveRoom', function(leftRoomToken) {
if (OCA.SpreedMe.app.token !== leftRoomToken) {
return;
}
self.leaveRoom();
});
},
setupRoom: function(token) {
OCA.SpreedMe.app.activeRoom = new OCA.SpreedMe.Models.Room({token: token});
OCA.SpreedMe.app.signaling.setRoom(OCA.SpreedMe.app.activeRoom);
OCA.SpreedMe.app.token = token;
OCA.SpreedMe.app.signaling.joinRoom(token);
},
leaveRoom: function() {
$('.request-password-wrapper .icon')
.removeClass('icon-loading-small-dark')
.addClass('icon-confirm-white');
$('#request-password-button').prop('disabled', '');
this.hideTalkSidebarTimeout = setTimeout(this.hideTalkSidebar, 5000);
},
showTalkSidebar: function() {
$('#talk-sidebar').removeClass('disappear');
},
hideTalkSidebar: function() {
$('#talk-sidebar').addClass('disappear');
delete this.hideTalkSidebarTimeout;
},
};
OCA.SpreedMe.app = new OCA.Talk.Application();
OCA.SpreedMe.app.on('start', function() {
OCA.Talk.PublicShareAuth.init();
});
// Unlike in the regular Talk app when Talk is embedded the signaling
// settings are not initially included in the HTML, so they need to be
// explicitly loaded before starting the app.
OCA.Talk.Signaling.loadSettings().then(function() {
OCA.SpreedMe.app.start();
});
})(OCA);