mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Add TURN server support for all WebRTC connections
This commit is contained in:
@@ -7,7 +7,7 @@ patrick = require 'patrick'
|
||||
telepath = require 'telepath'
|
||||
|
||||
Project = require 'project'
|
||||
{connectDocument, createPeer} = require './session-utils'
|
||||
sessionUtils = require './session-utils'
|
||||
|
||||
module.exports =
|
||||
class GuestSession
|
||||
@@ -19,7 +19,7 @@ class GuestSession
|
||||
stream: null
|
||||
|
||||
constructor: (sessionId) ->
|
||||
@peer = createPeer()
|
||||
@peer = sessionUtils.createPeer()
|
||||
connection = @peer.connect(sessionId, reliable: true)
|
||||
|
||||
connection.on 'open', =>
|
||||
@@ -35,12 +35,11 @@ class GuestSession
|
||||
window.site = new telepath.Site(@getId())
|
||||
doc = window.site.deserializeDocument(data.doc)
|
||||
|
||||
servers = {iceServers: [{url: "stun:54.218.196.152:3478"}, {url: "turn:ninefingers@54.218.196.152:3478", credential:"youhavetoberealistic"}]}
|
||||
mediaConnection = null
|
||||
|
||||
constraints = {video: true, audio: true}
|
||||
success = (stream) =>
|
||||
mediaConnection = new webkitRTCPeerConnection(servers)
|
||||
mediaConnection = new webkitRTCPeerConnection(sessionUtils.getIceServers())
|
||||
mediaConnection.onicecandidate = (event) =>
|
||||
return unless event.candidate?
|
||||
console.log "Set Guest Candidate", event.candidate
|
||||
@@ -86,7 +85,7 @@ class GuestSession
|
||||
else
|
||||
throw new Error("Unknown host key '#{key}'")
|
||||
|
||||
connectDocument(doc, connection)
|
||||
sessionUtils.connectDocument(doc, connection)
|
||||
@mirrorRepository(data.repoSnapshot)
|
||||
|
||||
mirrorRepository: (repoSnapshot) ->
|
||||
|
||||
@@ -4,7 +4,7 @@ _ = require 'underscore'
|
||||
patrick = require 'patrick'
|
||||
telepath = require 'telepath'
|
||||
|
||||
{createPeer, connectDocument} = require './session-utils'
|
||||
sessionUtils = require './session-utils'
|
||||
|
||||
module.exports =
|
||||
class HostSession
|
||||
@@ -19,12 +19,11 @@ class HostSession
|
||||
start: ->
|
||||
return if @peer?
|
||||
|
||||
servers = {iceServers: [{url: "stun:54.218.196.152:3478"}, {url: "turn:ninefingers@54.218.196.152:3478", credential:"youhavetoberealistic"}]}
|
||||
mediaConnection = null
|
||||
|
||||
constraints = {video: true, audio: true}
|
||||
success = (stream) =>
|
||||
mediaConnection = new webkitRTCPeerConnection(servers)
|
||||
mediaConnection = new webkitRTCPeerConnection(sessionUtils.getIceServers())
|
||||
mediaConnection.onicecandidate = (event) =>
|
||||
return unless event.candidate?
|
||||
console.log "Set Host Candidate", event.candidate
|
||||
@@ -37,7 +36,7 @@ class HostSession
|
||||
mediaConnection.addStream(stream)
|
||||
navigator.webkitGetUserMedia constraints, success, console.error
|
||||
|
||||
@peer = createPeer()
|
||||
@peer = sessionUtils.createPeer()
|
||||
@doc = site.createDocument({})
|
||||
@doc.set('windowState', atom.windowState)
|
||||
patrick.snapshot project.getPath(), (error, repoSnapshot) =>
|
||||
@@ -96,7 +95,7 @@ class HostSession
|
||||
connection.on 'open', =>
|
||||
console.log 'sending document'
|
||||
connection.send({repoSnapshot, doc: @doc.serialize()})
|
||||
connectDocument(@doc, connection)
|
||||
sessionUtils.connectDocument(@doc, connection)
|
||||
|
||||
connection.on 'close', =>
|
||||
console.log 'sharing session stopped'
|
||||
|
||||
@@ -21,11 +21,15 @@ module.exports =
|
||||
|
||||
getSessionUrl: (sessionId) -> "atom://session/#{sessionId}"
|
||||
|
||||
getIceServers: ->
|
||||
stunServer = {url: "stun:54.218.196.152:3478"}
|
||||
turnServer = {url: "turn:ninefingers@54.218.196.152:3478", credential:"youhavetoberealistic"}
|
||||
iceServers: [stunServer, turnServer]
|
||||
|
||||
createPeer: ->
|
||||
id = Guid.create().toString()
|
||||
key = '0njqmaln320dlsor'
|
||||
# config = {iceServers: [{url: "turn:ninefingers@54.218.196.152:3478", credential:"youhavetoberealistic"}]}
|
||||
config = {iceServers: [{url: "stun:54.218.196.152:3478"}, {url: "turn:ninefingers@54.218.196.152:3478", credential:"youhavetoberealistic"}]}
|
||||
config = @getIceServers()
|
||||
new Peer(id, {key, config})
|
||||
|
||||
connectDocument: (doc, connection) ->
|
||||
|
||||
Reference in New Issue
Block a user