/
globals.coffee
executable file
·406 lines (336 loc) · 15.7 KB
/
globals.coffee
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
@getBuildInformation = ->
copyrightYear = Meteor.config?.copyrightYear or "DATE"
html5ClientBuild = Meteor.config?.html5ClientBuild or "VERSION"
defaultWelcomeMessage = Meteor.config?.defaultWelcomeMessage or "WELCOME MESSAGE"
defaultWelcomeMessageFooter = Meteor.config?.defaultWelcomeMessageFooter or "WELCOME MESSAGE"
link = "<a href='http://bigbluebutton.org/' target='_blank'>http://bigbluebutton.org</a>"
{
'copyrightYear': copyrightYear
'html5ClientBuild': html5ClientBuild
'defaultWelcomeMessage': defaultWelcomeMessage
'defaultWelcomeMessageFooter': defaultWelcomeMessageFooter
'link': link
}
# Convert a color `value` as integer to a hex color (e.g. 255 to #0000ff)
@colourToHex = (value) ->
hex = parseInt(value).toString(16)
hex = "0" + hex while hex.length < 6
"##{hex}"
# color can be a number (a hex converted to int) or a string (e.g. "#ffff00")
@formatColor = (color) ->
color ?= "0" # default value
if !color.toString().match(/\#.*/)
color = colourToHex(color)
color
@getCurrentSlideDoc = -> # returns only one document
BBB.getCurrentSlide()
@getInSession = (k) -> SessionAmplify.get k
@getTime = -> # returns epoch in ms
(new Date).valueOf()
# helper to determine whether user has joined any type of audio
Handlebars.registerHelper "amIInAudio", ->
BBB.amIInAudio()
# helper to determine whether the user is in the listen only audio stream
Handlebars.registerHelper "amIListenOnlyAudio", ->
BBB.amIListenOnlyAudio()
Handlebars.registerHelper "colourToHex", (value) =>
@window.colourToHex(value)
Handlebars.registerHelper 'equals', (a, b) -> # equals operator was dropped in Meteor's migration from Handlebars to Spacebars
a is b
Handlebars.registerHelper "getCurrentMeeting", ->
Meteor.Meetings.findOne()
Handlebars.registerHelper "getCurrentSlide", ->
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
presentationId = currentPresentation?.presentation?.id
Meteor.Slides.find({"presentationId": presentationId, "slide.current": true})
# Allow access through all templates
Handlebars.registerHelper "getInSession", (k) -> SessionAmplify.get k
Handlebars.registerHelper "getMeetingName", ->
BBB.getMeetingName()
Handlebars.registerHelper "getShapesForSlide", ->
currentSlide = getCurrentSlideDoc()
# try to reuse the lines above
Meteor.Shapes.find({whiteboardId: currentSlide?.slide?.id})
# retrieves all users in the meeting
Handlebars.registerHelper "getUsersInMeeting", ->
# retrieve all users with raised hands
# raised hand is an object, so we can't simply search for true
# sort users by who has raised their hand first, place them at the top
raised = Meteor.Users.find({'user.raise_hand': {$not: {$in: [0, false, null]} }}, {sort: {'user.raise_hand': 1} }).fetch()
# find all users with a lowered hand
# when a hand is lowered, it is not always just false, it can be zero, or null
lowered = Meteor.Users.find({'user.raise_hand': $in: [0, false, null]}, {sort: {'user._sort_name': 1} }).fetch()
# add the users with lowered hands, to the list of people with raised hands
raised.concat lowered
Handlebars.registerHelper "getWhiteboardTitle", ->
(BBB.currentPresentationName() or "Loading presentation...")
Handlebars.registerHelper "isCurrentUser", (userId) ->
userId is null or userId is BBB.getCurrentUser()?.userId
Handlebars.registerHelper "isCurrentUserMuted", ->
BBB.amIMuted()
#Retreives a username for a private chat tab from the database if it exists
Handlebars.registerHelper "privateChatName", ->
obj = Meteor.Users.findOne({ userId: getInSession "inChatWith" })
if obj?
obj?.user?.name
Handlebars.registerHelper "isCurrentUserRaisingHand", ->
BBB.isCurrentUserRaisingHand()
Handlebars.registerHelper "isCurrentUserSharingVideo", ->
BBB.amISharingVideo()
Handlebars.registerHelper "isCurrentUserTalking", ->
BBB.amITalking()
Handlebars.registerHelper "isCurrentUserPresenter", ->
BBB.isUserPresenter(getInSession('userId'))
Handlebars.registerHelper "isDisconnected", ->
return !Meteor.status().connected
Handlebars.registerHelper "isUserInAudio", (userId) ->
BBB.isUserInAudio(userId)
Handlebars.registerHelper "isUserListenOnlyAudio", (userId) ->
BBB.isUserListenOnlyAudio(userId)
Handlebars.registerHelper "isUserMuted", (userId) ->
BBB.isUserMuted(userId)
Handlebars.registerHelper "isUserSharingVideo", (userId) ->
BBB.isUserSharingWebcam(userId)
Handlebars.registerHelper "isUserTalking", (userId) ->
BBB.isUserTalking(userId)
Handlebars.registerHelper 'isMobile', () ->
isMobile()
Handlebars.registerHelper 'isPortraitMobile', () ->
isPortraitMobile()
Handlebars.registerHelper 'isMobileChromeOrFirefox', () ->
isMobile() and ((getBrowserName() is 'Chrome') or (getBrowserName() is 'Firefox'))
Handlebars.registerHelper "meetingIsRecording", ->
BBB.isMeetingRecording()
Handlebars.registerHelper "messageFontSize", ->
style: "font-size: #{getInSession("messageFontSize")}px;"
Handlebars.registerHelper "pointerLocation", ->
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
presentationId = currentPresentation?.presentation?.id
currentSlideDoc = Meteor.Slides.findOne({"presentationId": presentationId, "slide.current": true})
pointer = currentPresentation?.pointer
pointer.x = (- currentSlideDoc.slide.x_offset * 2 + currentSlideDoc.slide.width_ratio * pointer.x) / 100
pointer.y = (- currentSlideDoc.slide.y_offset * 2 + currentSlideDoc.slide.height_ratio * pointer.y) / 100
pointer
Handlebars.registerHelper "safeName", (str) ->
safeString(str)
Handlebars.registerHelper "visibility", (section) ->
if getInSession "display_#{section}"
style: 'display:block;'
else
style: 'display:none;'
Handlebars.registerHelper 'containerPosition', (section) ->
if getInSession 'display_usersList'
return 'moved-to-right'
else if getInSession 'display_menu'
return 'moved-to-left'
else
return ''
# vertically shrinks the whiteboard if the slide navigation controllers are present
Handlebars.registerHelper 'whiteboardSize', (section) ->
if BBB.isUserPresenter(getInSession('userId'))
return 'presenter-whiteboard'
else
return 'viewer-whiteboard'
# transform plain text links into HTML tags compatible with Flash client
@linkify = (str) ->
www = /(^|[^\/])(www\.[\S]+($|\b))/img
http = /\b(https?:\/\/[0-9a-z+|.,:;\/&?_~%#=@!-]*[0-9a-z+|\/&_~%#=@-])/img
str = str.replace http, "<a href='event:$1'><u>$1</u></a>"
str = str.replace www, "$1<a href='event:http://$2'><u>$2</u></a>"
@setInSession = (k, v) -> SessionAmplify.set k, v
@safeString = (str) ->
if typeof str is 'string'
str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
@toggleCam = (event) ->
# Meteor.Users.update {_id: context._id} , {$set:{"user.sharingVideo": !context.sharingVideo}}
# Meteor.call('userToggleCam', context._id, !context.sharingVideo)
@toggleChatbar = ->
if getInSession("display_chatbar") and isOnlyOnePanelOpen()
setInSession "display_usersList", true
setInSession "display_whiteboard", true
setInSession "display_chatbar", true
else
setInSession "display_chatbar", !getInSession "display_chatbar"
setTimeout(redrawWhiteboard, 0)
@toggleMic = (event) ->
BBB.toggleMyMic()
# toggle state of session variable
@toggleUsersList = ->
setInSession "display_usersList", !getInSession "display_usersList"
setTimeout(redrawWhiteboard, 0)
@toggleMenu = ->
setInSession 'display_menu', !getInSession 'display_menu'
@removeFullscreenStyles = ->
$('#whiteboard-paper').removeClass('verticallyCentered')
$('#chat').removeClass('invisible')
$('#users').removeClass('invisible')
$('#navbar').removeClass('invisible')
$('.fullscreenButton').removeClass('exitFullscreenButton')
$('.fullscreenButton').addClass('whiteboardFullscreenButton')
$('.fullscreenButton i').removeClass('ion-arrow-shrink')
$('.fullscreenButton i').addClass('ion-arrow-expand')
@enterWhiteboardFullscreen = ->
element = document.getElementById('whiteboard')
if element.requestFullscreen
element.requestFullscreen()
else if element.mozRequestFullScreen
element.mozRequestFullScreen()
$('.fullscreenButton').addClass('iconFirefox') # browser-specific icon sizing
else if element.webkitRequestFullscreen
element.webkitRequestFullscreen()
$('.fullscreenButton').addClass('iconChrome') # browser-specific icon sizing
else if element.msRequestFullscreen
element.msRequestFullscreen()
$('#chat').addClass('invisible')
$('#users').addClass('invisible')
$('#navbar').addClass('invisible')
$('.fullscreenButton').removeClass('whiteboardFullscreenButton')
$('.fullscreenButton').addClass('exitFullscreenButton')
$('.fullscreenButton i').removeClass('ion-arrow-expand')
$('.fullscreenButton i').addClass('ion-arrow-shrink')
$('#whiteboard-paper').addClass('verticallyCentered')
$('#whiteboard').bind 'webkitfullscreenchange', (e) ->
if document.webkitFullscreenElement is null
$('#whiteboard').unbind('webkitfullscreenchange')
$('.fullscreenButton').removeClass('iconChrome')
removeFullscreenStyles()
redrawWhiteboard()
$(document).bind 'mozfullscreenchange', (e) -> # target is always the document in Firefox
if document.mozFullScreenElement is null
$(document).unbind('mozfullscreenchange')
$('.fullscreenButton').removeClass('iconFirefox')
removeFullscreenStyles()
redrawWhiteboard()
@closePushMenus = ->
setInSession 'display_usersList', false
setInSession 'display_menu', false
# Periodically check the status of the WebRTC call, when a call has been established attempt to hangup,
# retry if a call is in progress, send the leave voice conference message to BBB
@exitVoiceCall = (event) ->
# To be called when the hangup is initiated
hangupCallback = ->
console.log "Exiting Voice Conference"
# Checks periodically until a call is established so we can successfully end the call
# clean state
getInSession("triedHangup", false)
# function to initiate call
(checkToHangupCall = (context) ->
# if an attempt to hang up the call is made when the current session is not yet finished, the request has no effect
# keep track in the session if we haven't tried a hangup
if BBB.getCallStatus() isnt null and !getInSession("triedHangup")
console.log "Attempting to hangup on WebRTC call"
if BBB.amIListenOnlyAudio() # notify BBB-apps we are leaving the call call if we are listen only
Meteor.call('listenOnlyRequestToggle', BBB.getMeetingId(), getInSession("userId"), getInSession("authToken"), false)
BBB.leaveVoiceConference hangupCallback
getInSession("triedHangup", true) # we have hung up, prevent retries
notification_WebRTCAudioExited()
else
console.log "RETRYING hangup on WebRTC call in #{Meteor.config.app.WebRTCHangupRetryInterval} ms"
setTimeout checkToHangupCall, Meteor.config.app.WebRTCHangupRetryInterval # try again periodically
)(@) # automatically run function
return false
# close the daudio UI, then join the conference. If listen only send the request to the server
@joinVoiceCall = (event, {isListenOnly} = {}) ->
if !isWebRTCAvailable()
notification_WebRTCNotSupported()
return
isListenOnly ?= true
# create voice call params
joinCallback = (message) ->
console.log "Beginning WebRTC Conference Call"
notification_WebRTCAudioJoining()
if isListenOnly
Meteor.call('listenOnlyRequestToggle', BBB.getMeetingId(), getInSession("userId"), getInSession("authToken"), true)
BBB.joinVoiceConference joinCallback, isListenOnly # make the call #TODO should we apply role permissions to this action?
return false
# Starts the entire logout procedure.
# meeting: the meeting the user is in
# the user's userId
@userLogout = (meeting, user) ->
Meteor.call("userLogout", meeting, user, getInSession("authToken"))
console.log "logging out"
clearSessionVar(document.location = getInSession 'logoutURL') # navigate to logout
# Clear the local user session
@clearSessionVar = (callback) ->
amplify.store('authToken', null)
amplify.store('bbbServerVersion', null)
amplify.store('chatTabs', null)
amplify.store('dateOfBuild', null)
amplify.store('display_chatPane', null)
amplify.store('display_chatbar', null)
amplify.store('display_navbar', null)
amplify.store('display_usersList', null)
amplify.store('display_whiteboard', null)
amplify.store('inChatWith', null)
amplify.store('logoutURL', null)
amplify.store('meetingId', null)
amplify.store('messageFontSize', null)
amplify.store('tabsRenderedTime', null)
amplify.store('userId', null)
amplify.store('userName', null)
amplify.store('display_menu', null)
if callback?
callback()
# assign the default values for the Session vars
@setDefaultSettings = ->
setInSession "display_navbar", true
setInSession "display_chatbar", true
setInSession "display_whiteboard", true
setInSession "display_chatPane", true
if not getInSession "inChatWith" then setInSession "inChatWith", 'PUBLIC_CHAT'
if isPortraitMobile() or isLandscapeMobile()
setInSession "messageFontSize", Meteor.config.app.mobileFont
else
setInSession "messageFontSize", Meteor.config.app.desktopFont
setInSession 'display_slidingMenu', false
setInSession 'display_hiddenNavbarSection', false
if isLandscape()
setInSession 'display_usersList', true
else
setInSession 'display_usersList', false
setInSession 'display_menu', false
@onLoadComplete = ->
document.title = "BigBlueButton #{BBB.getMeetingName() ? 'HTML5'}"
setDefaultSettings()
Meteor.Users.find().observe({
removed: (oldDocument) ->
if oldDocument.userId is getInSession 'userId'
document.location = getInSession 'logoutURL'
})
# Detects a mobile device
@isMobile = ->
navigator.userAgent.match(/Android/i) or
navigator.userAgent.match(/iPhone|iPad|iPod/i) or
navigator.userAgent.match(/BlackBerry/i) or
navigator.userAgent.match(/Windows Phone/i) or
navigator.userAgent.match(/IEMobile/i) or
navigator.userAgent.match(/BlackBerry/i) or
navigator.userAgent.match(/webOS/i)
@isLandscape = ->
window.matchMedia('(orientation: landscape)').matches
# Checks if the view is portrait and a mobile device is being used
@isPortraitMobile = () ->
isMobile() and
window.matchMedia('(orientation: portrait)').matches and # browser is portrait
window.matchMedia('(max-device-aspect-ratio: 1/1)').matches # device is portrait
# Checks if the view is landscape and mobile device is being used
@isLandscapeMobile = () ->
isMobile() and
window.matchMedia('(orientation: landscape)').matches and # browser is landscape
window.matchMedia('(min-device-aspect-ratio: 1/1)').matches # device is landscape
# Checks if only one panel (userlist/whiteboard/chatbar) is currently open
@isOnlyOnePanelOpen = () ->
#(getInSession "display_usersList" ? 1 : 0) + (getInSession "display_whiteboard" ? 1 : 0) + (getInSession "display_chatbar" ? 1 : 0) is 1
getInSession("display_usersList") + getInSession("display_whiteboard") + getInSession("display_chatbar") is 1
# determines which browser is being used
@getBrowserName = () ->
if navigator.userAgent.match(/Chrome/i)
return 'Chrome'
else if navigator.userAgent.match(/Firefox/i)
return 'Firefox'
else if navigator.userAgent.match(/Safari/i)
return 'Safari'
else if navigator.userAgent.match(/Trident/i)
return 'IE'
else
return null