From 1755702e1a23455fa1ffd4abb487a32c5f8a7691 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki & Nathan Sobo Date: Thu, 25 Jul 2013 11:51:07 -0600 Subject: [PATCH] Include participants data w/ HostSession 'started' event --- .../collaboration/lib/host-session.coffee | 4 +-- .../collaboration/lib/ws-channel.coffee | 3 +- .../spec/collaboration-spec.coffee | 28 +++++++++++++++++-- .../vendor/atom-collaboration-server | 2 +- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/packages/collaboration/lib/host-session.coffee b/src/packages/collaboration/lib/host-session.coffee index faaa17c45..245322f7c 100644 --- a/src/packages/collaboration/lib/host-session.coffee +++ b/src/packages/collaboration/lib/host-session.coffee @@ -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', => diff --git a/src/packages/collaboration/lib/ws-channel.coffee b/src/packages/collaboration/lib/ws-channel.coffee index 02aec1ed2..25428deb8 100644 --- a/src/packages/collaboration/lib/ws-channel.coffee +++ b/src/packages/collaboration/lib/ws-channel.coffee @@ -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...) -> diff --git a/src/packages/collaboration/spec/collaboration-spec.coffee b/src/packages/collaboration/spec/collaboration-spec.coffee index 97f150049..88a8e5715 100644 --- a/src/packages/collaboration/spec/collaboration-spec.coffee +++ b/src/packages/collaboration/spec/collaboration-spec.coffee @@ -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] diff --git a/src/packages/collaboration/vendor/atom-collaboration-server b/src/packages/collaboration/vendor/atom-collaboration-server index 438a00afc..4f788e697 160000 --- a/src/packages/collaboration/vendor/atom-collaboration-server +++ b/src/packages/collaboration/vendor/atom-collaboration-server @@ -1 +1 @@ -Subproject commit 438a00afc2c5b06854f8a8151de5baf249cb3520 +Subproject commit 4f788e697bbbffaf3d33cda7a134b102b6ff867c