put the disconnection handling code back in place

This commit is contained in:
Anton Georgiev 2014-11-19 20:14:19 +00:00
parent a31246c6f9
commit 9e628b0282

View File

@ -3,10 +3,47 @@
Meteor.publish 'users', (meetingId, userid) ->
console.log "publishing users for #{meetingId}, #{userid}"
Meteor.Users.find(
{meetingId: meetingId},
{fields:{'userSecret': 0}
})
u = Meteor.Users.findOne({'userId': userid, 'meetingId': meetingId})
if u?
console.log "found it from the first time #{userid}"
username = u?.user?.name or "UNKNOWN"
Meteor.Users.update({'meetingId':meetingId, 'userId': userid}, {$set:{'user.connection_status': "online"}})
console.log "username of the subscriber: " + username + ", connection_status becomes online"
@_session.socket.on("close", Meteor.bindEnvironment(=>
console.log "\na user lost connection: session.id=#{@_session.id} userId = #{userid}, username=#{username}, meeting=#{meetingId}"
Meteor.Users.update({'meetingId':meetingId, 'userId': userid}, {$set:{'user.connection_status': "offline"}})
console.log "username of the user losing connection: " + username + ", connection_status: becomes offline"
# check the status of the user later to see if the user managed to reconnect
setTimeout(Meteor.bindEnvironment(=>
result = Meteor.Users.findOne({'userId': userid, 'meetingId': meetingId})?.user?.connection_status
if result is "online"
console.log "user #{userid} (#{username}) managed to reconnect in meeting #{meetingId}"
else
console.log "user #{userid} (#{username}) failed to reconnect in meeting #{meetingId} and will be kicked out of the meeting"
requestUserLeaving meetingId, userid
)
, 10000) #TODO pick this from config.coffee
)
)
Meteor.Users.find(
{meetingId: meetingId},
{fields:{'userSecret': 0}
})
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
Meteor.publish 'chat', (meetingId, userid) ->