Include participants data w/ HostSession 'started' event

This commit is contained in:
Kevin Sawicki & Nathan Sobo
2013-07-25 11:51:07 -06:00
parent a4e1d84ebb
commit 1755702e1a
4 changed files with 29 additions and 8 deletions

View File

@@ -40,8 +40,8 @@ class HostSession extends Session
@doc = @createDocument()
channel = @subscribe(@id)
channel.on 'channel:opened', =>
@trigger 'started'
channel.on 'channel:subscribed', (participants) =>
@trigger 'started', participants
@connectDocument(@doc, channel)
channel.on 'channel:participant-entered', =>

View File

@@ -12,10 +12,9 @@ class WsChannel
@socket = new WebSocket("ws://localhost:8080?token=#{token}")
@socket.onopen = =>
@rawSend 'subscribe', @name, @clientId
@trigger 'channel:opened'
@socket.onmessage = (message) =>
[operation, data] = JSON.parse(message.data)
data = JSON.parse(message.data)
@trigger(data...)
send: (data...) ->

View File

@@ -8,14 +8,24 @@ HostSession = require '../lib/host-session'
describe "Collaboration", ->
describe "when a host and a guest join a channel", ->
[server, hostSession, guestSession, repositoryMirrored] = []
[server, hostSession, guestSession, repositoryMirrored, token, userDataByToken] = []
beforeEach ->
jasmine.unspy(window, 'setTimeout')
spyOn(keytar, 'getPassword')
spyOn(keytar, 'getPassword').andCallFake -> token
token = 'hubot-token'
userDataByToken =
'hubot-token':
login: 'hubot'
server = new Server()
spyOn(server, 'verifyClient').andCallFake (info, verify) -> verify(true)
spyOn(server, 'log')
spyOn(server, 'error')
spyOn(server, 'authenticate').andCallFake (token, callback) ->
if userData = userDataByToken[token]
callback(null, userData)
else
callback("Invalid token")
waitsFor "server to start", (started) ->
server.once 'started', started
@@ -64,3 +74,15 @@ describe "Collaboration", ->
runs ->
expect(repositoryMirrored).toBe true
it "reports on the participants of the channel", ->
hostSession.start()
waitsFor "host session to start", (started) ->
participants = null
hostSession.one 'started', (participantsArg) ->
participants = participantsArg
started()
runs ->
expect(participants).toEqual [login: 'hubot', clientId: hostSession.clientId]