How to use @ssv/signalr-client - 5 common examples

To help you get started, we’ve selected a few @ssv/signalr-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 sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / data / live.tsx View on Github external
// directly on the hub, which is managed with normal classes
      // instead of waiting for react-render lifecycles
      if (hub['hubConnection'].state !== ConnectionStatus.connected) {
        /* private field. YOLO */
        return;
      }

      try {
        hub.send('UnsubscribeFrom', subscribeTo);
      } catch (e) {
        console.log(
          'tried to unsubscribe: ',
          subscribeTo,
          isConnected,
          hub['hubConnection'].state,
          ConnectionStatus.connected
        );

        throw e;
      }
    };
  }, [subscribeTo, isConnected, isSubscribed, hub]);
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / data / live.tsx View on Github external
return () => {
      if (subscription.current) {
        subscription.current.unsubscribe();
      }

      if (!isConnected) return;
      // NOTE: isConnected from the context provider doesn't
      // propagate its update quick enough for this particular value
      // of this particular copy of the reference to be correct /
      // the most up to date. So we need to access the state
      // directly on the hub, which is managed with normal classes
      // instead of waiting for react-render lifecycles
      if (hub['hubConnection'].state !== ConnectionStatus.connected) {
        /* private field. YOLO */
        return;
      }

      try {
        hub.send('UnsubscribeFrom', subscribeTo);
      } catch (e) {
        console.log(
          'tried to unsubscribe: ',
          subscribeTo,
          isConnected,
          hub['hubConnection'].state,
          ConnectionStatus.connected
        );

        throw e;
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / data / live.tsx View on Github external
interface ILiveDataContext {
  dataStore: Store;
  socket?: DataSocketClient;
  pushData: (transforms: TransformOrOperations) => Observable<{}>;
  subscriptions: string[];
  isConnected: boolean;
  connectionState: ConnectionStatus;
}

const DataContext = React.createContext({
  dataStore: undefined,
  socket: undefined,
  pushData: undefined,
  subscriptions: [],
  isConnected: false,
  connectionState: ConnectionStatus.disconnected,
});

export function useLiveData(subscribeTo?: string) {
  const dataCtx = useContext(DataContext);
  const { socket, isConnected } = dataCtx;

  const hub: HubConnection = isTesting ? undefined : socket.hub;

  const { isSubscribed } = useSubscribeToResource(hub, subscribeTo, isConnected);

  const pushData = useCallback(
    (transforms: TransformOrOperations) => {
      if (isTesting) {
        console.debug('testing early return: figure out how to test websocket communication');
        return;
      }
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / sockets / data-socket.tsx View on Github external
(state) => {
          if (this.isDestroying) return;

          this.setState({
            isConnected: state.status === ConnectionStatus.connected,
            connectionState: state,
          });
        }
      );
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / sockets / data-socket.tsx View on Github external
constructor(props: LiveDataProps) {
    super(props);

    this.hubFactory = new HubConnectionFactory();

    this.startSocket();
  }

@ssv/signalr-client

SignalR client library built on top of @microsoft/signalr. This gives you more features and easier to use.

MIT
Latest version published 8 months ago

Package Health Score

59 / 100
Full package analysis