How to use the @firebase/webchannel-wrapper.WebChannel.EventType function in @firebase/webchannel-wrapper

To help you get started, we’ve selected a few @firebase/webchannel-wrapper 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 firebase / firebase-js-sdk / packages / firestore / src / platform_browser / webchannel_connection.ts View on Github external
fn: (param?: T) => void
    ): void => {
      // TODO(dimond): closure typing seems broken because WebChannel does
      // not implement goog.events.Listenable
      channel.listen(type, (param: unknown) => {
        try {
          fn(param as T);
        } catch (e) {
          setTimeout(() => {
            throw e;
          }, 0);
        }
      });
    };

    unguardedEventListen(WebChannel.EventType.OPEN, () => {
      if (!closed) {
        log.debug(LOG_TAG, 'WebChannel transport opened.');
      }
    });

    unguardedEventListen(WebChannel.EventType.CLOSE, () => {
      if (!closed) {
        closed = true;
        log.debug(LOG_TAG, 'WebChannel transport closed');
        streamBridge.callOnClose();
      }
    });

    unguardedEventListen(WebChannel.EventType.ERROR, err => {
      if (!closed) {
        closed = true;
github firebase / firebase-js-sdk / packages / firestore / src / platform_browser / webchannel_connection.ts View on Github external
Code.UNAVAILABLE,
            'The operation could not be completed'
          )
        );
      }
    });

    // WebChannel delivers message events as array. If batching is not enabled
    // (it's off by default) each message will be delivered alone, resulting in
    // a single element array.
    interface WebChannelResponse {
      data: Resp[];
    }

    unguardedEventListen(
      WebChannel.EventType.MESSAGE,
      msg => {
        if (!closed) {
          const msgData = msg!.data[0];
          assert(!!msgData, 'Got a webchannel message without data.');
          // TODO(b/35143891): There is a bug in One Platform that caused errors
          // (and only errors) to be wrapped in an extra array. To be forward
          // compatible with the bug we need to check either condition. The latter
          // can be removed once the fix has been rolled out.
          // Use any because msgData.error is not typed.
          const msgDataOrError: WebChannelError | object = msgData;
          const error =
            msgDataOrError.error ||
            (msgDataOrError as WebChannelError[])[0]?.error;
          if (error) {
            log.debug(LOG_TAG, 'WebChannel received error:', error);
            // error.status will be a string like 'OK' or 'NOT_FOUND'.

@firebase/webchannel-wrapper

A wrapper of the webchannel packages from closure-library for use outside of a closure compiled application

Apache-2.0
Latest version published 18 days ago

Package Health Score

95 / 100
Full package analysis

Similar packages