types#WebsocketMessageNames TypeScript Examples

The following examples show how to use types#WebsocketMessageNames. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: chainEventsNs.ts    From commonwealth with GNU General Public License v3.0 6 votes vote down vote up
public async init() {
    this.ceNs = io(`/${WebsocketNamespaces.ChainEvents}`, {
      transports: ['websocket'],
    });
    this.ceNs.on('connect', this.onConnect.bind(this));
    this.ceNs.on('disconnect', this.onDisconnect.bind(this));
    this.ceNs.on(
        WebsocketMessageNames.ChainEventNotification,
        this.onChainEvent.bind(this)
    );
  }
Example #2
Source File: chainEventsNs.ts    From commonwealth with GNU General Public License v3.0 6 votes vote down vote up
public addChainEventSubscriptions(subs: NotificationSubscription[]) {
    if (this._isConnected) {
      const eventTypes = subs.map((x) => x.ChainEventType?.id).filter((x) => !!x);
      console.log('Adding Websocket subscriptions for:', eventTypes);
      this.ceNs.emit(WebsocketMessageNames.NewSubscriptions, eventTypes);
    } else {
      console.log('ChainEventsNamespace is not connected');
    }
  }
Example #3
Source File: chainEventsNs.ts    From commonwealth with GNU General Public License v3.0 6 votes vote down vote up
public deleteChainEventSubscriptions(subs: NotificationSubscription[]) {
    if (this._isConnected) {
      const eventTypes = subs.map((x) => x.ChainEventType?.id).filter((x) => !!x);
      console.log('Deleting Websocket subscriptions for:', eventTypes);
      this.ceNs.emit(
        WebsocketMessageNames.DeleteSubscriptions,
        subs.map((x) => x.ChainEventType?.id)
      );
    } else {
      console.log('ChainEventsNamespace is not connected');
    }
  }
Example #4
Source File: chat_window.tsx    From commonwealth with GNU General Public License v3.0 6 votes vote down vote up
oninit(vnode) {
    this.shouldScroll = true;
    this.shouldScrollToHighlight = Boolean(m.route.param("message"))
    this.scrollToBottom = () => {
      const scroller = $((vnode as any).dom).find('.chat-messages')[0];
      scroller.scrollTop = scroller.scrollHeight - scroller.clientHeight + 20;
    };
    this.onIncomingMessage = (msg) => {
      console.log('Message received');
      const { chat_channel_id } = msg;
      if (chat_channel_id === vnode.attrs.channel_id) {
        this.shouldScroll = false;
      }
      m.redraw();
    };

    app.socket.chatNs.addListener(
      WebsocketMessageNames.ChatMessage,
      this.onIncomingMessage.bind(vnode)
    );
  }
Example #5
Source File: chatNs.ts    From commonwealth with GNU General Public License v3.0 5 votes vote down vote up
public sendMessage(message: Record<string, any>, channel: IChannel) {
        if (this.isConnected) {
            this.chatNs.emit(WebsocketMessageNames.ChatMessage, {
                socket_room: ChatNamespace.channelToRoomId(channel),
                ...message
            })
        }
    }
Example #6
Source File: chatNs.ts    From commonwealth with GNU General Public License v3.0 5 votes vote down vote up
public connectToChannels(channel_ids: string[]) {
        if (this.isConnected) this.chatNs.emit(WebsocketMessageNames.JoinChatChannel, channel_ids)
    }
Example #7
Source File: chatNs.ts    From commonwealth with GNU General Public License v3.0 5 votes vote down vote up
public disconnectFromChannels(channel_ids: string[]) {
        if (this.isConnected) this.chatNs.emit(WebsocketMessageNames.LeaveChatChannel, channel_ids)
    }
Example #8
Source File: chatNs.ts    From commonwealth with GNU General Public License v3.0 5 votes vote down vote up
public async initialize() {
        console.log("Initializing chat state")
        this.addListener(WebsocketMessageNames.ChatMessage, this.onMessage.bind(this))
        this.connectToChannels(Object.values(this.channels).map(ChatNamespace.channelToRoomId))
        this._initialized = true;
    }
Example #9
Source File: chatNs.ts    From commonwealth with GNU General Public License v3.0 5 votes vote down vote up
public async deinit() {
        this._initialized = false;
        this.removeListener(WebsocketMessageNames.ChatMessage, this.onMessage.bind(this))
        this.disconnectFromChannels(Object.values(this.channels).map(ChatNamespace.channelToRoomId))
        this.channels = {}
    }
Example #10
Source File: chat_section.tsx    From commonwealth with GNU General Public License v3.0 5 votes vote down vote up
async oninit(vnode) {
    this.loaded = false;
    this.chain = app.activeChainId();
    this.activeChannel = null;
    app.socket.chatNs.activeChannel = null;

    this.channelToToggleTree = (channels: IChannel[]) => {
      const toggleTree = {};
      channels.forEach((k) => {
        toggleTree[k.name] = { toggledState: false };
      });
      return toggleTree;
    };

    this.categoryToToggleTree = (
      categories: string[],
      defaultState: boolean
    ) => {
      const toggleTree = {};
      categories.forEach((category) => {
        const channelToggleTree = this.channelToToggleTree(
          this.channels[category]
        );
        toggleTree[category] = {
          toggledState: defaultState,
          children: channelToggleTree,
        };
      });
      return toggleTree;
    };

    this.adminModals = {
      CreateCategory: false,
      CreateChannel: false,
      RenameCategory: false,
      DeleteCategory: false,
      RenameChannel: false,
      DeleteChannel: false,
    };

    this.adminCategory = '';
    this.adminChannel = {};

    this.channels = {};
    Object.values(app.socket.chatNs.channels).forEach((c) => {
      const { ChatMessages, ...metadata } = c;
      this.channels[metadata.category]
        ? this.channels[metadata.category].push(metadata)
        : (this.channels[metadata.category] = [metadata]);
    });

    this.onIncomingMessage = (msg) => {
      m.redraw.sync();
    };

    app.socket.chatNs.addListener(
      WebsocketMessageNames.ChatMessage,
      this.onIncomingMessage.bind(vnode)
    );
    this.loaded = true;

    this.menuToggleTree = {
      // Used to track admin menu render status for hover
      toggledState: false,
      children: this.categoryToToggleTree(Object.keys(this.channels), false),
    };
  }
Example #11
Source File: chat_section.tsx    From commonwealth with GNU General Public License v3.0 5 votes vote down vote up
onremove() {
    if (app.socket) {
      app.socket.chatNs.removeListener(
        WebsocketMessageNames.ChatMessage,
        this.onIncomingMessage
      );
    }
  }
Example #12
Source File: chat_window.tsx    From commonwealth with GNU General Public License v3.0 5 votes vote down vote up
onremove() {
    app.socket.chatNs.removeListener(
      WebsocketMessageNames.ChatMessage,
      this.onIncomingMessage
    );
  }