mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-16 02:52:31 -04:00
add comments
This commit is contained in:
parent
273af3f3aa
commit
1c74cbbc4e
2 changed files with 8 additions and 1 deletions
|
@ -17,6 +17,9 @@ module.exports = ChannelManager =
|
|||
subscribe: (rclient, baseChannel, id) ->
|
||||
clientChannelMap = @getClientMapEntry(rclient)
|
||||
channel = "#{baseChannel}:#{id}"
|
||||
# we track pending subscribes because we want to be sure that the
|
||||
# channel is active before letting the client join the doc or project,
|
||||
# so that events are not lost.
|
||||
if clientChannelMap.has(channel)
|
||||
logger.warn {channel}, "subscribe already actioned"
|
||||
# return the existing subscribe promise, so we can wait for it to resolve
|
||||
|
@ -33,6 +36,9 @@ module.exports = ChannelManager =
|
|||
unsubscribe: (rclient, baseChannel, id) ->
|
||||
clientChannelMap = @getClientMapEntry(rclient)
|
||||
channel = "#{baseChannel}:#{id}"
|
||||
# we don't need to track pending unsubscribes, because we there is no
|
||||
# harm if events continue to arrive on the channel while the unsubscribe
|
||||
# command in pending.
|
||||
if !clientChannelMap.has(channel)
|
||||
logger.error {channel}, "not subscribed - shouldn't happen"
|
||||
else
|
||||
|
|
|
@ -2,7 +2,7 @@ logger = require 'logger-sharelatex'
|
|||
{EventEmitter} = require 'events'
|
||||
|
||||
IdMap = new Map() # keep track of whether ids are from projects or docs
|
||||
RoomEvents = new EventEmitter()
|
||||
RoomEvents = new EventEmitter() # emits {project,doc}-active and {project,doc}-empty events
|
||||
|
||||
# Manage socket.io rooms for individual projects and docs
|
||||
#
|
||||
|
@ -49,6 +49,7 @@ module.exports = RoomManager =
|
|||
if beforeCount == 0
|
||||
logger.log {entity, id}, "room is now active"
|
||||
RoomEvents.once "#{entity}-subscribed-#{id}", (err) ->
|
||||
# only allow the client to join when all the relevant channels have subscribed
|
||||
logger.log {client: client.id, entity, id, beforeCount}, "client joined room after subscribing channel"
|
||||
client.join id
|
||||
callback(err)
|
||||
|
|
Loading…
Reference in a new issue