bigbluebutton-Github/labs/meteor-client/client/views/users/user_item.coffee

119 lines
3.1 KiB
CoffeeScript
Raw Normal View History

2014-06-12 22:08:55 +08:00
Template.userItem.helpers
domain: ->
a = document.createElement("a")
a.href = @url
a.hostname
# retrieve account for selected user, or the first mod account if nothing is selected
getCurrentUser: ->
id = Session.get("userId") or "a1a1a1a1a1a1"
u = Meteor.users.findOne("user.userId": id)
2014-06-12 22:08:55 +08:00
u
# using handlebars' {{equals}} wasn't working for these some reason, so heres a simple JS function to do it
compareUserIds: (u1, u2) ->
u1 is u2
Template.userItem.events
"click input.raiseHand": (event) ->
Meteor.users.update
2014-06-12 22:08:55 +08:00
_id: @_id
,
$set:
"user.handRaised": true
"click input.disableCam": (event) ->
Meteor.users.update
2014-06-12 22:08:55 +08:00
_id: @_id
,
$set:
"user.sharingVideo": false
"click input.disableMic": (event) ->
Meteor.users.update
2014-06-12 22:08:55 +08:00
_id: @_id
,
$set:
"user.sharingAudio": false
"click input.enableMic": (event) ->
Meteor.users.update
2014-06-12 22:08:55 +08:00
_id: @_id
,
$set:
"user.sharingAudio": true
"click input.enableCam": (event) ->
Meteor.users.update
2014-06-12 22:08:55 +08:00
_id: @_id
,
$set:
"user.sharingVideo": true
"click input.lowerHand": (event) ->
Meteor.users.update
2014-06-12 22:08:55 +08:00
_id: @_id
,
$set:
"user.handRaised": false
"click input.setPresenter": (event) ->
#
# Not the best way to go about doing this
# The meeting should probably know about the presenter instead of the individual user
#
2014-06-12 22:08:55 +08:00
# only perform operation if user is not already presenter, prevent extra DB work
unless @user.presenter
# from new user, find meeting
m = Meetings.findOne(meetingName: @meetingId)
# unset old user as presenter
if m?
u = Meteor.users.findOne(
2014-06-12 22:08:55 +08:00
meetingId: m.meetingName
"user.presenter": true
)
if u?
Meteor.users.update
2014-06-12 22:08:55 +08:00
_id: u._id
,
$set:
"user.presenter": false
# set newly selected user as presenter
Meteor.users.update
2014-06-12 22:08:55 +08:00
_id: @_id
,
$set:
"user.presenter": true
"click input.kickUser": (event) ->
#
# Add:
# When user is blown away, if they were presenter remove that from meeting (if kicking the presenter is even possible?)
#
user = @
meeting = Meetings.findOne(meetingName: @meetingId)
if user? and meeting?
# find users index. I couldn't get indexOf() working because the array is of objects
index = -1
i = 0
while i < meeting.users.length
if meeting.users[i].userId is user.user.externUserId
index = i
break
i++
if index >= 0
meeting.users.splice index, 1 # remove user from meeting
Meetings.update # update meeting
_id: meeting._id
,
$set:
users: meeting.users
Meteor.users.update # remove meeting from user
2014-06-12 22:08:55 +08:00
_id: @_id
,
$set:
meetingId: null