mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Add share button to buddy list
This commit is contained in:
committed by
Kevin Sawicki
parent
0fd44994ee
commit
be078b2b41
@@ -6,14 +6,39 @@ BuddyView = require './buddy-view'
|
||||
module.exports =
|
||||
class BuddyList extends ScrollView
|
||||
@content: ->
|
||||
@div class: 'buddy-list', tabindex: -1
|
||||
@div class: 'buddy-list', tabindex: -1, =>
|
||||
@button outlet: 'shareButton', type: 'button', class: 'btn btn-default'
|
||||
@div outlet: 'buddies'
|
||||
|
||||
initialize: (@presence) ->
|
||||
presence: null
|
||||
sharingSession: null
|
||||
|
||||
initialize: (@presence, @sharingSession) ->
|
||||
super
|
||||
|
||||
if @sharingSession.isSharing()
|
||||
@shareButton.text('Stop')
|
||||
else
|
||||
@shareButton.text('Start')
|
||||
|
||||
@presence.on 'person-added', => @updateBuddies()
|
||||
@presence.on 'person-removed', => @updateBuddies()
|
||||
@presence.on 'person-status-changed', => @updateBuddies()
|
||||
@shareButton.on 'click', =>
|
||||
@shareButton.disable()
|
||||
|
||||
if @sharingSession.isSharing()
|
||||
@shareButton.text('Stopping...')
|
||||
@sharingSession.stop()
|
||||
else
|
||||
@shareButton.text('Starting...')
|
||||
@sharingSession.start()
|
||||
|
||||
@sharingSession.on 'started', =>
|
||||
@shareButton.text('Stop').enable()
|
||||
|
||||
@sharingSession.on 'stopped', =>
|
||||
@shareButton.text('Start').enable()
|
||||
|
||||
toggle: ->
|
||||
if @hasParent()
|
||||
@@ -27,5 +52,5 @@ class BuddyList extends ScrollView
|
||||
@updateBuddies()
|
||||
|
||||
updateBuddies: ->
|
||||
@empty()
|
||||
@append(new BuddyView(buddy)) for buddy in @presence.getPeople()
|
||||
@buddies.empty()
|
||||
@buddies.append(new BuddyView(buddy)) for buddy in @presence.getPeople()
|
||||
|
||||
@@ -1,34 +1,24 @@
|
||||
JoinPromptView = require './join-prompt-view'
|
||||
{createSite, Document} = require 'telepath'
|
||||
{createPeer, connectDocument} = require './session-utils'
|
||||
Presence = require './presence'
|
||||
SharingSession = require './sharing-session'
|
||||
BuddyList = require './buddy-list'
|
||||
|
||||
startSession = ->
|
||||
peer = createPeer()
|
||||
peer.on 'connection', (connection) ->
|
||||
connection.on 'open', ->
|
||||
console.log 'sending document'
|
||||
windowState = atom.getWindowState()
|
||||
connection.send(windowState.serialize())
|
||||
connectDocument(windowState, connection)
|
||||
peer.id
|
||||
JoinPromptView = require './join-prompt-view'
|
||||
|
||||
module.exports =
|
||||
activate: ->
|
||||
presence = new Presence()
|
||||
sharingSession = new SharingSession()
|
||||
buddyList = null
|
||||
sessionId = null
|
||||
|
||||
rootView.command 'collaboration:toggle-buddy-list', ->
|
||||
buddyList ?= new BuddyList(presence)
|
||||
buddyList ?= new BuddyList(presence, sharingSession)
|
||||
buddyList.toggle()
|
||||
|
||||
rootView.command 'collaboration:copy-session-id', ->
|
||||
sessionId = sharingSession.getId()
|
||||
pasteboard.write(sessionId) if sessionId
|
||||
|
||||
rootView.command 'collaboration:start-session', ->
|
||||
if sessionId = startSession()
|
||||
if sessionId = sharingSession.start()
|
||||
pasteboard.write(sessionId)
|
||||
|
||||
rootView.command 'collaboration:join-session', ->
|
||||
@@ -38,3 +28,5 @@ module.exports =
|
||||
resourcePath: window.resourcePath
|
||||
sessionId: id
|
||||
atom.openWindow(windowSettings)
|
||||
|
||||
rootView.trigger 'collaboration:toggle-buddy-list' # TEMP
|
||||
|
||||
@@ -4,7 +4,7 @@ Guid = require 'guid'
|
||||
module.exports =
|
||||
createPeer: ->
|
||||
id = Guid.create().toString()
|
||||
new Peer(id, host: 'ec2-54-218-51-127.us-west-2.compute.amazonaws.com', port: 8080)
|
||||
new Peer(id, key: '0njqmaln320dlsor')
|
||||
|
||||
connectDocument: (doc, connection) ->
|
||||
nextOutputEventId = 1
|
||||
|
||||
44
src/packages/collaboration/lib/sharing-session.coffee
Normal file
44
src/packages/collaboration/lib/sharing-session.coffee
Normal file
@@ -0,0 +1,44 @@
|
||||
_ = 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
src/packages/collaboration/vendor/peer.js
vendored
2
src/packages/collaboration/vendor/peer.js
vendored
@@ -782,7 +782,7 @@ var util = {
|
||||
global.attachEvent('onmessage', handleMessage);
|
||||
}
|
||||
return setZeroTimeoutPostMessage;
|
||||
}(this)),
|
||||
}(window)),
|
||||
|
||||
blobToArrayBuffer: function(blob, cb){
|
||||
var fr = new FileReader();
|
||||
|
||||
Reference in New Issue
Block a user