Add Participant class

This commit is contained in:
Kevin Sawicki & Nathan Sobo
2013-07-26 12:25:15 -06:00
parent 32f75040de
commit a60320df3a
5 changed files with 45 additions and 14 deletions

View File

@@ -20,10 +20,10 @@ module.exports =
session.on 'participant-entered', (participant) =>
view = @createParticipant(session, participant)
participantViews[participant.id] = view
participantViews[participant.clientId] = view
session.on 'participant-exited', (participant) =>
view = participantViews[participant.id]
view = participantViews[participant.clientId]
view.detach()
rootView.eachPane (pane) ->

View File

@@ -14,8 +14,10 @@ class ParticipantView extends View
@div class: 'volume-container', outlet: 'volumeContainer', =>
@div class: 'volume', outlet: 'volume'
initialize: (@session, {id, email}) ->
@session.waitForStream (stream) =>
initialize: (@session, @participant) ->
{id, email} = @participant.getState()
@session.waitForStream (stream) =>
@video[0].src = URL.createObjectURL(stream)
@video.click =>

View File

@@ -0,0 +1,15 @@
_ = require 'underscore'
module.exports =
class Participant
constructor: (@state) ->
{@clientId} = @state
getState: -> @state
isEqual: (other) ->
if other instanceof @constructor
otherState = other.getState()
else
otherState = other
_.isEqual(@getState(), otherState)

View File

@@ -7,6 +7,7 @@ patrick = require 'patrick'
MediaConnection = require './media-connection'
Project = require 'project'
WsChannel = require './ws-channel'
Participant = require './participant'
module.exports =
class Session
@@ -39,14 +40,11 @@ class Session
@listening = false
@trigger 'stopped'
@channel.on 'channel:participant-entered', (participant) =>
@participants.push(participant)
@trigger 'participant-entered', participant
@channel.on 'channel:participant-entered', (participantState) =>
@trigger 'participant-entered', @addParticipant(participantState)
@channel.on 'channel:participant-exited', (participant) =>
@participants = @participants.filter ({clientId}) ->
clientId isnt participant.clientId
@trigger 'participant-exited', participant
@channel.on 'channel:participant-exited', (participantState) =>
@trigger 'participant-exited', @removeParticipant(participantState)
if @isLeader()
@doc = @createDocument()
@@ -54,7 +52,8 @@ class Session
@mediaConnection.start()
@connectDocument()
@channel.one 'channel:subscribed', (@participants) =>
@channel.one 'channel:subscribed', (participantStates) =>
@setParticipantStates(participantStates)
@listening = true
@trigger 'started', @getParticipants()
@@ -67,7 +66,8 @@ class Session
@channel.send 'welcome', welcomePackage
else
@channel.one 'channel:subscribed', (@participants) =>
@channel.one 'channel:subscribed', (participantStates) =>
@setParticipantStates(participantStates)
@channel.one 'welcome', ({doc, siteId, repoSnapshot}) =>
@site = new Site(siteId)
@doc = @site.deserializeDocument(doc)
@@ -108,6 +108,20 @@ class Session
getOtherParticipants: ->
@getParticipants().filter ({clientId}) => clientId isnt @clientId
addParticipant: (participantState) ->
participant = new Participant(participantState)
@participants.push(participant)
participant
removeParticipant: (participantState) ->
clientIdToRemove = participantState.clientId
participant = _.find @participants, ({clientId}) -> clientId is clientIdToRemove
@participants = _.without(@participants, participant)
participant
setParticipantStates: (participantStates) ->
@participants = participantStates.map (state) -> new Participant(state)
subscribe: (name) ->
token = keytar.getPassword('github.com', 'github')
channel = new WsChannel({name, @host, @port, @secure, token})

View File

@@ -9,7 +9,7 @@ ServerHost = 'localhost'
ServerPort = 8081
describe "Collaboration", ->
describe "when a host and a guest join a channel", ->
fdescribe "when a host and a guest join a channel", ->
[server, leaderSession, guestSession, leaderStartedHandler, guestStartedHandler, guestStoppedHandler, token, userDataByToken] = []
beforeEach ->