on regiser user add the user to the collection. on userjoin update the user

This commit is contained in:
Anton Georgiev 2014-11-20 21:32:51 +00:00
parent 0bf242900d
commit ecacf5010b
3 changed files with 70 additions and 12 deletions

View File

@ -157,10 +157,49 @@ Meteor.methods
else
Meteor.log.info "ERROR! did not find such voiceUser!"
@addUserToCollection = (meetingId, user) ->
@userJoined = (meetingId, user) ->
userId = user.userid
#check if the user is already in the meeting
unless Meteor.Users.findOne({userId:userId, meetingId: meetingId})?
u = Meteor.Users.findOne({userId:user.userid, meetingId: meetingId})
# the collection already contains an entry for this user because
# we added a dummy user on register_user_message (to save authToken)
if u?
Meteor.log.info "UPDATING USER #{user.userid}"
Meteor.Users.update({userId:user.userid, meetingId: meetingId}, {$set:{
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
connection_status: "" # TODO consider other default value
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
}})
else
# scenario: there are meetings running at the time when the meteor
# process starts. As a result we the get_users_reply message contains
# users for which we have not observed user_registered_message and
# hence we do not have the auth_token. There will be permission issues
# as the server collection does not have the auth_token of such users
# and cannot authorize their client side actions
Meteor.log.info "NOTE: got user_joined_message "
entry =
meetingId: meetingId
userId: userId
@ -191,4 +230,17 @@ Meteor.methods
webcam_stream: user.webcam_stream
id = Meteor.Users.insert(entry)
Meteor.log.info "added user userSecret=#{entry.userSecret} id=[#{id}]:#{user.name}. Users.size is now #{Meteor.Users.find({meetingId: meetingId}).count()}"
Meteor.log.info "joining user id=[#{id}]:#{user.name}. Users.size is now #{Meteor.Users.find({meetingId: meetingId}).count()}"
@createDummyUser = (meetingId, user) ->
if Meteor.Users.findOne({userId:user.userid, meetingId: meetingId})?
Meteor.log.info "ERROR!! CAN'T REGISTER AN EXISTSING USER"
else
entry =
meetingId: meetingId
userId: user.userid
authToken: user.authToken
id = Meteor.Users.insert(entry)
Meteor.log.info "added user dummy user id=[#{id}]:#{user.name}.
Users.size is now #{Meteor.Users.find({meetingId: meetingId}).count()}"

View File

@ -2,7 +2,7 @@
# On the client side we pass the meetingId parameter
Meteor.publish 'users', (meetingId, userid) ->
console.log "publishing users for #{meetingId}, #{userid}"
###
u = Meteor.Users.findOne({'userId': userid, 'meetingId': meetingId})
if u?
console.log "found it from the first time #{userid}"
@ -36,10 +36,13 @@ Meteor.publish 'users', (meetingId, userid) ->
else #subscribing before the user was added to the collection
Meteor.call "validateAuthToken", meetingId, userid, userid
console.log "there was no such user #{userid} in #{meetingId}"
###
# TODO switch the logging here with .info log
# TODO switch the logging here with .info log
Meteor.Users.find(
{meetingId: meetingId},
{fields:{'userSecret': 0}
})

View File

@ -96,17 +96,20 @@ class Meteor.RedisPubSub
users = message.payload.users
for user in users
user.timeOfJoining = message.header.current_time # TODO this might need to be removed
addUserToCollection meetingId, user
userJoined meetingId, user
return
if message.header.name is "validate_auth_token_reply"
console.log "validate_auth_token_reply--#{JSON.stringify message}"
return
if message.header.name is "user_registered_message"
createDummyUser message.payload.meeting_id, message.payload.user
return
if message.header.name is "user_joined_message"
user = message.payload.user
user.timeOfJoining = message.header.current_time
addUserToCollection meetingId, user
userJoined meetingId, user
return
if message.header.name is "user_left_message"
@ -161,7 +164,7 @@ class Meteor.RedisPubSub
#request for shapes
whiteboardId = "#{presentation.id}/#{page.num}" # d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1404411622872/1
Meteor.log.info "the whiteboard_id here is:" + whiteboardId
#Meteor.log.info "the whiteboard_id here is:" + whiteboardId
message =
"payload":