2014-11-22 04:57:36 +08:00
|
|
|
# Publish only the online users that are in the particular meetingId
|
2014-06-19 23:36:51 +08:00
|
|
|
# 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 04:57:36 +08:00
|
|
|
Meteor.log.info "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?
|
2014-11-22 04:57:36 +08:00
|
|
|
Meteor.log.info "found it from the first time #{userid}"
|
2014-11-22 04:29:07 +08:00
|
|
|
if isAllowedTo('subscribeUsers', meetingId, userid, authToken)
|
2014-12-12 01:23:19 +08:00
|
|
|
Meteor.log.info "#{userid} was 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"}})
|
2014-11-22 04:57:36 +08:00
|
|
|
Meteor.log.info "username of the subscriber: " + username + ", connection_status becomes online"
|
2014-11-21 07:35:30 +08:00
|
|
|
|
|
|
|
@_session.socket.on("close", Meteor.bindEnvironment(=>
|
2014-11-22 04:57:36 +08:00
|
|
|
Meteor.log.info "\na user lost connection: session.id=#{@_session.id} userId = #{userid}, username=#{username}, meeting=#{meetingId}"
|
2014-11-21 07:35:30 +08:00
|
|
|
Meteor.Users.update({'meetingId':meetingId, 'userId': userid}, {$set:{'user.connection_status': "offline"}})
|
2014-11-22 04:57:36 +08:00
|
|
|
Meteor.log.info "username of the user losing connection: " + username + ", connection_status: becomes offline"
|
2014-11-22 04:29:07 +08:00
|
|
|
requestUserLeaving meetingId, userid
|
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-12-11 00:23:25 +08:00
|
|
|
{meetingId: meetingId, 'user.connection_status':{$in: ["online", ""]}},
|
2014-11-22 04:29:07 +08:00
|
|
|
{fields:{'authToken': false}
|
2014-11-21 07:35:30 +08:00
|
|
|
})
|
2014-11-22 04:29:07 +08:00
|
|
|
else
|
2014-12-12 01:23:19 +08:00
|
|
|
Meteor.log.warn "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
|
2014-12-12 01:23:19 +08:00
|
|
|
Meteor.log.error "there was no such user #{userid} in #{meetingId}"
|
2014-11-20 04:14:19 +08:00
|
|
|
Meteor.Users.find(
|
2014-12-11 00:23:25 +08:00
|
|
|
{meetingId: meetingId, 'user.connection_status':{$in: ["online", ""]}},
|
2014-11-21 07:35:30 +08:00
|
|
|
{fields:{'authToken': false}
|
2014-11-20 04:14:19 +08:00
|
|
|
})
|
|
|
|
|
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 04:57:36 +08:00
|
|
|
Meteor.log.info "publishing chat for #{meetingId} #{userid} #{authToken}"
|
2014-11-28 04:30:23 +08:00
|
|
|
return Meteor.Chat.find({$or: [
|
|
|
|
{'message.chat_type': 'PUBLIC_CHAT', 'meetingId': meetingId},
|
|
|
|
{'message.from_userid': userid, 'meetingId': meetingId},
|
|
|
|
{'message.to_userid': userid, 'meetingId': meetingId}
|
|
|
|
]})
|
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-22 04:57:36 +08:00
|
|
|
Meteor.log.info "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-22 04:57:36 +08:00
|
|
|
Meteor.log.info "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-22 04:57:36 +08:00
|
|
|
Meteor.log.info "publishing presentations for #{meetingId}"
|
2014-07-30 04:57:02 +08:00
|
|
|
Meteor.Presentations.find({meetingId: meetingId})
|