Add video and audio streams to host view

This commit is contained in:
Corey Johnson & Matt Colyer
2013-07-22 14:13:13 -07:00
parent 1f18c0ba02
commit d051cbe0f6
5 changed files with 31 additions and 11 deletions

View File

@@ -33,6 +33,7 @@ class GuestSession
createTelepathDocument: (data, connection) ->
doc = telepath.Document.deserialize(data.doc, site: telepath.createSite(@getId()))
servers = null
mediaConnection = new webkitRTCPeerConnection(servers)
mediaConnection.onicecandidate = (event) =>
@@ -44,6 +45,10 @@ class GuestSession
@trigger 'stream-ready', @stream
console.log('Added Stream', @stream)
constraints = {video: true, audio: true}
success = (stream) => mediaConnection.addStream(stream)
navigator.webkitGetUserMedia constraints, success, console.error
atom.windowState = doc.get('windowState')
@repository = doc.get('collaborationState.repositoryState')

View File

@@ -26,8 +26,6 @@ class GuestView extends View
addStream: (stream) ->
return unless stream
console.log "STREAM", @video[0]
@video[0].src = URL.createObjectURL(stream)
updateParticipants: (participants) ->

View File

@@ -14,21 +14,24 @@ class HostSession
participants: null
peer: null
sharing: false
mediaConnection: null
stream: null
start: ->
return if @peer?
servers = null
@mediaConnection = new webkitRTCPeerConnection(servers)
@mediaConnection.onicecandidate = (event) =>
mediaConnection = new webkitRTCPeerConnection(servers)
mediaConnection.onicecandidate = (event) =>
return unless event.candidate?
console.log "Set Host Candidate", event.candidate
@doc.set 'collaborationState.host.candidate', event.candidate
constraints = {video: true, audio: true}
success = (stream) => @mediaConnection.addStream(stream)
mediaConnection.onaddstream = ({@stream}) =>
@trigger 'stream-ready', @stream
console.log('Added Stream', @stream)
constraints = {video: true, audio: true}
success = (stream) => mediaConnection.addStream(stream)
navigator.webkitGetUserMedia constraints, success, console.error
@peer = createPeer()
@@ -53,19 +56,19 @@ class HostSession
guest.on 'changed', ({key, newValue}) =>
switch key
when 'ready'
@mediaConnection.createOffer (description) =>
mediaConnection.createOffer (description) =>
console.log "Create Offer", description
@mediaConnection.setLocalDescription(description)
mediaConnection.setLocalDescription(description)
host.set 'description', description
when 'description'
guestDescription = newValue.toObject()
console.log "Received Guest description", guestDescription
sessionDescription = new RTCSessionDescription(guestDescription)
@mediaConnection.setRemoteDescription(sessionDescription)
mediaConnection.setRemoteDescription(sessionDescription)
when 'candidate'
guestCandidate = new RTCIceCandidate newValue.toObject()
console.log('Host received candidate', guestCandidate)
@mediaConnection.addIceCandidate(new RTCIceCandidate(guestCandidate))
mediaConnection.addIceCandidate(new RTCIceCandidate(guestCandidate))
else
throw new Error("Unknown guest key '#{key}'")

View File

@@ -6,6 +6,7 @@ class HostView extends View
@content: ->
@div class: 'collaboration', tabindex: -1, =>
@div outlet: 'share', type: 'button', class: 'share'
@video autoplay: true, outlet: 'video'
@div outlet: 'participants'
hostSession: null
@@ -28,8 +29,17 @@ class HostView extends View
@hostSession.on 'participants-changed', (participants) =>
@updateParticipants(participants)
@addStream(@hostSession.stream)
@hostSession.on 'stream-ready', (stream) =>
console.log "Stream is ready", stream
@addStream(stream)
@attach()
addStream: (stream) ->
return unless stream
@video[0].src = URL.createObjectURL(stream)
updateParticipants: (participants) ->
@participants.empty()
hostId = @hostSession.getId()

View File

@@ -29,4 +29,8 @@
width: @width;
margin: 2px;
}
video {
width: @width;
}
}