Merge pull request #635 from perroned/bridge-construction

Moving functionality into BBB bridge
This commit is contained in:
Richard Alam 2015-05-07 11:42:08 -04:00
commit 6a9bf94c2c
9 changed files with 165 additions and 112 deletions

View File

@ -30,37 +30,14 @@
color = colourToHex(color)
color
# thickness can be a number (e.g. "2") or a string (e.g. "2px")
@formatThickness = (thickness) ->
thickness ?= "1" # default value
if !thickness.toString().match(/.*px$/)
"#" + thickness + "px" # leading "#" - to be compatible with Firefox
thickness
@getCurrentSlideDoc = -> # returns only one document
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
presentationId = currentPresentation?.presentation?.id
currentSlide = Meteor.Slides.findOne({"presentationId": presentationId, "slide.current": true})
# retrieve account for selected user
@getCurrentUserFromSession = ->
Meteor.Users.findOne(userId: getInSession("userId"))
BBB.getCurrentSlide()
@getInSession = (k) -> SessionAmplify.get k
@getMeetingName = ->
return Meteor.Meetings.findOne()?.meetingName or null
@getTime = -> # returns epoch in ms
(new Date).valueOf()
@getTimeOfJoining = ->
Meteor.Users.findOne(userId: getInSession "userId")?.user?.time_of_joining
@getPresentationFilename = ->
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
currentPresentation?.presentation?.name
# helper to determine whether user has joined any type of audio
Handlebars.registerHelper "amIInAudio", ->
BBB.amIInAudio()
@ -83,15 +60,11 @@ Handlebars.registerHelper "getCurrentSlide", ->
presentationId = currentPresentation?.presentation?.id
Meteor.Slides.find({"presentationId": presentationId, "slide.current": true})
# retrieve account for selected user
Handlebars.registerHelper "getCurrentUser", =>
@window.getCurrentUserFromSession()
# Allow access through all templates
Handlebars.registerHelper "getInSession", (k) -> SessionAmplify.get k
Handlebars.registerHelper "getMeetingName", ->
return Meteor.Meetings.findOne()?.meetingName or null
BBB.getMeetingName()
Handlebars.registerHelper "getShapesForSlide", ->
currentSlide = getCurrentSlideDoc()
@ -112,7 +85,7 @@ Handlebars.registerHelper "getUsersInMeeting", ->
raised.concat lowered
Handlebars.registerHelper "getWhiteboardTitle", ->
(getPresentationFilename() or "Loading presentaion...")
(BBB.currentPresentationName() or "Loading presentation...")
Handlebars.registerHelper "isCurrentUser", (userId) ->
userId is null or userId is BBB.getCurrentUser()?.userId
@ -121,8 +94,7 @@ Handlebars.registerHelper "isCurrentUserMuted", ->
BBB.amIMuted()
Handlebars.registerHelper "isCurrentUserRaisingHand", ->
user = BBB.getCurrentUser()
user?.user?.raise_hand
BBB.isCurrentUserRaisingHand()
Handlebars.registerHelper "isCurrentUserSharingVideo", ->
BBB.amISharingVideo()
@ -161,7 +133,7 @@ Handlebars.registerHelper 'isMobileChromeOrFirefox', () ->
isMobile() and ((getBrowserName() is 'Chrome') or (getBrowserName() is 'Firefox'))
Handlebars.registerHelper "meetingIsRecording", ->
Meteor.Meetings.findOne()?.recorded # Should only ever have one meeting, so we dont need any filter and can trust result #1
BBB.isMeetingRecording()
Handlebars.registerHelper "messageFontSize", ->
style: "font-size: #{getInSession("messageFontSize")}px;"
@ -248,9 +220,7 @@ Handlebars.registerHelper "visibility", (section) ->
setTimeout(redrawWhiteboard, 0)
@toggleMic = (event) ->
u = Meteor.Users.findOne({userId:getInSession("userId")})
if u?
Meteor.call('muteUser', getInSession("meetingId"), u.userId, getInSession("userId"), getInSession("authToken"), not u.user.voiceUser.muted)
BBB.toggleMyMic()
@toggleNavbar = ->
setInSession "display_navbar", !getInSession "display_navbar"
@ -282,7 +252,7 @@ Handlebars.registerHelper "visibility", (section) ->
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', getInSession("meetingId"), getInSession("userId"), getInSession("authToken"), false)
Meteor.call('listenOnlyRequestToggle', BBB.getMeetingId(), getInSession("userId"), getInSession("authToken"), false)
BBB.leaveVoiceConference hangupCallback
getInSession("triedHangup", true) # we have hung up, prevent retries
else
@ -301,7 +271,7 @@ Handlebars.registerHelper "visibility", (section) ->
console.log "Beginning WebRTC Conference Call"
if isListenOnly
Meteor.call('listenOnlyRequestToggle', getInSession("meetingId"), getInSession("userId"), getInSession("authToken"), true)
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
@ -394,12 +364,6 @@ Handlebars.registerHelper "visibility", (section) ->
document.location = getInSession 'logoutURL'
})
# applies zooming to the stroke thickness
@zoomStroke = (thickness) ->
currentSlide = @getCurrentSlideDoc()
ratio = (currentSlide?.slide.width_ratio + currentSlide?.slide.height_ratio) / 2
thickness * 100 / ratio
# Detects a mobile device
@isMobile = ->
navigator.userAgent.match(/Android/i) or

