add clientIdToSiteId to session's document

This commit is contained in:
Ben Ogle
2013-07-26 13:39:40 -07:00
parent e088daa15b
commit 4fe90900cc

View File

@@ -52,16 +52,23 @@ class Session
@mediaConnection = @createMediaConnection()
@mediaConnection.start()
@getClientIdToSiteIdMap().set(@clientId, @site.id)
@connectDocument()
@channel.one 'channel:subscribed', (participantStates) =>
@setParticipantStates(participantStates)
@listening = true
@trigger 'started', @getParticipants()
@on 'participant-entered', =>
@on 'participant-entered', (participant) =>
# inject siteId; TODO: should be moved to somewhere less sketch
guestSiteId = @nextGuestSiteId++
clientIdToSiteId = @getClientIdToSiteIdMap()
clientIdToSiteId.set(participant.clientId, guestSiteId)
@snapshotRepository (repoSnapshot) =>
welcomePackage =
siteId: @nextGuestSiteId++
siteId: guestSiteId
doc: @doc.serialize()
repoSnapshot: repoSnapshot
@channel.send 'welcome', welcomePackage
@@ -95,6 +102,7 @@ class Session
collaborationState:
guest: {description: '', candidate: '', ready: false}
host: {description: '', candidate: ''}
clientIdToSiteId: {}
repositoryState:
url: project.getRepo().getConfigValue('remote.origin.url')
branch: project.getRepo().getShortHead()
@@ -126,6 +134,8 @@ class Session
setParticipantStates: (participantStates) ->
@participants = participantStates.map (state) -> new Participant(state)
getClientIdToSiteIdMap: -> @doc.get('collaborationState.clientIdToSiteId')
subscribe: (name) ->
token = keytar.getPassword('github.com', 'github')
channel = new WsChannel({name, @host, @port, @secure, token})