Remove copy/paste signalling

This commit is contained in:
Arlo Breault 2019-04-30 22:05:40 -04:00
parent 79c84509fc
commit 622005c79e
13 changed files with 18 additions and 283 deletions

View file

@ -33,8 +33,3 @@ With no parameters,
snowflake uses the default relay `snowflake.bamsoftware.com:443` and
uses automatic signaling with the default broker at
`https://snowflake-broker.bamsoftware.com/`.
Here are optional parameters to include in the query string.
```
manual - enables copy-paste signalling mode.
```

View file

@ -40,15 +40,11 @@ class ProxyPair
] }
@pc.onicecandidate = (evt) =>
# Browser sends a null candidate once the ICE gathering completes.
# In this case, it makes sense to send one copy-paste blob.
if null == evt.candidate
# TODO: Use a promise.all to tell Snowflake about all offers at once,
# once multiple proxypairs are supported.
dbg 'Finished gathering ICE candidates.'
if COPY_PASTE_ENABLED
Signalling.send @pc.localDescription
else
snowflake.broker.sendAnswer @id, @pc.localDescription
snowflake.broker.sendAnswer @id, @pc.localDescription
# OnDataChannel triggered remotely from the client when connection succeeds.
@pc.ondatachannel = (dc) =>
channel = dc.channel
@ -193,4 +189,3 @@ class ProxyPair
webrtcIsReady: -> null != @client && 'open' == @client.readyState
relayIsReady: -> (null != @relay) && (WebSocket.OPEN == @relay.readyState)
isClosed: (ws) -> undefined == ws || WebSocket.CLOSED == ws.readyState

View file

@ -18,13 +18,11 @@ RELAY =
# Original non-wss relay:
# host: '192.81.135.242'
# port: 9902
COPY_PASTE_ENABLED = false
COOKIE_NAME = "snowflake-allow"
silenceNotifications = false
query = Query.parse(location)
DEBUG = Params.getBool(query, 'debug', false)
COPY_PASTE_ENABLED = Params.getBool(query, 'manual', false)
# Bytes per second. Set to undefined to disable limit.
DEFAULT_RATE_LIMIT = DEFAULT_RATE_LIMIT || undefined
@ -78,17 +76,14 @@ class Snowflake
setRelayAddr: (relayAddr) ->
@relayAddr = relayAddr
log 'Using ' + relayAddr.host + ':' + relayAddr.port + ' as Relay.'
log 'Input offer from the snowflake client:' if COPY_PASTE_ENABLED
return true
# Initialize WebRTC PeerConnection, which requires beginning the signalling
# process. If in copy paste mode, the user will need to copy and paste the SDP
# blobs. Otherwise, |pollBroker| automatically arranges signalling.
# process. |pollBroker| automatically arranges signalling.
beginWebRTC: ->
@state = MODE.WEBRTC_CONNECTING
for i in [1..CONNECTIONS_PER_CLIENT]
@makeProxyPair @relayAddr
return if COPY_PASTE_ENABLED
log 'ProxyPair Slots: ' + @proxyPairs.length
log 'Snowflake IDs: ' + (@proxyPairs.map (p) -> p.id).join ' | '
@pollBroker()
@ -182,31 +177,6 @@ class Snowflake
snowflake = null
# Signalling channel - just tells user to copy paste to the peer.
# When copy-paste mode is not enabled, this is handled automatically by Broker.
Signalling =
send: (msg) ->
log '---- Please copy the below to peer ----\n'
log JSON.stringify msg
log '\n'
receive: (msg) ->
recv = ''
try
recv = JSON.parse msg
catch e
log 'Invalid JSON.'
return
desc = recv['sdp']
if !desc
log 'Invalid SDP.'
return false
pair = snowflake.nextAvailableProxyPair()
if !pair
log 'At client capacity.'
return false
snowflake.receiveOffer pair, msg
# Log to both console and UI if applicable.
# Requires that the snowflake and UI objects are hooked up in order to
# log to console.
@ -246,8 +216,7 @@ init = (isNode) ->
return
# Otherwise, begin setting up WebRTC and acting as a proxy.
log 'Copy-Paste mode detected.' if COPY_PASTE_ENABLED
dbg 'Contacting Broker at ' + broker.url if not COPY_PASTE_ENABLED
dbg 'Contacting Broker at ' + broker.url
snowflake.setRelayAddr RELAY
snowflake.beginWebRTC()

View file

@ -10,16 +10,12 @@ describe 'UI', ->
it 'activates debug mode when badge does not exist', ->
spyOn(document, 'getElementById').and.callFake (id) ->
return null if 'badge' == id
return {
focus: ->
}
return {}
u = new UI()
expect(u.debug).toBe true
expect(document.getElementById.calls.count()).toEqual 5
expect(document.getElementById.calls.count()).toEqual 3
expect(u.$status).not.toBeNull()
expect(u.$msglog).not.toBeNull()
expect(u.$send).not.toBeNull()
expect(u.$input).not.toBeNull()
it 'is not debug mode when badge exists', ->
spyOn(document, 'getElementById').and.callFake (id) ->
@ -31,8 +27,6 @@ describe 'UI', ->
expect(document.getElementById.calls.count()).toEqual 1
expect(u.$status).toBeNull()
expect(u.$msglog).toBeNull()
expect(u.$send).toBeNull()
expect(u.$input).toBeNull()
it 'sets status message only when in debug mode', ->
u = new UI()

View file

@ -40,30 +40,6 @@
margin-bottom: 1em;
padding: 8px;
}
.inputarea {
position: relative;
width: 100%;
height: 3em;
display: block;
}
#input {
display: inline-block;
position: absolute; left: 0;
width: 89%; height: 100%;
padding: 8px 30px;
font-size: 80%;
color: #fff;
background-color: rgba(0,0,0,0.9);
border: 1px solid #999;
}
#send {
display: inline-block; position: absolute;
right: 0; top: 0; height: 100%; width: 10%;
background-color: #202; color: #f8f;
font-variant: small-caps; font-size: 100%;
border: none; /* box-shadow: 0 2px 5px #000; */
}
#send:hover { background-color: #636; }
#status {
background-color: rgba(0,0,0,0.9); color: #999;
margin: 8px 0; padding: 8px 1em; cursor: default;
@ -79,10 +55,6 @@
</div>
<textarea id="msglog" readonly>
</textarea>
<div class="inputarea">
<input type="text" id="input">
<input type="submit" id="send" value="send">
</div>
</div>
</body>

View file

@ -7,8 +7,6 @@ class UI
# DOM elements references.
$msglog: null
$send: null
$input: null
$status: null
constructor: ->
@ -21,14 +19,6 @@ class UI
@$msglog = document.getElementById('msglog')
@$msglog.value = ''
@$send = document.getElementById('send')
@$send.onclick = @acceptInput
@$input = document.getElementById('input')
@$input.focus()
@$input.onkeydown = (e) =>
@$send.onclick() if 13 == e.keyCode # enter
# Status bar
setStatus: (msg) =>
return if !@debug
@ -40,21 +30,6 @@ class UI
else
@$badge.className = if connected then 'active' else ''
# Local input from keyboard into message window.
acceptInput: =>
msg = @$input.value
if !COPY_PASTE_ENABLED
@log 'No input expected - Copy Paste Signalling disabled.'
else switch snowflake.state
when MODE.WEBRTC_CONNECTING
Signalling.receive msg
when MODE.WEBRTC_READY
@log 'No input expected - WebRTC connected.'
else
@log 'ERROR: ' + msg
@$input.value = ''
@$input.focus()
log: (msg) =>
return if !@debug
# Scroll to latest