Commit e2955562 authored by Arlo Breault's avatar Arlo Breault
Browse files

Standalone snowflake

 * Start of #30
parent c8c5d56b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13,3 +13,4 @@ proxy/build
proxy/node_modules
proxy/spec/support
ignore/
npm-debug.log
+2 −1
Original line number Diff line number Diff line
@@ -35,7 +35,8 @@ task 'test', 'snowflake unit tests', ->
  # Simply concat all the files because we're not using node exports.
  jasmineFiles = FILES_ALL
  outFile = 'test/bundle.spec.coffee'
  exec 'cat ' + jasmineFiles.join(' ') +  ' | cat > ' + outFile
  exec 'echo "TESTING = true" > ' + outFile
  exec 'cat ' + jasmineFiles.join(' ') +  ' | cat >> ' + outFile
  execSync 'coffee -cb ' + outFile
  spawn 'jasmine', ['test/bundle.spec.js'], {
    stdio: 'inherit'
+14 −4
Original line number Diff line number Diff line
@@ -11,14 +11,24 @@
    "lint": "cake lint",
    "build": "cake build",
    "clean": "cake clean",
    "modern": "modernizr -c modernizr-config.json -d static/"
    "modern": "modernizr -c modernizr-config.json -d static/",
    "prepublish": "npm run build",
    "start": "node build/snowflake.js"
  },
  "bin": {
    "snowflake": "build/snowflake.js"
  },
  "author": "Serene Han",
  "license": "BSD-3-Clause",
  "devDependencies": {
    "coffee-script": "^1.10.0",
    "coffeelint": "^1.15.0",
    "jasmine": "^2.4.1",
    "coffeelint": "^1.16.0",
    "jasmine": "^2.5.2",
    "modernizr": "^3.3.1"
  },
  "dependencies": {
    "coffee-script": "^1.12.2",
    "wrtc": "^0.0.61",
    "ws": "^1.1.1",
    "xmlhttprequest": "^1.8.0"
  }
}
+6 −6
Original line number Diff line number Diff line
@@ -69,14 +69,14 @@ class ProxyPair
    channel.onopen = =>
      log 'WebRTC DataChannel opened!'
      snowflake.state = MODE.WEBRTC_READY
      snowflake.ui.setActive true
      snowflake.ui?.setActive true
      # This is the point when the WebRTC datachannel is done, so the next step
      # is to establish websocket to the server.
      @connectRelay()
    channel.onclose = =>
      log 'WebRTC DataChannel closed.'
      snowflake.ui.setStatus 'disconnected by webrtc.'
      snowflake.ui.setActive false
      snowflake.ui?.setStatus 'disconnected by webrtc.'
      snowflake.ui?.setActive false
      snowflake.state = MODE.INIT
      @flush()
      @close()
@@ -95,11 +95,11 @@ class ProxyPair
        clearTimeout @timer
        @timer = 0
      log @relay.label + ' connected!'
      snowflake.ui.setStatus 'connected'
      snowflake.ui?.setStatus 'connected'
    @relay.onclose = =>
      log @relay.label + ' closed.'
      snowflake.ui.setStatus 'disconnected.'
      snowflake.ui.setActive false
      snowflake.ui?.setStatus 'disconnected.'
      snowflake.ui?.setActive false
      snowflake.state = MODE.INIT
      @flush()
      @close()
+20 −3
Original line number Diff line number Diff line
###
WebrTC shims for multiple browsers.
WebRTC shims for multiple browsers.
###

if typeof module isnt 'undefined' and module.exports
if module?.exports
  window = {}
  location = ''

  if not TESTING? or not TESTING
    webrtc = require 'wrtc'

    PeerConnection = webrtc.RTCPeerConnection
    IceCandidate = webrtc.RTCIceCandidate
    SessionDescription = webrtc.RTCSessionDescription

    WebSocket = require 'ws'
    { XMLHttpRequest } = require 'xmlhttprequest'

    process.nextTick () -> init true

else
  window = this
  location = window.location.search.substr(1)

  prop = Modernizr.prefixed 'RTCPeerConnection', window, false
  if not prop
    console.log 'webrtc feature not detected. shutting down'
@@ -18,4 +34,5 @@ else
  SessionDescription = window.RTCSessionDescription ||
    window.mozRTCSessionDescription

location = if window.location then window.location.search.substr(1) else ""
  WebSocket = window.WebSocket
  XMLHttpRequest = window.XMLHttpRequest
Loading