Emit 'participant-exited' events

This commit is contained in:
Kevin Sawicki & Nathan Sobo
2013-07-25 12:26:41 -06:00
parent 4c49b69613
commit 241e787d0f
5 changed files with 31 additions and 5 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)