This commit is contained in:
probablycorey
2013-07-19 15:35:45 -07:00
committed by Corey Johnson & Matt Colyer
parent 642df0924d
commit 7b57c12f59
2 changed files with 23 additions and 24 deletions

View File

@@ -18,21 +18,26 @@ class GuestSession
constructor: (sessionId) ->
@peer = createPeer()
connection = @peer.connect(sessionId, {reliable: true, connectionId: @getId()})
connection = @peer.connect(sessionId, reliable: true)
connection.on 'open', =>
console.log 'connection opened'
@trigger 'connection-opened'
connection.once 'data', (data) =>
@trigger 'connection-document-received'
console.log 'received document', data
doc = telepath.Document.deserialize(data.doc, site: telepath.createSite(@getId()))
atom.windowState = doc.get('windowState')
@repository = doc.get('collaborationState.repositoryState')
@participants = doc.get('collaborationState.participants')
@participants.on 'changed', =>
@trigger 'participants-changed', @participants.toObject()
connectDocument(doc, connection)
@mirrorRepository(data.repoSnapshot)
connection.on 'data', (data) =>
console.log 'received document', data
@trigger 'connection-document-received'
@createTelepathDocument(data, connection)
createTelepathDocument: (data, connection) ->
doc = telepath.Document.deserialize(data.doc, site: telepath.createSite(@getId()))
atom.windowState = doc.get('windowState')
@repository = doc.get('collaborationState.repositoryState')
@participants = doc.get('collaborationState.participants')
@participants.on 'changed', =>
@trigger 'participants-changed', @participants.toObject()
connectDocument(doc, connection)
@mirrorRepository(data.repoSnapshot)
mirrorRepository: (repoSnapshot)->
repoUrl = @repository.get('url')

View File

@@ -42,24 +42,18 @@ class HostSession
@peer.on 'connection', (connection) =>
connection.on 'open', =>
console.log 'sending document'
connection.send({repoSnapshot, doc: @doc.serialize()})
connection.send({repoSnapshot, doc: @doc.serialize(), telepath: true})
connectDocument(@doc, connection)
@sharing = true
@trigger 'started'
connection.on 'close', =>
console.log 'conection closed'
console.log 'sharing session stopped'
@sharing = false
@participants.each (participant, index) =>
if connection.peer is participant.get('id')
@participants.remove(index)
@peer.on 'open', =>
console.log 'sharing session started'
@sharing = true
@trigger 'started'
@peer.on 'close', =>
console.log 'sharing session stopped'
@sharing = false
@trigger 'stopped'
@trigger 'stopped'
@getId()