mirror of
https://github.com/atom/atom.git
synced 2026-02-02 02:35:00 -05:00
Show participants in the session
This commit is contained in:
committed by
Kevin Sawicki
parent
40d500949b
commit
460a09f9eb
@@ -2,8 +2,7 @@ require 'atom'
|
||||
require 'window'
|
||||
$ = require 'jquery'
|
||||
{$$} = require 'space-pen'
|
||||
{createPeer, connectDocument} = require './session-utils'
|
||||
{createSite, Document} = require 'telepath'
|
||||
GuestSession = require './guest-session'
|
||||
|
||||
window.setDimensions(width: 350, height: 100)
|
||||
window.setUpEnvironment('editor')
|
||||
@@ -15,13 +14,7 @@ loadingView = $$ ->
|
||||
$(window.rootViewParentSelector).append(loadingView)
|
||||
atom.show()
|
||||
|
||||
peer = createPeer()
|
||||
connection = peer.connect(sessionId, reliable: true)
|
||||
connection.on 'open', ->
|
||||
console.log 'connection opened'
|
||||
connection.once 'data', (data) ->
|
||||
loadingView.remove()
|
||||
console.log 'received document'
|
||||
atom.windowState = Document.deserialize(createSite(peer.id), data)
|
||||
connectDocument(atom.windowState, connection)
|
||||
window.startEditorWindow()
|
||||
atom.guestSession = new GuestSession(sessionId)
|
||||
atom.guestSession.on 'started', ->
|
||||
loadingView.remove()
|
||||
window.startEditorWindow()
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
url = require 'url'
|
||||
{$$, View} = require 'space-pen'
|
||||
|
||||
module.exports =
|
||||
class CollaborationView extends View
|
||||
@content: ->
|
||||
@div class: 'collaboration', tabindex: -1, =>
|
||||
@div outlet: 'share', type: 'button', class: 'share'
|
||||
@div outlet: 'participants'
|
||||
|
||||
sharingSession: null
|
||||
|
||||
initialize: (@sharingSession) ->
|
||||
if @sharingSession.isSharing()
|
||||
@share.addClass('running')
|
||||
|
||||
@share.on 'click', =>
|
||||
@share.disable()
|
||||
|
||||
if @sharingSession.isSharing()
|
||||
@sharingSession.stop()
|
||||
else
|
||||
@sharingSession.start()
|
||||
|
||||
@sharingSession.on 'started stopped', =>
|
||||
@share.toggleClass('running').enable()
|
||||
|
||||
@attach()
|
||||
|
||||
toggle: ->
|
||||
if @hasParent()
|
||||
@detach()
|
||||
else
|
||||
@attach()
|
||||
|
||||
attach: ->
|
||||
rootView.horizontal.append(this)
|
||||
@focus()
|
||||
@@ -1,24 +1,28 @@
|
||||
CollaborationView = require './collaboration-view'
|
||||
SharingSession = require './sharing-session'
|
||||
GuestView = require './guest-view'
|
||||
HostView = require './host-view'
|
||||
HostSession = require './host-session'
|
||||
JoinPromptView = require './join-prompt-view'
|
||||
|
||||
module.exports =
|
||||
activate: ->
|
||||
sharingSession = new SharingSession()
|
||||
if atom.getLoadSettings().sessionId
|
||||
new GuestView(atom.guestSession)
|
||||
else
|
||||
hostSession = new HostSession()
|
||||
|
||||
rootView.command 'collaboration:copy-session-id', ->
|
||||
sessionId = sharingSession.getId()
|
||||
pasteboard.write(sessionId) if sessionId
|
||||
rootView.command 'collaboration:copy-session-id', ->
|
||||
sessionId = hostSession.getId()
|
||||
pasteboard.write(sessionId) if sessionId
|
||||
|
||||
rootView.command 'collaboration:start-session', ->
|
||||
new CollaborationView(sharingSession)
|
||||
if sessionId = sharingSession.start()
|
||||
pasteboard.write(sessionId)
|
||||
rootView.command 'collaboration:start-session', ->
|
||||
new HostView(hostSession)
|
||||
if sessionId = hostSession.start()
|
||||
pasteboard.write(sessionId)
|
||||
|
||||
rootView.command 'collaboration:join-session', ->
|
||||
new JoinPromptView (id) ->
|
||||
windowSettings =
|
||||
bootstrapScript: require.resolve('collaboration/lib/bootstrap')
|
||||
resourcePath: window.resourcePath
|
||||
sessionId: id
|
||||
atom.openWindow(windowSettings)
|
||||
rootView.command 'collaboration:join-session', ->
|
||||
new JoinPromptView (id) ->
|
||||
windowSettings =
|
||||
bootstrapScript: require.resolve('collaboration/lib/bootstrap')
|
||||
resourcePath: window.resourcePath
|
||||
sessionId: id
|
||||
atom.openWindow(windowSettings)
|
||||
|
||||
30
src/packages/collaboration/lib/guest-session.coffee
Normal file
30
src/packages/collaboration/lib/guest-session.coffee
Normal file
@@ -0,0 +1,30 @@
|
||||
_ = require 'underscore'
|
||||
telepath = require 'telepath'
|
||||
{connectDocument, createPeer} = require './session-utils'
|
||||
|
||||
module.exports =
|
||||
class GuestSession
|
||||
_.extend @prototype, require('event-emitter')
|
||||
|
||||
participants: null
|
||||
peer: null
|
||||
|
||||
constructor: (sessionId) ->
|
||||
@peer = createPeer()
|
||||
connection = @peer.connect(sessionId, {reliable: true, connectionId: @getId()})
|
||||
connection.on 'open', =>
|
||||
console.log 'connection opened'
|
||||
connection.once 'data', (data) =>
|
||||
console.log 'received document'
|
||||
doc = telepath.Document.deserialize(telepath.createSite(@getId()), data)
|
||||
atom.windowState = doc.get('windowState')
|
||||
@participants = doc.get('participants')
|
||||
connectDocument(doc, connection)
|
||||
|
||||
@trigger 'started'
|
||||
|
||||
@participants.push
|
||||
id: @getId()
|
||||
email: git.getConfigValue('user.email')
|
||||
|
||||
getId: -> @peer.id
|
||||
34
src/packages/collaboration/lib/guest-view.coffee
Normal file
34
src/packages/collaboration/lib/guest-view.coffee
Normal file
@@ -0,0 +1,34 @@
|
||||
{$$, View} = require 'space-pen'
|
||||
|
||||
module.exports =
|
||||
class GuestView extends View
|
||||
@content: ->
|
||||
@div class: 'collaboration', tabindex: -1, =>
|
||||
@div class: 'guest'
|
||||
@div outlet: 'participants'
|
||||
|
||||
guestSession: null
|
||||
|
||||
initialize: (@guestSession) ->
|
||||
@guestSession.on 'participants-changed', (participants) =>
|
||||
@updateParticipants(participants)
|
||||
|
||||
@updateParticipants(@guestSession.participants.toObject())
|
||||
|
||||
@attach()
|
||||
|
||||
updateParticipants: (participants) ->
|
||||
@participants.empty()
|
||||
for {email, id} in participants when id isnt @guestSession.getId()
|
||||
@participants.append $$ ->
|
||||
@div email
|
||||
|
||||
toggle: ->
|
||||
if @hasParent()
|
||||
@detach()
|
||||
else
|
||||
@attach()
|
||||
|
||||
attach: ->
|
||||
rootView.horizontal.append(this)
|
||||
@focus()
|
||||
63
src/packages/collaboration/lib/host-session.coffee
Normal file
63
src/packages/collaboration/lib/host-session.coffee
Normal file
@@ -0,0 +1,63 @@
|
||||
_ = require 'underscore'
|
||||
telepath = require 'telepath'
|
||||
{createPeer, connectDocument} = require './session-utils'
|
||||
|
||||
module.exports =
|
||||
class HostSession
|
||||
_.extend @prototype, require('event-emitter')
|
||||
|
||||
doc: null
|
||||
participants: null
|
||||
peer: null
|
||||
sharing: false
|
||||
|
||||
start: ->
|
||||
return if @peer?
|
||||
|
||||
@peer = createPeer()
|
||||
@doc = telepath.Document.create({}, site: telepath.createSite(@getId()))
|
||||
@doc.set('windowState', atom.windowState)
|
||||
@doc.set('participants', [])
|
||||
@participants = @doc.get('participants')
|
||||
@participants.push
|
||||
id: @getId()
|
||||
email: git.getConfigValue('user.email')
|
||||
@participants.observe =>
|
||||
@trigger 'participants-changed', @participants.toObject()
|
||||
|
||||
@peer.on 'connection', (connection) =>
|
||||
console.log connection
|
||||
connection.on 'open', =>
|
||||
console.log 'sending document'
|
||||
connection.send(@doc.serialize())
|
||||
connectDocument(@doc, connection)
|
||||
|
||||
connection.on 'close', =>
|
||||
console.log 'conection closed'
|
||||
@participants.each (participant, index) =>
|
||||
if connection.peer is participant.get('id')
|
||||
@participants.remove(index)
|
||||
|
||||
@peer.on 'open', =>
|
||||
console.log 'sharing session started'
|
||||
@sharing = true
|
||||
@trigger 'started'
|
||||
|
||||
@peer.on 'close', =>
|
||||
console.log 'sharing session stopped'
|
||||
@sharing = false
|
||||
@trigger 'stopped'
|
||||
|
||||
@getId()
|
||||
|
||||
stop: ->
|
||||
return unless @peer?
|
||||
|
||||
@peer.destroy()
|
||||
@peer = null
|
||||
|
||||
getId: ->
|
||||
@peer.id
|
||||
|
||||
isSharing: ->
|
||||
@sharing
|
||||
46
src/packages/collaboration/lib/host-view.coffee
Normal file
46
src/packages/collaboration/lib/host-view.coffee
Normal file
@@ -0,0 +1,46 @@
|
||||
{$$, View} = require 'space-pen'
|
||||
|
||||
module.exports =
|
||||
class HostView extends View
|
||||
@content: ->
|
||||
@div class: 'collaboration', tabindex: -1, =>
|
||||
@div outlet: 'share', type: 'button', class: 'share'
|
||||
@div outlet: 'participants'
|
||||
|
||||
hostSession: null
|
||||
|
||||
initialize: (@hostSession) ->
|
||||
if @hostSession.isSharing()
|
||||
@share.addClass('running')
|
||||
|
||||
@share.on 'click', =>
|
||||
@share.disable()
|
||||
|
||||
if @hostSession.isSharing()
|
||||
@hostSession.stop()
|
||||
else
|
||||
@hostSession.start()
|
||||
|
||||
@hostSession.on 'started stopped', =>
|
||||
@share.toggleClass('running').enable()
|
||||
|
||||
@hostSession.on 'participants-changed', (participants) =>
|
||||
@updateParticipants(participants)
|
||||
|
||||
@attach()
|
||||
|
||||
updateParticipants: (participants) ->
|
||||
@participants.empty()
|
||||
for {email, id} in participants when id is @hostSession.getId()
|
||||
@participants.append $$ ->
|
||||
@div email
|
||||
|
||||
toggle: ->
|
||||
if @hasParent()
|
||||
@detach()
|
||||
else
|
||||
@attach()
|
||||
|
||||
attach: ->
|
||||
rootView.horizontal.append(this)
|
||||
@focus()
|
||||
@@ -9,6 +9,7 @@ module.exports =
|
||||
connectDocument: (doc, connection) ->
|
||||
nextOutputEventId = 1
|
||||
outputListener = (event) ->
|
||||
return unless connection.open
|
||||
event.id = nextOutputEventId++
|
||||
console.log 'sending event', event.id, event
|
||||
connection.send(event)
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
_ = require 'underscore'
|
||||
{createPeer, connectDocument} = require './session-utils'
|
||||
|
||||
module.exports =
|
||||
class SharingSession
|
||||
_.extend @prototype, require('event-emitter')
|
||||
|
||||
peer: null
|
||||
sharing: false
|
||||
|
||||
start: ->
|
||||
return if @peer
|
||||
|
||||
@peer = createPeer()
|
||||
@peer.on 'connection', (connection) ->
|
||||
connection.on 'open', ->
|
||||
console.log 'sending document'
|
||||
windowState = atom.getWindowState()
|
||||
connection.send(windowState.serialize())
|
||||
connectDocument(windowState, connection)
|
||||
|
||||
@peer.on 'open', =>
|
||||
console.log 'sharing session started'
|
||||
@sharing = true
|
||||
@trigger 'started'
|
||||
|
||||
@peer.on 'close', =>
|
||||
console.log 'sharing session stopped'
|
||||
@sharing = false
|
||||
@trigger 'stopped'
|
||||
|
||||
@getId()
|
||||
|
||||
stop: ->
|
||||
return unless @peer?
|
||||
|
||||
@peer.destroy()
|
||||
@peer = null
|
||||
|
||||
getId: ->
|
||||
@peer.id
|
||||
|
||||
isSharing: ->
|
||||
@sharing
|
||||
@@ -2,7 +2,6 @@
|
||||
@import "octicon-mixins.less";
|
||||
@runningColor: #99CC99;
|
||||
|
||||
|
||||
.collaboration {
|
||||
@item-line-height: @line-height-base * 1.25;
|
||||
padding: 10px;
|
||||
@@ -13,6 +12,11 @@
|
||||
.mini-icon(notifications);
|
||||
}
|
||||
|
||||
.guest {
|
||||
.mini-icon(watchers);
|
||||
color: #96CBFE;
|
||||
}
|
||||
|
||||
.running {
|
||||
color: @runningColor;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user