How to use sockjs-client - 10 common examples

To help you get started, we’ve selected a few sockjs-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github knalli / angular-vertxbus / test / unit / binding / vertxEventBusService.spec.js View on Github external
setTimeout(function () {
          var funcOne = new FunctionHolder();
          var funcTwo = new FunctionHolder();
          vertxEventBusService.addListener('abc', funcOne.handler);
          vertxEventBusService.addListener('xyz', funcTwo.handler);
          SockJS.currentMockInstance.onmessage({
            data : JSON.stringify({
              address : 'abc',
              body : 'abc',
              replyAddress : undefined
            })
          });
          expect(singleCallbackValue).to.be('abc');
          SockJS.currentMockInstance.onmessage({
            data : JSON.stringify({
              address : 'xyz',
              body : 'xyz',
              replyAddress : undefined
            })
          });
          expect(singleCallbackValue).to.be('xyz');
          // remove handlers
          vertxEventBusService.removeListener('abc', funcOne.handler);
          vertxEventBusService.removeListener('xyz', funcTwo.handler);
          done();
        }, 200);
      });
github knalli / angular-vertxbus / test / unit / binding / vertxEventBusService.spec.js View on Github external
setTimeout(function () {
          var abcHandler = function (message) {
            abcCalled = message;
          }, xyzHandler = function (message) {
            xyzCalled = message;
          };

          var abcFunct = vertxEventBusService.addListener('abc', abcHandler);
          var xyzFunct = vertxEventBusService.addListener('xyz', xyzHandler);
          // remove again!
          abcFunct();
          xyzFunct();
          SockJS.currentMockInstance.onmessage({
            data : JSON.stringify({
              address : 'xyz',
              body : {
                data : '1x'
              },
              replyAddress : undefined
            })
          });
          expect(abcCalled).to.be(undefined);
          expect(xyzCalled).to.be(undefined);
          done();
        }, 200);
      });
github knalli / angular-vertxbus / test / unit / binding / vertxEventBus.defaultHeaders.spec.js View on Github external
beforeEach(angular.mock.inject(function (_vertxEventBus_, _$timeout_, _$rootScope_, _$log_) {
      vertxEventBus = _vertxEventBus_;
      $timeout = _$timeout_;
      $rootScope = _$rootScope_;
      $log = _$log_;
      SockJS.currentMockInstance.$log = $log;

      // Mock bus is opened (said to be)
      _vertxEventBus_.readyState = function () {
        return _vertxEventBus_.EventBus.OPEN;
      };
    }));
github knalli / angular-vertxbus / test / unit / binding / vertxEventBus.defaultHeaders.spec.js View on Github external
beforeEach(angular.mock.inject(function (_vertxEventBus_, _$timeout_, _$rootScope_, _$log_) {
      vertxEventBus = _vertxEventBus_;
      $timeout = _$timeout_;
      $rootScope = _$rootScope_;
      $log = _$log_;
      SockJS.currentMockInstance.$log = $log;

      // Mock bus is opened (said to be)
      vertxEventBus.readyState = function () {
        return vertxEventBus.EventBus.OPEN;
      };
      vertxEventBus.applyDefaultHeaders({
        x : 1,
        y : 2
      });
    }));
github knalli / angular-vertxbus / test / unit / binding / vertxEventBus.spec.js View on Github external
setTimeout(function () {
          $rootScope.$digest(); // for $q
          $log.debug('check..');
          expect(SockJS.currentMockInstance.url).to.be('http://localhost:1234/eventbus1');
          expect(onopenCount).to.be(1);
          expect(oncloseCount).to.be(0);
          expect(connectPromiseResult ).to.be(true);
          done();
        }, 1200);
      }, 200);
github cdapio / cdap / cdap-ui / app / cdap / services / socket / index.js View on Github external
init(attempt) {
    attempt = attempt || 1;
    clearTimeout(this.timeout);

    this.socket = new SockJS('/_sock');

    this.socket.onopen = async () => {
      if (!this.isFirstTime) {
        await fetchSessionToken();
        this.eventEmitter.emit('SOCKET_RECONNECT');
      }
      this.isFirstTime = false;

      // Buffering request while Socket is still starting up
      this.buffer.forEach((req) => {
        this._doSend(req);
      });
      this.buffer = [];
    };

    this.socket.onmessage = (event) => {
github pintowar / opta-invest / client / src / pages / portfolio / show.vue View on Github external
created () {
    this.portfolioId = Number(this.$route.params.id)

    const socket = new SockJS('/stomp')
    this.client = Stomp.over(socket)
    this.client.debug = null
    let self = this
    this.client.connect({}, frame => {
      console.log('Connected: ' + frame)
      self.client.subscribe('/topic/solution', message => {
        const data = JSON.parse(message.body)
        // console.log(data.status)
        if (data.id === this.portfolioId) {
          self.status = data.status
          self.portfolio = data.portfolio
        }
      })
    })

    axios.get(`/api/portfolio/${this.portfolioId}`).then(res => {
github researchstudio-sat / webofneeds / webofneeds / won-owner-webapp / src / main / webapp / app / messaging-agent.js View on Github external
const sendFirstInBuffer = function(newMsgBuffer) {
      if (newMsgBuffer && !newMsgBuffer.isEmpty()) {
        try {
          const firstEntry = newMsgBuffer.entries().next().value;
          if (firstEntry && ws.readyState === SockJS.OPEN) {
            //undefined if queue is empty
            if (firstEntry.length != 2) {
              console.error(
                "Could not send message, did not find a uri/message pair in the message buffer. The first Entry in the buffer is:",
                firstEntry
              );
              return;
            }
            const [eventUri, msg] = firstEntry;
            ws.send(JSON.stringify(msg));
            //console.log("messaging-agent.js: sent message: " + JSON.stringify(msg));

            // move message to next stat ("waitingForAnswer"). Also triggers this watch again as a result.
            redux.dispatch(
              actionCreators.messages__waitingForAnswer({ eventUri, msg })
            );
github amark / coalesce / coalesce.js View on Github external
a.list(web.opt.node.src).each(function(url){
						var toe = toes.create(url);
						web.node.cons[url] = toe;
						toe.on('error', function(e){ console.log('ut-oh', e) }); // need to add this before the connection event.
						toe.on('connection', function(){
							toe.writable = true;
							toe.mid = url;
							toe.write(a.text.ify(a.com.meta({
								what: {auth: web.opt.node.key, to: url}
								,where: {mid: web.opt.node.mid}
							})));
							state.con(toe);
						});
					});
				}
github amark / gun / node_modules / coalesce / coalesce.js View on Github external
a.list(web.opt.node.src).each(function(url){
						var toe = toes.create(url);
						web.node.cons[url] = toe;
						toe.on('error', function(e){ console.log('ut-oh', e) }); // need to add this before the connection event.
						toe.on('connection', function(){
							toe.writable = true;
							toe.mid = url;
							toe.write(a.text.ify(a.com.meta({
								what: {auth: web.opt.node.key, to: url}
								,where: {mid: web.opt.node.mid}
							})));
							state.con(toe);
						});
					});
				}

sockjs-client

SockJS-client is a browser JavaScript library that provides a WebSocket-like object.

MIT
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis