mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Emit 'participant-exited' events
This commit is contained in:
@@ -16,18 +16,22 @@ class GuestSession extends Session
|
||||
constructor: (@hostId) ->
|
||||
|
||||
start: ->
|
||||
channel = @subscribe(@hostId)
|
||||
@channel = @subscribe(@hostId)
|
||||
|
||||
channel.on 'channel:subscribed', (participants) =>
|
||||
@channel.on 'channel:subscribed', (participants) =>
|
||||
@trigger 'started', participants
|
||||
|
||||
channel.one 'welcome', ({doc, siteId, repoSnapshot}) =>
|
||||
@channel.on 'channel:closed', => @trigger 'stopped'
|
||||
|
||||
@channel.one 'welcome', ({doc, siteId, repoSnapshot}) =>
|
||||
@site = new telepath.Site(siteId)
|
||||
@doc = @site.deserializeDocument(doc)
|
||||
@connectDocument(@doc, channel)
|
||||
@connectDocument(@doc, @channel)
|
||||
repoUrl = @doc.get('collaborationState.repositoryState.url')
|
||||
@mirrorRepository repoUrl, repoSnapshot, => @trigger 'started'
|
||||
|
||||
stop: -> @channel.stop()
|
||||
|
||||
getSite: -> @site
|
||||
|
||||
getDocument: -> @doc
|
||||
|
||||
@@ -53,6 +53,9 @@ class HostSession extends Session
|
||||
repoSnapshot: repoSnapshot
|
||||
channel.send 'welcome', welcomePackage
|
||||
|
||||
channel.on 'channel:participant-exited', (participant) =>
|
||||
@trigger 'participant-exited', participant
|
||||
|
||||
# host = @doc.get('collaborationState.host')
|
||||
# guest = @doc.get('collaborationState.guest')
|
||||
# @mediaConnection = new MediaConnection(host, guest, isHost: true)
|
||||
|
||||
@@ -13,10 +13,16 @@ class WsChannel
|
||||
@socket.onopen = =>
|
||||
@rawSend 'subscribe', @name, @clientId
|
||||
|
||||
@socket.onclose = =>
|
||||
@trigger 'channel:closed'
|
||||
|
||||
@socket.onmessage = (message) =>
|
||||
data = JSON.parse(message.data)
|
||||
@trigger(data...)
|
||||
|
||||
stop: ->
|
||||
@socket.close()
|
||||
|
||||
send: (data...) ->
|
||||
@rawSend('broadcast', data)
|
||||
|
||||
|
||||
@@ -80,7 +80,9 @@ describe "Collaboration", ->
|
||||
it "reports on the participants of the channel", ->
|
||||
hostSession.one 'started', hostStartedHandler = jasmine.createSpy("hostStartedHandler")
|
||||
guestSession.one 'started', guestStartedHandler = jasmine.createSpy("guestStartedHandler")
|
||||
guestSession.one 'stopped', guestStoppedHandler = jasmine.createSpy("guestS")
|
||||
hostSession.on 'participant-entered', hostParticipantEnteredHandler = jasmine.createSpy("hostParticipantEnteredHandler")
|
||||
hostSession.on 'participant-exited', hostParticipantExitedHandler = jasmine.createSpy("hostParticipantExitedHandler")
|
||||
|
||||
hostSession.start()
|
||||
waitsFor "host session to start", -> hostStartedHandler.callCount > 0
|
||||
@@ -97,4 +99,15 @@ describe "Collaboration", ->
|
||||
{ login: 'hubot', clientId: hostSession.clientId }
|
||||
{ login: 'octocat', clientId: guestSession.clientId }
|
||||
]
|
||||
|
||||
waitsFor "host to see guest enter", -> hostParticipantEnteredHandler.callCount > 0
|
||||
|
||||
runs ->
|
||||
expect(hostParticipantEnteredHandler).toHaveBeenCalledWith(login: 'octocat', clientId: guestSession.clientId)
|
||||
guestSession.stop()
|
||||
|
||||
waitsFor "guest session to stop", -> guestStoppedHandler.callCount > 0
|
||||
waitsFor "host to see guest exit", -> hostParticipantExitedHandler.callCount > 0
|
||||
|
||||
runs ->
|
||||
expect(hostParticipantExitedHandler).toHaveBeenCalledWith(login: 'octocat', clientId: guestSession.clientId)
|
||||
|
||||
Reference in New Issue
Block a user