View File

@ -23,6 +23,11 @@ https://github.com/bigbluebutton/bigbluebutton/blob/master/bigbluebutton-client/
else
res
BBB.getMeetingId = ->
Meteor.Meetings.findOne()?.meetingId
BBB.getInternalMeetingId = (callback) ->
###
Queryies the user object via it's id
###
@ -59,6 +64,7 @@ https://github.com/bigbluebutton/bigbluebutton/blob/master/bigbluebutton-client/
# BBB.getUser(userId)?.user?.webcam_stream?.length isnt 0
return false
# returns whether the user has joined any type of audio
BBB.amIInAudio = (callback) ->
user = BBB.getCurrentUser()
@ -93,25 +99,51 @@ https://github.com/bigbluebutton/bigbluebutton/blob/master/bigbluebutton-client/
BBB.getUser(userId)?.user?.presenter
# returns true if the current user is marked as locked
BBB.amILocked = () ->
BBB.amILocked = ->
return BBB.getCurrentUser()?.user.locked
# check whether the user is locked AND the current lock settings for the room
# includes locking the microphone of viewers (listenOnly is still alowed)
BBB.isMyMicLocked = () ->
BBB.isMyMicLocked = ->
lockedMicForRoom = Meteor.Meetings.findOne()?.roomLockSettings.disableMic
# note that voiceUser.locked is not used in BigBlueButton at this stage (April 2015)
return lockedMicForRoom and BBB.amILocked()
BBB.getCurrentSlide = ->
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
presentationId = currentPresentation?.presentation?.id
currentSlide = Meteor.Slides.findOne({"presentationId": presentationId, "slide.current": true})
BBB.getMeetingName = ->
Meteor.Meetings.findOne()?.meetingName or null
BBB.getNumberOfUsers = ->
Meteor.Users.find().count()
BBB.currentPresentationName = ->
Meteor.Presentations.findOne({"presentation.current": true})?.presentation?.name
###
Raise user's hand.
Param:
raiseHand - [true/false]
###
BBB.raiseHand = (raiseHand) ->
BBB.lowerHand = (meetingId, toUserId, byUserId, byAuthToken) ->
Meteor.call('userLowerHand', meetingId, toUserId, byUserId, byAuthToken)
BBB.raiseHand = (meetingId, toUserId, byUserId, byAuthToken) ->
Meteor.call('userRaiseHand', meetingId, toUserId, byUserId, byAuthToken)
BBB.isUserRaisingHand = (userId) ->
BBB.getUser(userId)?.user?.raise_hand
BBB.isCurrentUserRaisingHand = ->
BBB.isUserRaisingHand(BBB.getCurrentUser()?.userId)
BBB.isMeetingRecording = ->
MEteor.Meetings.findOne()?.recorded
###
Issue a switch presenter command.
@ -217,9 +249,7 @@ https://github.com/bigbluebutton/bigbluebutton/blob/master/bigbluebutton-client/
Params:
callback - function that gets executed for the response.
###
BBB.getMeetingID = (callback) ->
BBB.getInternalMeetingID = (callback) ->
###
Join the voice conference.
@ -271,11 +301,22 @@ https://github.com/bigbluebutton/bigbluebutton/blob/master/bigbluebutton-client/
Mute the current user.
###
BBB.muteMe = ->
BBB.muteUser(getInSession("userId"), getInSession("userId"), getInSession("authToken"))
###
Unmute the current user.
###
BBB.unmuteMe = ->
BBB.unmuteUser(getInSession("userId"), getInSession("userId"), getInSession("authToken"))
BBB.muteUser = (meetingId, userId, toMuteId, requesterId, requestToken) ->
Meteor.call('muteUser', meetingId, toMuteId, requesterId, getInSession("authToken"))
BBB.unmuteUser = (meetingId, userId, toMuteId, requesterId, requestToken) ->
Meteor.call('unmuteUser', meetingId, toMuteId, requesterId, getInSession("authToken"))
BBB.toggleMyMic = ->
request = if BBB.amIMuted() then "unmuteUser" else "muteUser"
Meteor.call(request, BBB.getMeetingId(), getInSession("userId"), getInSession("userId"), getInSession("authToken"))
###
Mute all the users.
@ -311,6 +352,20 @@ https://github.com/bigbluebutton/bigbluebutton/blob/master/bigbluebutton-client/
message - the message to send
###
BBB.sendPublicChatMessage = (fontColor, localeLang, message) ->
messageForServer = { # construct message for server
"message": message
"chat_type": "PUBLIC_CHAT"
"from_userid": getInSession("userId")
"from_username": BBB.getMyUserName()
"from_tz_offset": "240"
"to_username": "public_chat_username"
"to_userid": "public_chat_userid"
"from_lang": localeLang
"from_time": getTime()
"from_color": fontColor
}
Meteor.call "sendChatMessagetoServer", BBB.getMeetingId(), messageForServer, getInSession("userId"), getInSession("authToken")
###
Request to send a private chat
@ -320,7 +375,21 @@ https://github.com/bigbluebutton/bigbluebutton/blob/master/bigbluebutton-client/
message - the message to send
toUserID - the external user id of the receiver
###
BBB.sendPrivateChatMessage = (fontColor, localeLang, message, toUserID) ->
BBB.sendPrivateChatMessage = (fontColor, localeLang, message, toUserID, toUserName) ->
messageForServer = { # construct message for server
"message": message
"chat_type": "PRIVATE_CHAT"
"from_userid": getInSession("userId")
"from_username": BBB.getMyUserName()
"from_tz_offset": "240"
"to_username": toUserName
"to_userid": toUserID
"from_lang": localeLang
"from_time": getTime()
"from_color": fontColor
}
Meteor.call "sendChatMessagetoServer", BBB.getMeetingId(), messageForServer, getInSession("userId"), getInSession("authToken")
###
Request to display a presentation.
@ -411,4 +480,6 @@ https://github.com/bigbluebutton/bigbluebutton/blob/master/bigbluebutton-client/
BBB.init = (callback) ->
BBB
)()
)()
#

