How to use the websocket.js function in websocket

To help you get started, we’ve selected a few websocket 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 webkom / lego-webapp / app / utils / websockets.ts View on Github external
const makeSocket = jwt => {
      if (socket || !jwt) return;

      const qs = createQueryString({ jwt });
      socket = new WebSocketClient(`${config.wsServerUrl}/${qs}`);

      socket.onmessage = event => {
        const { type, payload, meta: socketMeta } = JSON.parse(event.data);

        const meta = {
          ...socketMeta,
          currentUser: selectCurrentUser(store.getState())
        };

        if (
          type === Event.SOCKET_REGISTRATION.SUCCESS &&
          payload.user.id === meta.currentUser.id
        ) {
          store.dispatch(isUserFollowing(meta.eventId));
        }
github webkom / lego-webapp / app / utils / websockets.js View on Github external
const makeSocket = jwt => {
      if (socket || !jwt) return;

      const qs = createQueryString({ jwt });
      socket = new WebSocketClient(`${config.wsServerUrl}/${qs}`);

      socket.onmessage = event => {
        const { type, payload, meta: socketMeta } = JSON.parse(event.data);

        const meta = {
          ...socketMeta,
          currentUser: selectCurrentUser(store.getState())
        };

        store.dispatch({ type, payload, meta });
        const message = meta.successMessage || meta.errorMessage;
        if (message) {
          store.dispatch(addToast({ message }));
        }
      };