2014-06-19 23:36:51 +08:00
|
|
|
# Publish only the users that are in the particular meetingId
|
|
|
|
# On the client side we pass the meetingId parameter
|
2014-11-21 07:35:30 +08:00
|
|
|
Meteor.publish 'users', (meetingId, userid, authToken) ->
|
2014-11-22 01:07:16 +08:00
|
|
|
console.log "attempt publishing users for #{meetingId}, #{userid}, #{authToken}"
|
2014-11-22 04:29:07 +08:00
|
|
|
u = Meteor.Users.findOne({'userId': userid, 'meetingId': meetingId})
|
|
|
|
if u?
|
|
|
|
console.log "found it from the first time #{userid}"
|
|
|
|
if isAllowedTo('subscribeUsers', meetingId, userid, authToken)
|
|
|
|
console.log "allowed to subscribe to 'users'"
|
2014-11-21 07:35:30 +08:00
|
|
|
username = u?.user?.name or "UNKNOWN"
|
2014-11-22 04:29:07 +08:00
|
|
|
|
|
|
|
# offline -> online
|
|
|
|
if u.user?.connection_status isnt 'online'
|
|
|
|
Meteor.call "validateAuthToken", meetingId, userid, authToken
|
|
|
|
|
2014-11-21 07:35:30 +08:00
|
|
|
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"
|
2014-11-22 04:29:07 +08:00
|
|
|
requestUserLeaving meetingId, userid
|
2014-11-21 07:35:30 +08:00
|
|
|
# check the status of the user later to see if the user managed to reconnect
|
2014-11-22 04:29:07 +08:00
|
|
|
# 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
|
2014-11-20 04:14:19 +08:00
|
|
|
)
|
|
|
|
)
|
2014-11-21 07:35:30 +08:00
|
|
|
|
2014-11-22 04:29:07 +08:00
|
|
|
#publish the users which are not offline
|
2014-11-21 07:35:30 +08:00
|
|
|
Meteor.Users.find(
|
2014-11-22 04:29:07 +08:00
|
|
|
{meetingId: meetingId, 'user.connection_status':{$ne: "offline"}},
|
|
|
|
{fields:{'authToken': false}
|
2014-11-21 07:35:30 +08:00
|
|
|
})
|
2014-11-22 04:29:07 +08:00
|
|
|
else
|
|
|
|
console.log "was not authorized to subscribe to 'users'"
|
2014-11-21 07:35:30 +08:00
|
|
|
|
2014-11-22 04:29:07 +08:00
|
|
|
else #subscribing before the user was added to the collection
|
|
|
|
Meteor.call "validateAuthToken", meetingId, userid, authToken
|
|
|
|
console.log "there was no such user #{userid} in #{meetingId}"
|
2014-11-20 04:14:19 +08:00
|
|
|
Meteor.Users.find(
|
2014-11-22 04:29:07 +08:00
|
|
|
{meetingId: meetingId, 'user.connection_status':{$ne: "offline"}},
|
2014-11-21 07:35:30 +08:00
|
|
|
{fields:{'authToken': false}
|
2014-11-20 04:14:19 +08:00
|
|
|
})
|
|
|
|
|
2014-11-22 04:29:07 +08:00
|
|
|
# TODO switch the logging here with .info log
|
|
|
|
|
|
|
|
# Meteor.Users.find(
|
|
|
|
# {meetingId: meetingId},
|
|
|
|
# {fields:{'authToken': false}
|
|
|
|
# })
|
|
|
|
|
2014-10-30 04:40:39 +08:00
|
|
|
|
2014-11-21 07:35:30 +08:00
|
|
|
Meteor.publish 'chat', (meetingId, userid, authToken) ->
|
|
|
|
if isAllowedTo('subscribeChat', meetingId, userid, authToken)
|
2014-11-22 01:07:16 +08:00
|
|
|
console.log "publishing chat for #{meetingId} #{userid} #{authToken}"
|
2014-11-21 07:35:30 +08:00
|
|
|
me = Meteor.Users.findOne({meetingId: meetingId, userId: userid})
|
|
|
|
if me?
|
|
|
|
me = me._id
|
2014-11-22 01:07:16 +08:00
|
|
|
#TODO change _id with userid
|
|
|
|
return Meteor.Chat.find({$or: [
|
2014-11-21 07:35:30 +08:00
|
|
|
{'message.chat_type': 'PUBLIC_CHAT', 'meetingId': meetingId},
|
|
|
|
{'message.from_userid': me, 'meetingId': meetingId},
|
|
|
|
{'message.to_userid': me, 'meetingId': meetingId}
|
|
|
|
]})
|
2014-11-22 01:07:16 +08:00
|
|
|
else
|
|
|
|
console.log "could not find myself in publishing chat"
|
2014-07-08 04:31:18 +08:00
|
|
|
|
|
|
|
Meteor.publish 'shapes', (meetingId) ->
|
|
|
|
Meteor.Shapes.find({meetingId: meetingId})
|
2014-07-08 04:58:50 +08:00
|
|
|
|
|
|
|
Meteor.publish 'slides', (meetingId) ->
|
2014-11-12 21:15:13 +08:00
|
|
|
console.log "publishing slides for #{meetingId}"
|
2014-07-08 04:58:50 +08:00
|
|
|
Meteor.Slides.find({meetingId: meetingId})
|
|
|
|
|
2014-07-10 00:06:25 +08:00
|
|
|
Meteor.publish 'meetings', (meetingId) ->
|
2014-11-12 21:15:13 +08:00
|
|
|
console.log "publishing meetings for #{meetingId}"
|
2014-07-10 00:06:25 +08:00
|
|
|
Meteor.Meetings.find({meetingId: meetingId})
|
2014-07-28 23:00:07 +08:00
|
|
|
|
2014-07-30 04:57:02 +08:00
|
|
|
Meteor.publish 'presentations', (meetingId) ->
|
2014-11-12 21:15:13 +08:00
|
|
|
console.log "publishing presentations for #{meetingId}"
|
2014-07-30 04:57:02 +08:00
|
|
|
Meteor.Presentations.find({meetingId: meetingId})
|
|
|
|
|
2014-07-28 23:00:07 +08:00
|
|
|
# Clear all data in subcriptions
|
|
|
|
@clearCollections = ->
|
|
|
|
Meteor.Users.remove({})
|
2014-10-25 02:02:01 +08:00
|
|
|
Meteor.log.info "cleared Users Collection!"
|
2014-07-28 23:00:07 +08:00
|
|
|
Meteor.Chat.remove({})
|
2014-10-25 02:02:01 +08:00
|
|
|
Meteor.log.info "cleared Chat Collection!"
|
2014-07-28 23:00:07 +08:00
|
|
|
Meteor.Meetings.remove({})
|
2014-10-25 02:02:01 +08:00
|
|
|
Meteor.log.info "cleared Meetings Collection!"
|
2014-07-28 23:00:07 +08:00
|
|
|
Meteor.Shapes.remove({})
|
2014-10-25 02:02:01 +08:00
|
|
|
Meteor.log.info "cleared Shapes Collection!"
|
2014-07-28 23:00:07 +08:00
|
|
|
Meteor.Slides.remove({})
|
2014-10-25 02:02:01 +08:00
|
|
|
Meteor.log.info "cleared Slides Collection!"
|
2014-07-30 04:57:02 +08:00
|
|
|
Meteor.Presentations.remove({})
|
2014-10-25 02:02:01 +08:00
|
|
|
Meteor.log.info "cleared Presentations Collection!"
|