-
Notifications
You must be signed in to change notification settings - Fork 510
Expand file tree
/
Copy pathemptycontentview.js
More file actions
253 lines (207 loc) · 9.21 KB
/
emptycontentview.js
File metadata and controls
253 lines (207 loc) · 9.21 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/* global Marionette, $ */
/**
*
* @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, Marionette, $) {
'use strict';
OCA.SpreedMe = OCA.SpreedMe || {};
OCA.SpreedMe.Views = OCA.SpreedMe.Views || {};
var roomsChannel = Backbone.Radio.channel('rooms');
var localMediaChannel = Backbone.Radio.channel('localMedia');
/**
* View for the main empty content message.
*
* This view does not render its own elements; an existing element must be
* provided when the view is created. In the main UI of Talk that element
* comes from the templates rendered by the server, which ensures that even
* if the UI takes a while to load the user will not see just an empty
* screen (which would happen if the view itself rendered the elements).
*/
var EmptyContentView = Marionette.View.extend({
template: false,
ui: {
'icon': '#emptycontent-icon',
'message': 'h2',
'messageAdditional': '.emptycontent-additional',
'shareRoomInput': '.share-room-input',
'shareRoomClipboardButton': '.shareRoomClipboard',
},
/**
* @param {string} options.el selector for the existing empty content
* element.
*/
initialize: function(/*options*/) {
// Force render to create the UI bindings to the existing elements.
this.render();
this.listenTo(roomsChannel, 'leaveCurrentRoom', this.setEmptyContentMessageWhenConversationEnded);
this.listenTo(localMediaChannel, 'webRtcNotSupported', function() {
this._disableUpdatesOnActiveRoomChanges();
this.setEmptyContentMessageWhenWebRtcIsNotSupported();
});
this.listenTo(localMediaChannel, 'waitingForPermissions', function() {
this._disableUpdatesOnActiveRoomChanges();
this.setEmptyContentMessageWhenWaitingForMediaPermissions();
});
this.listenTo(localMediaChannel, 'startLocalMedia', function() {
this.setEmptyContentMessageWhenWaitingForOthersToJoinTheCall();
this._enableUpdatesOnActiveRoomChanges();
});
this.listenTo(localMediaChannel, 'startWithoutLocalMedia', function() {
this.setEmptyContentMessageWhenWaitingForOthersToJoinTheCall();
this._enableUpdatesOnActiveRoomChanges();
});
},
setActiveRoom: function(activeRoom) {
this.stopListening(this._activeRoom, 'destroy', this.setInitialEmptyContentMessage);
this._disableUpdatesOnActiveRoomChanges();
this._activeRoom = activeRoom;
this.setEmptyContentMessageWhenWaitingForOthersToJoinTheCall();
// The 'leaveCurrentRoom' is triggered before the 'destroy' event,
// so when the room is destroyed the initial message overwrites the
// conversation ended message.
this.listenTo(this._activeRoom, 'destroy', this.setInitialEmptyContentMessage);
this._enableUpdatesOnActiveRoomChanges();
},
_disableUpdatesOnActiveRoomChanges: function() {
this.stopListening(this._activeRoom, 'change:participants', this.setEmptyContentMessageWhenWaitingForOthersToJoinTheCall);
this.stopListening(this._activeRoom, 'change:numGuests', this.setEmptyContentMessageWhenWaitingForOthersToJoinTheCall);
this.stopListening(this._activeRoom, 'change:participantType', this.setEmptyContentMessageWhenWaitingForOthersToJoinTheCall);
this.stopListening(this._activeRoom, 'change:type', this.setEmptyContentMessageWhenWaitingForOthersToJoinTheCall);
},
_enableUpdatesOnActiveRoomChanges: function() {
this.listenTo(this._activeRoom, 'change:participants', this.setEmptyContentMessageWhenWaitingForOthersToJoinTheCall);
this.listenTo(this._activeRoom, 'change:numGuests', this.setEmptyContentMessageWhenWaitingForOthersToJoinTheCall);
this.listenTo(this._activeRoom, 'change:participantType', this.setEmptyContentMessageWhenWaitingForOthersToJoinTheCall);
this.listenTo(this._activeRoom, 'change:type', this.setEmptyContentMessageWhenWaitingForOthersToJoinTheCall);
},
/**
*
* @param {string|Object} icon
* @param {string} icon.userId
* @param {string} icon.displayName
* @param {string} message
* @param {string} [messageAdditional]
* @param {string} [url]
*/
setEmptyContentMessage: function(icon, message, messageAdditional, url) {
//Remove previous icon and avatar from emptycontent
this.getUI('icon').removeAttr('class').attr('class', '');
this.getUI('icon').html('');
if (url) {
this.getUI('shareRoomInput').removeClass('hidden').val(url);
this.getUI('shareRoomClipboardButton').removeClass('hidden');
} else {
this.getUI('shareRoomInput').addClass('hidden');
this.getUI('shareRoomClipboardButton').addClass('hidden');
}
if (typeof icon === 'string') {
this.getUI('icon').addClass(icon);
} else {
var $avatar = $('<div>');
$avatar.addClass('avatar room-avatar');
if (icon.userId !== icon.displayName) {
$avatar.avatar(icon.userId, 128, undefined, false, undefined, icon.displayName);
} else {
$avatar.avatar(icon.userId, 128);
}
this.getUI('icon').append($avatar);
}
this.getUI('message').html(message);
this.getUI('messageAdditional').text(messageAdditional ? messageAdditional : '');
},
setInitialEmptyContentMessage: function() {
this.setEmptyContentMessage(
'icon-talk',
t('spreed', 'Join a conversation or start a new one'),
t('spreed', 'Say hi to your friends and colleagues!')
);
},
setEmptyContentMessageWhenWaitingForOthersToJoinTheCall: function() {
var icon = '';
var message = '';
var messageAdditional = '';
var url = '';
var isGuest = (OC.getCurrentUser().uid === null);
var participants = this._activeRoom.get('participants');
var numberOfParticipants = Object.keys(participants).length;
if (this._activeRoom.get('type') === OCA.SpreedMe.app.ROOM_TYPE_PUBLIC) {
icon = 'icon-public';
} else {
icon = 'icon-contacts-dark';
}
if (numberOfParticipants === 1 && this._activeRoom.get('numGuests') === 0) {
message = t('spreed', 'No other people in this call');
} else if ((!isGuest && numberOfParticipants === 2 && this._activeRoom.get('numGuests') === 0) ||
(isGuest && numberOfParticipants === 1 && this._activeRoom.get('numGuests') === 1)) {
var participantId = '',
participantName = '';
_.each(participants, function(data, userId) {
if (OC.getCurrentUser().uid !== userId) {
participantId = userId;
participantName = data.name;
}
});
icon = { userId: participantId, displayName: participantName};
message = t('spreed', 'Waiting for {participantName} to join the call …', {participantName: participantName});
} else {
message = t('spreed', 'Waiting for others to join the call …');
}
var canModerate = this._activeRoom.get('participantType') === OCA.SpreedMe.app.OWNER ||
this._activeRoom.get('participantType') === OCA.SpreedMe.app.MODERATOR;
if (this._activeRoom.get('type') === OCA.SpreedMe.app.ROOM_TYPE_GROUP && canModerate) {
messageAdditional = t('spreed', 'You can invite others in the participant tab of the sidebar');
} else if (this._activeRoom.get('type') === OCA.SpreedMe.app.ROOM_TYPE_PUBLIC) {
messageAdditional = t('spreed', 'Share this link to invite others!');
canModerate = canModerate ||
this._activeRoom.get('participantType') === OCA.SpreedMe.app.GUEST_MODERATOR;
if (canModerate) {
messageAdditional = t('spreed', 'You can invite others in the participant tab of the sidebar or share this link to invite others!');
}
url = window.location.protocol + '//' + window.location.host + OC.generateUrl('/call/' + this._activeRoom.get('token'));
}
if (this._activeRoom.get('objectType') === 'share:password' || this._activeRoom.get('objectType') === 'file') {
messageAdditional = '';
url = '';
}
this.setEmptyContentMessage(icon, message, messageAdditional, url);
},
setEmptyContentMessageWhenWebRtcIsNotSupported: function() {
this.setEmptyContentMessage(
'icon-video-off',
t('spreed', 'WebRTC is not supported in your browser :-/'),
t('spreed', 'Please use a different browser like Firefox or Chrome')
);
},
setEmptyContentMessageWhenWaitingForMediaPermissions: function() {
this.setEmptyContentMessage(
'icon-video-off',
t('spreed', 'Waiting for camera and microphone permissions'),
t('spreed', 'Please, give your browser access to use your camera and microphone in order to use this app.')
);
},
setEmptyContentMessageWhenConversationEnded: function() {
this.setEmptyContentMessage(
'icon-video-off',
t('spreed', 'This conversation has ended')
);
},
});
OCA.SpreedMe.Views.EmptyContentView = EmptyContentView;
})(OCA, Marionette, $);