2014-10-01 01:12:47 +08:00
# --------------------------------------------------------------------------------------------
# Public methods on server
# All these method must first authenticate the user before it calls the private function counterpart below
2014-10-02 22:15:45 +08:00
# 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.
2014-10-01 01:12:47 +08:00
# --------------------------------------------------------------------------------------------
2014-06-20 00:57:43 +08:00
Meteor . methods
2014-09-26 01:21:46 +08:00
userShareAudio: (meetingId, userId, user_id) ->
2014-10-02 22:15:45 +08:00
updateVoiceUser { ' user_id ' : user_id , ' talking ' : false , ' joined ' : true , ' muted ' : false }
2014-10-01 01:12:47 +08:00
#TODO we need to send a message to bbb-apps about it
2014-09-26 01:21:46 +08:00
userStopAudio: (meetingId, userId, user_id, requesterUserId, requester_id) ->
user = Meteor . Users . findOne ( { ' meetingId ' : meetingId , ' userId ' : userId , ' _id ' : user_id } )
requester = Meteor . Users . findOne ( { ' meetingId ' : meetingId , ' userId ' : requesterUserId , ' _id ' : requester_id } )
if user ? and requester ? and ( ( user . _id is requester . _id ) or requester . presenter )
message =
" payload " :
" userid " : user . userId
" meeting_id " : user . meetingId
" header " :
" timestamp " : new Date ( ) . getTime ( )
" name " : " user_left_voice_request "
" version " : " 0.0.1 "
2014-09-25 03:55:55 +08:00
2014-09-26 02:47:43 +08:00
publish Meteor . config . redis . channels . toBBBApps . voice , message
2014-10-15 05:20:27 +08:00
updateVoiceUser meetingId , { ' user_id ' : user_id , talking : false , joined: false , muted : false }
2014-09-25 03:55:55 +08:00
else
2014-10-25 02:02:01 +08:00
Meteor . log . info " did not have enough information to send a mute_user_request "
2014-09-25 03:55:55 +08:00
2014-09-26 01:37:07 +08:00
# Verifies muter exists, provided proper credentials, and has permission to mute the user
2014-09-26 01:21:46 +08:00
publishMuteRequest: (meetingId, mutee_id, requesterUserId, requester_id, mutedBoolean) ->
2014-10-25 02:02:01 +08:00
Meteor . log . info " publishing a user mute #{ mutedBoolean } request for #{ mutee_id } "
2014-09-26 01:21:46 +08:00
mutee = Meteor . Users . findOne ( { ' meetingId ' : meetingId , _id: mutee_id } )
muter = Meteor . Users . findOne ( { ' meetingId ' : meetingId , ' userId ' : requesterUserId , _id: requester_id } )
if mutee ? and muter ?
message =
" payload " :
" userid " : mutee . userId
" meeting_id " : meetingId
" mute " : mutedBoolean
" requester_id " : muter . userId
" header " :
" timestamp " : new Date ( ) . getTime ( )
" name " : " mute_user_request "
" version " : " 0.0.1 "
2014-09-25 03:55:55 +08:00
2014-09-26 02:47:43 +08:00
publish Meteor . config . redis . channels . toBBBApps . voice , message
2014-10-15 04:25:45 +08:00
updateVoiceUser meetingId , { ' user_id ' : mutee . _id , talking : false , muted : mutedBoolean }
2014-09-26 01:21:46 +08:00
#
2014-09-25 03:55:55 +08:00
else
2014-10-25 02:02:01 +08:00
Meteor . log . info " did not have enough information to send a mute_user_request "
2014-09-25 03:55:55 +08:00
2014-09-26 00:19:02 +08:00
# meetingId: the meetingId which both users are in
2014-11-14 04:04:51 +08:00
# toLowerUserId: the userid of the user to have their hand lowered
2014-09-26 00:19:02 +08:00
# loweredByUserId: userId of person lowering
2014-11-14 04:04:51 +08:00
# loweredBySecret: the secret of the requestor
userLowerHand: (meetingId, toLowerUserId, loweredByUserId, loweredBySecret) ->
2014-11-15 00:00:55 +08:00
action = ->
if toLowerUserId is loweredByUserId
return ' lowerOwnHand '
2014-11-14 04:04:51 +08:00
else
2014-11-15 00:00:55 +08:00
return ' lowerOthersHand '
if isAllowedTo ( action ( ) , meetingId , loweredByUserId , loweredBySecret )
message =
payload:
userid: toLowerUserId
meeting_id: meetingId
raise_hand: false
lowered_by: loweredByUserId
header:
timestamp: new Date ( ) . getTime ( )
name: " user_lowered_hand_message "
version: " 0.0.1 "
# publish to pubsub
publish Meteor . config . redis . channels . toBBBApps . users , message
return
2014-09-26 00:19:02 +08:00
2014-11-14 04:04:51 +08:00
# meetingId: the meetingId which both users are in
# toRaiseUserId: the userid of the user to have their hand lowered
# raisedByUserId: userId of person lowering
# raisedBySecret: the secret of the requestor
userRaiseHand: (meetingId, toRaiseUserId, raisedByUserId, raisedBySecret) ->
2014-11-15 00:00:55 +08:00
action = ->
if toRaiseUserId is raisedByUserId
return ' raiseOwnHand '
2014-11-14 04:04:51 +08:00
else
2014-11-15 00:00:55 +08:00
return ' raiseOthersHand '
2014-11-14 04:04:51 +08:00
2014-11-15 00:00:55 +08:00
if isAllowedTo ( action ( ) , meetingId , raisedByUserId , raisedBySecret )
message =
payload:
userid: toRaiseUserId
meeting_id: meetingId
raise_hand: false
lowered_by: raisedByUserId
header:
timestamp: new Date ( ) . getTime ( )
name: " user_raised_hand_message "
version: " 0.0.1 "
2014-11-14 04:04:51 +08:00
2014-11-15 00:00:55 +08:00
# publish to pubsub
publish Meteor . config . redis . channels . toBBBApps . users , message
return
2014-09-25 03:55:55 +08:00
2014-10-08 04:34:03 +08:00
userLogout: (meetingId, userId) ->
2014-10-25 02:02:01 +08:00
Meteor . log . info " a user is logging out from #{ meetingId } : " + userId
2014-10-08 04:34:03 +08:00
u = Meteor . Users . findOne ( { meetingId: meetingId , userId: userId } )
2014-10-08 04:53:25 +08:00
if u ?
2014-09-25 23:54:14 +08:00
#remove from the collection and dispatch a message to redis
2014-10-08 04:34:03 +08:00
requestUserLeaving meetingId , u . userId , u . _id
2014-09-25 22:45:13 +08:00
# --------------------------------------------------------------------------------------------
# Private methods on server
# --------------------------------------------------------------------------------------------
2014-10-08 04:08:36 +08:00
2014-09-26 01:21:46 +08:00
# Only callable from server
2014-10-08 04:08:36 +08:00
# Received information from BBB-Apps that a user left
# Need to update the collection
2014-10-08 04:34:03 +08:00
# params: meetingid, userid as defined in BBB-Apps
2014-10-08 04:08:36 +08:00
@removeUserFromMeeting = (meetingId, userId) ->
u = Meteor . Users . findOne ( { ' meetingId ' : meetingId , ' userId ' : userId } )
2014-09-26 01:21:46 +08:00
if u ?
2014-10-08 04:08:36 +08:00
Meteor . Users . remove ( u . _id )
2014-10-25 02:02:01 +08:00
Meteor . log . info " ----removed user[ " + userId + " ] from " + meetingId
2014-10-08 04:08:36 +08:00
else
2014-10-25 02:02:01 +08:00
Meteor . log . info " did not find a user [userId] to delete in meetingid: #{ meetingId } "
2014-10-08 04:08:36 +08:00
2014-10-08 04:34:03 +08:00
# Corresponds to a valid action on the HTML clientside
# After authorization, publish a user_leaving_request in redis
# params: meetingid, userid as defined in BBB-Apps, the _id user identifier in mongo
@requestUserLeaving = (meetingId, userId, user_id) ->
u = Meteor . Users . findOne ( { ' meetingId ' : meetingId , ' userId ' : userId , _id: user_id } )
if u ?
message =
" payload " :
" meeting_id " : meetingId
2014-10-08 04:53:25 +08:00
" userid " : u . userId
2014-10-08 04:34:03 +08:00
" header " :
" timestamp " : new Date ( ) . getTime ( )
" name " : " user_leaving_request "
" version " : " 0.0.1 "
2014-10-25 02:02:01 +08:00
Meteor . log . info " sending a user_leaving_request for #{ meetingId } : #{ u . _id } "
2014-10-08 04:34:03 +08:00
2014-10-08 04:53:25 +08:00
if u . userId ? and meetingId ?
2014-10-08 04:34:03 +08:00
publish Meteor . config . redis . channels . toBBBApps . users , message
else
2014-10-25 02:02:01 +08:00
Meteor . log . info " did not have enough information to send a user_leaving_request "
2014-10-08 04:08:36 +08:00
2014-09-26 01:21:46 +08:00
#update a voiceUser - a helper method
2014-10-11 05:35:51 +08:00
@updateVoiceUser = (meetingId, voiceUserObject) ->
2014-10-15 04:25:45 +08:00
u = Meteor . Users . findOne userId: voiceUserObject . web_userid
if u ?
if voiceUserObject . talking ?
Meteor . Users . update ( { meetingId: meetingId , userId: voiceUserObject . web_userid } , { $set: { ' user.voiceUser.talking ' : voiceUserObject . talking } } , { multi: false } ) # talking
if voiceUserObject . joined ?
Meteor . Users . update ( { meetingId: meetingId , userId: voiceUserObject . web_userid } , { $set: { ' user.voiceUser.joined ' : voiceUserObject . joined } } , { multi: false } ) # joined
if voiceUserObject . locked ?
Meteor . Users . update ( { meetingId: meetingId , userId: voiceUserObject . web_userid } , { $set: { ' user.voiceUser.locked ' : voiceUserObject . locked } } , { multi: false } ) # locked
if voiceUserObject . muted ?
Meteor . Users . update ( { meetingId: meetingId , userId: voiceUserObject . web_userid } , { $set: { ' user.voiceUser.muted ' : voiceUserObject . muted } } , { multi: false } ) # muted
if voiceUserObject . listenOnly ?
Meteor . Users . update ( { meetingId: meetingId , userId: voiceUserObject . web_userid } , { $set: { ' user.listenOnly ' : voiceUserObject . listenOnly } } , { multi: false } ) # muted
else
2014-10-25 02:02:01 +08:00
Meteor . log . info " ERROR! did not find such voiceUser! "
2014-09-26 02:29:43 +08:00
@addUserToCollection = (meetingId, user) ->
userId = user . userid
#check if the user is already in the meeting
unless Meteor . Users . findOne ( { userId : userId , meetingId: meetingId } ) ?
2014-10-07 21:27:17 +08:00
entry =
2014-09-26 02:29:43 +08:00
meetingId: meetingId
userId: userId
2014-11-14 01:54:50 +08:00
userSecret: Math . random ( ) . toString ( 36 ) . substring ( 2 , 13 )
2014-09-26 02:29:43 +08:00
user:
userid: user . userid
presenter: user . presenter
name: user . name
phone_user: user . phone_user
raise_hand: user . raise_hand
has_stream: user . has_stream
role: user . role
listenOnly: user . listenOnly
extern_userid: user . extern_userid
permissions: user . permissions
locked: user . locked
time_of_joining: user . timeOfJoining
2014-10-30 05:58:57 +08:00
connection_status: " " # TODO consider other default value
2014-09-26 02:29:43 +08:00
voiceUser:
web_userid: user . voiceUser . web_userid
callernum: user . voiceUser . callernum
userid: user . voiceUser . userid
talking: user . voiceUser . talking
joined: user . voiceUser . joined
callername: user . voiceUser . callername
locked: user . voiceUser . locked
muted: user . voiceUser . muted
webcam_stream: user . webcam_stream
2014-10-24 01:26:08 +08:00
id = Meteor . Users . insert ( entry )
2014-11-14 04:04:51 +08:00
Meteor . log . info " added user userSecret= #{ entry . userSecret } id=[ #{ id } ]: #{ user . name } . Users.size is now #{ Meteor . Users . find ( { meetingId: meetingId } ).count()} "