websockets.js 1.0 KB

12345678910111213141516171819202122232425262728
  1. (function () {
  2. 'use strict';
  3. /*global ab: false, RealtimeUpdate: false */
  4. window.wsRealtime = {
  5. init: function (server, httpPort, path, httpsPort, timeline) {
  6. var isHTTPS = (document.location.protocol === 'https:'),
  7. protocol = isHTTPS ? 'wss' : 'ws',
  8. port = isHTTPS ? httpsPort : httpPort,
  9. conn = new ab.Session(
  10. protocol + '://' + server + ':' + port + path,
  11. function () { // Connect
  12. conn.subscribe(timeline, function (undefined, data) {
  13. RealtimeUpdate.receive(data);
  14. });
  15. },
  16. function () { // Connection closed
  17. console.warn('WebSocket connection closed');
  18. },
  19. { // Additional parameters, we're ignoring the WAMP sub-protocol for older browsers
  20. 'skipSubprotocolCheck': true
  21. }
  22. );
  23. }
  24. };
  25. }());