2014-07-09 21:15:50 +08:00
Handlebars . registerHelper ' equals ' , (a, b) -> # equals operator was dropped in Meteor's migration from Handlebars to Spacebars
2014-07-04 01:54:41 +08:00
a is b
2014-06-14 02:19:50 +08:00
# Allow access through all templates
2014-07-22 21:31:32 +08:00
Handlebars . registerHelper " setInSession " , (k, v) -> SessionAmplify . set k , v
Handlebars . registerHelper " getInSession " , (k) -> SessionAmplify . get k
2014-06-14 02:19:50 +08:00
# Allow access throughout all coffeescript/js files
2014-07-22 21:31:32 +08:00
@setInSession = (k, v) -> SessionAmplify . set k , v
2014-07-18 03:45:26 +08:00
@getInSession = (k) -> SessionAmplify . get k
2014-06-14 02:19:50 +08:00
2014-06-26 02:51:16 +08:00
# retrieve account for selected user
2014-06-14 02:19:50 +08:00
@getCurrentUserFromSession = ->
2014-07-18 04:13:06 +08:00
Meteor . Users . findOne ( " userId " : getInSession ( " userId " ) )
2014-06-14 02:19:50 +08:00
# retrieve account for selected user
Handlebars . registerHelper " getCurrentUser " , =>
2014-07-18 04:13:06 +08:00
@ window . getCurrentUserFromSession ( )
2014-06-14 02:19:50 +08:00
# toggle state of field in the database
2014-07-14 22:46:02 +08:00
@toggleCam = (event) ->
2014-06-27 01:13:19 +08:00
# Meteor.Users.update {_id: context._id} , {$set:{"user.sharingVideo": !context.sharingVideo}}
# Meteor.call('userToggleCam', context._id, !context.sharingVideo)
2014-06-14 02:19:50 +08:00
2014-07-29 03:24:07 +08:00
@toggleVoiceCall = (event) ->
2014-07-14 22:46:02 +08:00
if getInSession " isSharingAudio "
callback = ->
setInSession " isSharingAudio " , false # update to no longer sharing
console . log " left voice conference "
2014-07-25 04:04:04 +08:00
# sometimes we can hangup before the message that the user stopped talking is received so lets set it manually, otherwise they might leave the audio call but still be registered as talking
2014-07-29 01:43:26 +08:00
Meteor . call ( " userStopAudio " , getInSession ( " meetingId " ) , getInSession ( " userId " ) )
2014-07-14 22:46:02 +08:00
webrtc_hangup callback # sign out of call
else
# create voice call params
2014-07-18 04:13:06 +08:00
username = " #{ getInSession ( " userId " ) } -bbbID- #{ getUsersName ( ) } "
2014-07-14 22:46:02 +08:00
voiceBridge = " 70827 "
server = null
callback = (message) ->
console . log JSON . stringify message
setInSession " isSharingAudio " , true
2014-07-29 01:43:26 +08:00
Meteor . call ( " userShareAudio " , getInSession ( " meetingId " ) , getInSession ( " userId " ) )
2014-07-14 22:46:02 +08:00
webrtc_call ( username , voiceBridge , server , callback ) # make the call
2014-06-14 02:19:50 +08:00
2014-07-29 03:24:07 +08:00
@toggleMic = (event) ->
if getInSession " isSharingAudio " # only allow muting/unmuting if they are in the call
console . log " toggling mute "
# u = Meteor.Users.findOne({userId:getInSession("userId")})
# if u?
# Meteor.call('muteRequest', u.userId, u.meetingId, u.userId, not u.user.voiceUser.muted)
2014-06-14 02:19:50 +08:00
# toggle state of session variable
@toggleUsersList = ->
2014-06-19 21:26:46 +08:00
setInSession " display_usersList " , ! getInSession " display_usersList "
2014-06-14 02:19:50 +08:00
@toggleNavbar = ->
2014-06-19 21:26:46 +08:00
setInSession " display_navbar " , ! getInSession " display_navbar "
@toggleChatbar = ->
2014-06-19 22:45:58 +08:00
setInSession " display_chatbar " , ! getInSession " display_chatbar "
Meteor . methods
sendMeetingInfoToClient: (meetingId, userId) ->
2014-07-18 04:13:06 +08:00
setInSession ( " userId " , userId )
setInSession ( " meetingId " , meetingId )
setInSession ( " currentChatId " , meetingId )
setInSession ( " meetingName " , null )
setInSession ( " bbbServerVersion " , " 0.90 " )
setInSession ( " userName " , null )
2014-07-18 23:18:27 +08:00
setInSession ( " validUser " , true ) # got info from server, user is a valid user
2014-07-18 03:45:26 +08:00
2014-07-09 21:15:50 +08:00
@getUsersName = ->
2014-07-18 04:13:06 +08:00
name = getInSession ( " userName " ) # check if we actually have one in the session
2014-07-09 21:15:50 +08:00
if name ? then name # great return it, no database query
else # we need it from the database
2014-07-18 04:13:06 +08:00
user = Meteor . Users . findOne ( { ' userId ' : getInSession ( " userId " ) } )
2014-07-09 21:15:50 +08:00
if user ? . user ? . name
2014-07-18 04:13:06 +08:00
setInSession " userName " , user . user . name # store in session for fast access next time
2014-07-09 21:15:50 +08:00
user . user . name
else null
2014-06-24 00:58:30 +08:00
2014-07-10 21:11:38 +08:00
@getMeetingName = ->
2014-07-18 04:13:06 +08:00
meetName = getInSession ( " meetingName " ) # check if we actually have one in the session
2014-07-10 21:11:38 +08:00
if meetName ? then meetName # great return it, no database query
else # we need it from the database
meet = Meteor . Meetings . findOne ( { } )
if meet ? . meetingName
2014-07-18 04:13:06 +08:00
setInSession " meetingName " , meet ? . meetingName # store in session for fast access next time
2014-07-10 21:11:38 +08:00
meet ? . meetingName
else null
2014-07-09 21:28:33 +08:00
2014-07-10 21:11:38 +08:00
Handlebars . registerHelper " getMeetingName " , ->
window . getMeetingName ( )
2014-06-24 00:58:30 +08:00
Handlebars . registerHelper " isUserSharingVideo " , (u) ->
u . webcam_stream . length isnt 0
2014-06-27 21:59:31 +08:00
Handlebars . registerHelper " isCurrentUser " , (id) ->
2014-07-18 04:13:06 +08:00
id is getInSession ( " userId " )
2014-06-27 21:59:31 +08:00
# retrieves all users in the meeting
2014-06-25 02:10:02 +08:00
Handlebars . registerHelper " getUsersInMeeting " , ->
2014-07-09 21:15:50 +08:00
Meteor . Users . find ( { } )
2014-07-11 23:53:49 +08:00
2014-07-25 00:12:27 +08:00
Handlebars . registerHelper " isUserTalking " , (u) ->
2014-07-29 01:43:26 +08:00
if u ? then u . voiceUser ? . talking
else return false
Handlebars . registerHelper " isUserSharingAudio " , (u) ->
if u ? then u . voiceUser ? . joined
else return false
# Starts the entire logout procedure. Can be called for signout out
2014-07-25 01:56:31 +08:00
# meeting: the meeting the user is in
# the user's userId
2014-07-28 23:00:07 +08:00
@userLogout = (meeting, user) ->
2014-07-25 01:56:31 +08:00
Meteor . call ( " userLogout " , meeting , user )
2014-07-28 23:00:07 +08:00
# Clear the local user session and redirect them away
2014-07-25 01:56:31 +08:00
setInSession ( " userId " , null )
setInSession ( " meetingId " , null )
setInSession ( " currentChatId " , null )
setInSession ( " meetingName " , null )
setInSession ( " bbbServerVersion " , null )
setInSession ( " userName " , null )
setInSession " display_navbar " , false # needed to hide navbar when the layout template renders
2014-07-28 23:00:07 +08:00
Router . go ( ' logout ' ) # navigate to logout
2014-07-29 01:43:26 +08:00
@userKick = (meeting, user) ->
Meteor . call ( " userKick " , meeting , user )
@getTime = -> # returns epoch in ms
( new Date ) . valueOf ( )