diff --git a/.gitmodules b/.gitmodules index 8cf380ccd..bfe9e9757 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "vendor/telepath"] path = vendor/telepath url = https://github.com/github/telepath.git +[submodule "src/packages/collaboration/vendor/atom-collaboration-server"] + path = src/packages/collaboration/vendor/atom-collaboration-server + url = https://github.com/github/atom-collaboration-server.git diff --git a/package.json b/package.json index 957359a2e..372255d31 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,8 @@ "grunt-contrib-coffee": "~0.7.0", "grunt-contrib-less": "~0.5.2", "jasmine-focused": "~0.7.0", - "walkdir": "0.0.7" + "walkdir": "0.0.7", + "ws": "0.4.27" }, "private": true, "scripts": { diff --git a/src/packages/collaboration/spec/collaboration-spec.coffee b/src/packages/collaboration/spec/collaboration-spec.coffee index 24195ab13..97f150049 100644 --- a/src/packages/collaboration/spec/collaboration-spec.coffee +++ b/src/packages/collaboration/spec/collaboration-spec.coffee @@ -2,79 +2,43 @@ _ = require 'underscore' keytar = require 'keytar' {Site} = require 'telepath' +Server = require '../vendor/atom-collaboration-server' GuestSession = require '../lib/guest-session' HostSession = require '../lib/host-session' -class Server - constructor: -> - @channels = {} - - getChannel: (channelName) -> - @channels[channelName] ?= new ChannelServer(channelName) - - createClient: -> new Client(this) - -class Client - @nextId: 1 - - constructor: (@server) -> - @id = @constructor.nextId++ - - subscribe: (channelName) -> - @server.getChannel(channelName).subscribe(this) - -class ChannelServer - constructor: (@name) -> - @channelClients = {} - - subscribe: (subscribingClient) -> - channelClient = new ChannelClient(subscribingClient, this) - @channelClients[subscribingClient.id] = channelClient - setTimeout => - for client in @getChannelClients() - if client is channelClient - client.trigger 'channel:opened' - else - client.trigger 'channel:participant-entered' - channelClient - - getChannelClients: -> _.values(@channelClients) - - send: (sendingClient, eventName, eventData) -> - setTimeout => - for client in @getChannelClients() when client isnt sendingClient - client.trigger(eventName, eventData) - -class ChannelClient - _.extend @prototype, require('event-emitter') - - constructor: (@pusherClient, @channelServer) -> - - send: (eventName, eventData) -> - @channelServer.send(this, eventName, eventData) - -fdescribe "Collaboration", -> - describe "joining a host session", -> - [hostSession, guestSession, pusher, repositoryMirrored] = [] +describe "Collaboration", -> + describe "when a host and a guest join a channel", -> + [server, hostSession, guestSession, repositoryMirrored] = [] beforeEach -> - spyOn(keytar, 'getPassword') jasmine.unspy(window, 'setTimeout') - pusherServer = new Server() - hostSession = new HostSession(new Site(1)) - spyOn(hostSession, 'snapshotRepository').andCallFake (callback) -> - callback({url: 'git://server/repo.git'}) - spyOn(hostSession, 'subscribe').andCallFake (channelName) -> - pusherServer.createClient().subscribe(channelName) - guestSession = new GuestSession(hostSession.getId()) - spyOn(guestSession, 'subscribe').andCallFake (channelName) -> - pusherServer.createClient().subscribe(channelName) - spyOn(guestSession, 'mirrorRepository').andCallFake (repoUrl, repoSnapshot, callback) -> - setTimeout -> - repositoryMirrored = true - callback() + spyOn(keytar, 'getPassword') - it "sends the document from the host session to the guest session", -> + server = new Server() + spyOn(server, 'verifyClient').andCallFake (info, verify) -> verify(true) + + waitsFor "server to start", (started) -> + server.once 'started', started + server.start() + + runs -> + hostSession = new HostSession(new Site(1)) + guestSession = new GuestSession(hostSession.getId()) + + spyOn(hostSession, 'snapshotRepository').andCallFake (callback) -> + callback({url: 'git://server/repo.git'}) + + spyOn(guestSession, 'mirrorRepository').andCallFake (repoUrl, repoSnapshot, callback) -> + setTimeout -> + repositoryMirrored = true + callback() + + afterEach -> + waitsFor "server to stop", (stopped) -> + server.once 'stopped', stopped + server.stop() + + it "sends the document and file system from the host session to the guest session", -> hostSession.start() startedHandler = jasmine.createSpy('startedHandler') guestSession.on 'started', startedHandler diff --git a/src/packages/collaboration/vendor/atom-collaboration-server b/src/packages/collaboration/vendor/atom-collaboration-server new file mode 160000 index 000000000..438a00afc --- /dev/null +++ b/src/packages/collaboration/vendor/atom-collaboration-server @@ -0,0 +1 @@ +Subproject commit 438a00afc2c5b06854f8a8151de5baf249cb3520