Stop resetting after every pair closes

This commit is contained in:
Arlo Breault 2019-06-29 18:09:12 -04:00 committed by Cecylia Bocovich
parent 58d07788c7
commit b1116a1c35
4 changed files with 11 additions and 25 deletions

View file

@ -54,7 +54,7 @@ window.onbeforeunload = ->
null
window.onunload = ->
pair.close() for pair in snowflake.proxyPairs
snowflake.disable()
null
window.onload = init

View file

@ -45,7 +45,7 @@ window.onbeforeunload = ->
null
window.onunload = ->
pair.close() for pair in snowflake.proxyPairs
snowflake.disable()
null
window.onload = init

View file

@ -78,8 +78,6 @@ class ProxyPair
snowflake.state = Snowflake.MODE.INIT
@flush()
@close()
# TODO: Change this for multiplexing.
snowflake.reset()
channel.onerror = -> log 'Data channel error!'
channel.binaryType = "arraybuffer"
channel.onmessage = @onClientToRelayMessage
@ -149,6 +147,7 @@ class ProxyPair
@client.close() if @webrtcIsReady()
@relay.close() if @relayIsReady()
relay = null
@onCleanup()
# Send as much data in both directions as the rate limit currently allows.
flush: =>

View file

@ -51,8 +51,6 @@ class Snowflake
# process. |pollBroker| automatically arranges signalling.
beginWebRTC: ->
@state = Snowflake.MODE.WEBRTC_CONNECTING
for i in [1..@config.connectionsPerClient]
@makeProxyPair @relayAddr
log 'ProxyPair Slots: ' + @proxyPairs.length
log 'Snowflake IDs: ' + (@proxyPairs.map (p) -> p.id).join ' | '
@pollBroker()
@ -82,6 +80,8 @@ class Snowflake
# Returns the first ProxyPair that's available to connect.
nextAvailableProxyPair: ->
if @proxyPairs.length < @config.connectionsPerClient
return @makeProxyPair @relayAddr
return @proxyPairs.find (pp, i, arr) -> return !pp.active
# Receive an SDP offer from some client assigned by the Broker,
@ -110,27 +110,14 @@ class Snowflake
@proxyPairs.push pair
pair.onCleanup = (event) =>
# Delete from the list of active proxy pairs.
@proxyPairs.splice(@proxyPairs.indexOf(pair), 1)
@pollBroker()
ind = @proxyPairs.indexOf(pair)
if ind > -1 then @proxyPairs.splice(ind, 1)
pair.begin()
return pair
# Stop all proxypairs.
cease: ->
while @proxyPairs.length > 0
@proxyPairs.pop().close()
clearInterval(@pollInterval)
disable: ->
log 'Disabling Snowflake.'
@cease()
die: ->
log 'Snowflake died.'
@cease()
# Close all existing ProxyPairs and begin finding new clients from scratch.
reset: ->
@cease()
log 'Snowflake resetting...'
@retries = 0
@beginWebRTC()
clearInterval(@pollInterval)
while @proxyPairs.length > 0
@proxyPairs.pop().close()