connect.js 491 B

1234567891011121314151617
  1. (function () {
  2. // connect to server
  3. var socket = new WebSocket("ws://" + window.location.host);
  4. socket.onclose = function () { $.state.server.set(false) };
  5. socket.onopen = function () { $.state.server.set(true) };
  6. $.state.connection.set(require('q-connection')(socket));
  7. // subscribe to server-side persistence store
  8. var update = $.emit("update");
  9. require('q').done($.api("subscribe", update), update,
  10. $.error("could not subscribe to server"));
  11. return socket;
  12. })