View File

@ -45,7 +45,7 @@ ieIconPath = 'M27.998,2.266c-2.12-1.91-6.925,0.382-9.575,1.93c-0.76-0.12-1.557-0
$('#notification-text').html("You've joined the Listen Only Audio")
else
$('#notification-text').html("You've joined the audio")
$('#notification').dialog('open')
setTimeout () ->
$('#notification').dialog('close') # close the entire notification
@ -146,17 +146,17 @@ Template.header.events
"click .leaveAudioButton": (event) ->
exitVoiceCall event
"click .lowerHand": (event) ->
$(".tooltip").hide()
Meteor.call('userLowerHand', getInSession("meetingId"), getInSession("userId"), getInSession("userId"), getInSession("authToken"))
"click .muteIcon": (event) ->
$(".tooltip").hide()
toggleMic @
"click .lowerHand": (event) ->
$(".tooltip").hide()
BBB.lowerHand(BBB.getMeetingId(), getInSession("userId"), getInSession("userId"), getInSession("authToken"))
"click .raiseHand": (event) ->
$(".tooltip").hide()
Meteor.call('userRaiseHand', getInSession("meetingId"), getInSession("userId"), getInSession("userId"), getInSession("authToken"))
BBB.raiseHand(BBB.getMeetingId(), getInSession("userId"), getInSession("userId"), getInSession("authToken"))
# "click .settingsIcon": (event) ->
# alert "settings"
@ -202,16 +202,15 @@ Template.slidingMenu.events
toggleSlidingMenu()
toggleChatbar()
'click .lowerHand': (event) ->
$('.tooltip').hide()
"click .lowerHand": (event) ->
$(".tooltip").hide()
toggleSlidingMenu()
Meteor.call('userLowerHand', getInSession('meetingId'), getInSession('userId'), getInSession('userId'), getInSession('authToken'))
BBB.lowerHand(BBB.getMeetingId(), getInSession("userId"), getInSession("userId"), getInSession("authToken"))
'click .raiseHand': (event) ->
console.log 'navbar raise own hand from client'
$('.tooltip').hide()
"click .raiseHand": (event) ->
$(".tooltip").hide()
toggleSlidingMenu()
Meteor.call('userRaiseHand', getInSession("meetingId"), getInSession("userId"), getInSession("userId"), getInSession("authToken"))
BBB.raiseHand(BBB.getMeetingId(), getInSession("userId"), getInSession("userId"), getInSession("authToken"))
'click .usersListIcon': (event) ->
$('.tooltip').hide()
@ -234,7 +233,7 @@ Template.slidingMenu.events
Template.main.helpers
setTitle: ->
document.title = "BigBlueButton #{window.getMeetingName() ? 'HTML5'}"
document.title = "BigBlueButton #{BBB.getMeetingName() ? 'HTML5'}"
Template.main.rendered = ->
# the initialization code for the dialog presenting the user with microphone+listen only options
@ -278,7 +277,7 @@ Template.main.rendered = ->
{
text: 'Yes'
click: () ->
userLogout getInSession("meetingId"), getInSession("userId"), true
userLogout BBB.getMeetingId(), getInSession("userId"), true
$(this).dialog("close")
class: 'btn btn-xs btn-primary active'
}

