addEventListener('load', function () {
  if(reqUri = getRequestURIFromString(location.href))
    readWSStream(reqUri, appendToBody)
  else
    appendToBody('No URL given <br>')
})

function readWSStream (requestURI, callback) {
  var conn = new WebSocket('ws://' + requestURI, 'echo-protocol')
  conn.onmessage = callerWithKey(callback, 'data')
}

function callerWithKey(someFunct, key) {
  return function (someObject) {
    someFunct (someObject[key])
  }
}

function appendToBody (someString) {
  return document.body.innerHTML += someString
}

function getRequestURIFromString (someString) {
  var uri = someString.split('#')
  return uri.length > 1 ? uri[1] : false
}

addEventListener('load', function () {
  if(reqParams = getRequestParamsFromString(location.href)) {
    readWSStream(reqParams[0], reqParams[1], appendToBody)
  } else {
    appendToBody('No URL given <br>')
  }
})

function readWSStream (requestURI, socketProto, callback) {
  var conn = new WebSocket(socketProto + '://' + requestURI, 'echo-protocol')
  conn.onmessage = callerWithKey(callback, 'data')
  conn.onerror = errorHandler
}

function callerWithKey(someFunct, key) {
  return function (someObject) {
    someFunct (someObject[key])
  }
}

function errorHandler (error) {
  appendToBody(error)
  console.log(error)
}

function appendToBody (someString) {
  return document.body.innerHTML += someString
}

function getRequestParamsFromString (someString) {
  var params = someString.split('#')
  return params.length > 1 ? [params[1], params[2]] : false
}

Add a second param for the protocol
Add a second param for the protocol