View File

@ -88,26 +88,12 @@ Handlebars.registerHelper "inPrivateChat", ->
unless (message?.length > 0 and (/\S/.test(message))) # check the message has content and it is not whitespace
return # do nothing if invalid message
chattingWith = getInSession('inChatWith')
if chattingWith isnt "PUBLIC_CHAT"
color = "0x000000" #"0x#{getInSession("messageColor")}"
if (chattingWith = getInSession('inChatWith')) isnt "PUBLIC_CHAT"
toUsername = Meteor.Users.findOne(userId: chattingWith)?.user.name
messageForServer = { # construct message for server
"message": message
"chat_type": if chattingWith is "PUBLIC_CHAT" then "PUBLIC_CHAT" else "PRIVATE_CHAT"
"from_userid": getInSession("userId")
"from_username": BBB.getMyUserName()
"from_tz_offset": "240"
"to_username": if chattingWith is "PUBLIC_CHAT" then "public_chat_username" else toUsername
"to_userid": if chattingWith is "PUBLIC_CHAT" then "public_chat_userid" else chattingWith
"from_lang": "en"
"from_time": getTime()
"from_color": "0x000000"
# "from_color": "0x#{getInSession("messageColor")}"
}
Meteor.call "sendChatMessagetoServer", getInSession("meetingId"), messageForServer, getInSession("userId"), getInSession("authToken")
BBB.sendPrivateChatMessage(color, "en", message, chattingWith, toUsername)
else
BBB.sendPublicChatMessage(color, "en", message)
$('#newMessageInput').val '' # Clear message box
@ -263,7 +249,7 @@ Template.optionsBar.events
Template.optionsBar.helpers
thereArePeopletoChatWith: -> # Subtract 1 for the current user. Returns whether there are other people in the chat
# TODO: Add a check for the count to only include users who are allowed to private chat
(Meteor.Users.find({'meetingId': getInSession("meetingId")}).count()-1) >= 1
(BBB.getNumberOfUsers()-1) >= 1
Template.optionsBar.rendered = ->
$('div[rel=tooltip]').tooltip()

View File

@ -7,8 +7,7 @@ Template.displayUserIcons.events
# the meeting id
# the _id of the person whose land is to be lowered
# the userId of the person who is lowering the hand
console.log "lower hand- client click handler"
Meteor.call('userLowerHand', getInSession("meetingId"), @userId, getInSession("userId"), getInSession("authToken"))
BBB.lowerHand(getInSession("meetingId"), @userId, getInSession("userId"), getInSession("authToken"))
Template.displayUserIcons.helpers
userLockedIconApplicable: (userId) ->

View File

@ -1,6 +1,6 @@
Template.usersList.helpers
getInfoNumberOfUsers: ->
numberUsers = Meteor.Users.find().count()
numberUsers = BBB.getNumberOfUsers()
if numberUsers > 8
return "Users: #{numberUsers}"
# do not display the label if there are just a few users

View File

@ -23,3 +23,16 @@ Meteor.methods
$('body').append form
form.submit()
# thickness can be a number (e.g. "2") or a string (e.g. "2px")
@formatThickness = (thickness) ->
thickness ?= "1" # default value
if !thickness.toString().match(/.*px$/)
"#" + thickness + "px" # leading "#" - to be compatible with Firefox
thickness
# applies zooming to the stroke thickness
@zoomStroke = (thickness) ->
currentSlide = @getCurrentSlideDoc()
ratio = (currentSlide?.slide.width_ratio + currentSlide?.slide.height_ratio) / 2
thickness * 100 / ratio

View File

@ -24,7 +24,7 @@ Meteor.methods
header :
timestamp: new Date().getTime()
name: eventName
payload:
payload:
message: chatObject
meeting_id: meetingId
requester_id: chatObject.from_userid
@ -89,4 +89,3 @@ Meteor.methods
result = message
result = result.replace(new RegExp(BREAK_LINE, 'g'), CARRIAGE_RETURN)
result

View File

@ -3,7 +3,7 @@
# All these method must first authenticate the user before it calls the private function counterpart below
# which sends the request to bbbApps. If the method is modifying the media the current user is sharing,
# you should perform the request before sending the request to bbbApps. This allows the user request to be performed
# immediately, since they do not require permission for things such as muting themsevles.
# immediately, since they do not require permission for things such as muting themsevles.
# --------------------------------------------------------------------------------------------
Meteor.methods
# meetingId: the meetingId of the meeting the user is in
@ -50,42 +50,64 @@ Meteor.methods
return
# meetingId: the meetingId of the meeting the user[s] is in
# toMuteUserId: the userId of the user to be [un]muted
# toMuteUserId: the userId of the user to be muted
# requesterUserId: the userId of the requester
# requesterToken: the authToken of the requester
# mutedBoolean: true for muting, false for unmuting
muteUser: (meetingId, toMuteUserId, requesterUserId, requesterToken, mutedBoolean) ->
muteUser: (meetingId, toMuteUserId, requesterUserId, requesterToken) ->
action = ->
if mutedBoolean
if toMuteUserId is requesterUserId
return 'muteSelf'
else
return 'muteOther'
if toMuteUserId is requesterUserId
return 'muteSelf'
else
if toMuteUserId is requesterUserId
return 'unmuteSelf'
else
return 'unmuteOther'
return 'muteOther'
if isAllowedTo(action(), meetingId, requesterUserId, requesterToken)
message =
payload:
userid: toMuteUserId
meeting_id: meetingId
mute: mutedBoolean
mute: true
requester_id: requesterUserId
header:
timestamp: new Date().getTime()
name: "mute_user_request"
version: "0.0.1"
Meteor.log.info "publishing a user mute #{mutedBoolean} request for #{toMuteUserId}"
Meteor.log.info "publishing a user mute request for #{toMuteUserId}"
publish Meteor.config.redis.channels.toBBBApps.voice, message
updateVoiceUser meetingId, {'web_userid': toMuteUserId, talking:false, muted:mutedBoolean}
updateVoiceUser meetingId, {'web_userid': toMuteUserId, talking:false, muted:true}
return
# meetingId: the meetingId which both users are in
# meetingId: the meetingId of the meeting the user[s] is in
# toMuteUserId: the userId of the user to be unmuted
# requesterUserId: the userId of the requester
# requesterToken: the authToken of the requester
unmuteUser: (meetingId, toMuteUserId, requesterUserId, requesterToken) ->
action = ->
if toMuteUserId is requesterUserId
return 'unmuteSelf'
else
return 'unmuteOther'
if isAllowedTo(action(), meetingId, requesterUserId, requesterToken)
message =
payload:
userid: toMuteUserId
meeting_id: meetingId
mute: false
requester_id: requesterUserId
header:
timestamp: new Date().getTime()
name: "mute_user_request"
version: "0.0.1"
Meteor.log.info "publishing a user unmute request for #{toMuteUserId}"
publish Meteor.config.redis.channels.toBBBApps.voice, message
updateVoiceUser meetingId, {'web_userid': toMuteUserId, talking:false, muted:false}
return
# meetingId: the meetingId which both users are in
# toLowerUserId: the userid of the user to have their hand lowered
# loweredByUserId: userId of person lowering
# loweredByToken: the authToken of the requestor
@ -112,7 +134,7 @@ Meteor.methods
publish Meteor.config.redis.channels.toBBBApps.users, message
return
# meetingId: the meetingId which both users are in
# meetingId: the meetingId which both users are in
# toRaiseUserId: the userid of the user to have their hand lowered
# raisedByUserId: userId of person lowering
# raisedByToken: the authToken of the requestor