How to use rsocket-types - 10 common examples

To help you get started, we’ve selected a few rsocket-types 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 rsocket / rsocket-js / packages / rsocket-websocket-server / src / RSocketWebSocketServer.js View on Github external
constructor(socket: ws.Socket, encoders: ?Encoders<*>) {
    this._active = true;
    this._close = new Deferred();
    this._encoders = encoders;
    this._socket = socket;
    this._statusSubscribers = new Set();

    if (socket) {
      this._status = CONNECTION_STATUS.CONNECTED;
    } else {
      this._status = CONNECTION_STATUS.NOT_CONNECTED;
    }

    // If _receiver has been `subscribe()`-ed already
    let isSubscribed = false;
    this._receiver = new Flowable(subscriber => {
      invariant(
        !isSubscribed,
        'RSocketWebSocketServer: Multicast receive() is not supported. Be sure ' +
          'to receive/subscribe only once.',
      );
      isSubscribed = true;

      // Whether `request()` has been called.
      let initialized = false;
github rsocket / rsocket-js / packages / rsocket-tcp-client / src / RSocketTcpClient.js View on Github external
_close(error?: Error) {
    if (this._status.kind === 'CLOSED' || this._status.kind === 'ERROR') {
      // already closed
      return;
    }
    const status = error ? {error, kind: 'ERROR'} : CONNECTION_STATUS.CLOSED;
    this.setConnectionStatus(status);
    this._receivers.forEach(subscriber => {
      if (error) {
        subscriber.onError(error);
      } else {
        subscriber.onComplete();
      }
    });
    this._receivers.clear();
    this._senders.forEach(subscription => subscription.cancel());
    this._senders.clear();
    const socket = this._socket;
    if (socket) {
      socket.removeAllListeners();
      socket.end();
      this._socket = null;
github rsocket / rsocket-js / packages / rsocket-websocket-client / src / RSocketWebSocketClient.js View on Github external
_close(error?: Error) {
    if (this._status.kind === 'CLOSED' || this._status.kind === 'ERROR') {
      // already closed
      return;
    }
    const status = error ? {error, kind: 'ERROR'} : CONNECTION_STATUS.CLOSED;
    this._setConnectionStatus(status);
    this._receivers.forEach(subscriber => {
      if (error) {
        subscriber.onError(error);
      } else {
        subscriber.onComplete();
      }
    });
    this._receivers.clear();
    this._senders.forEach(subscription => subscription.cancel());
    this._senders.clear();
    const socket = this._socket;
    if (socket) {
      (socket.removeEventListener: $FlowIssue)('close', this._handleClosed);
      (socket.removeEventListener: $FlowIssue)('error', this._handleClosed);
      (socket.removeEventListener: $FlowIssue)('open', this._handleOpened);
github rsocket / rsocket-js / packages / rsocket-websocket-server / src / RSocketWebSocketServer.js View on Github external
constructor(socket: ws.Socket, encoders: ?Encoders<*>) {
    this._active = true;
    this._close = new Deferred();
    this._encoders = encoders;
    this._socket = socket;
    this._statusSubscribers = new Set();

    if (socket) {
      this._status = CONNECTION_STATUS.CONNECTED;
    } else {
      this._status = CONNECTION_STATUS.NOT_CONNECTED;
    }

    // If _receiver has been `subscribe()`-ed already
    let isSubscribed = false;
    this._receiver = new Flowable(subscriber => {
      invariant(
        !isSubscribed,
        'RSocketWebSocketServer: Multicast receive() is not supported. Be sure ' +
          'to receive/subscribe only once.',
      );
      isSubscribed = true;

      // Whether `request()` has been called.
      let initialized = false;
      const closeSocket = () => {
        if (!initialized) {
github rsocket / rsocket-js / packages / rsocket-core / src / RSocketResumableTransport.js View on Github external
_handleConnected(connection: DuplexConnection): void {
    this._currentConnection = connection;
    this._flushFrames();
    this._setConnectionStatus(CONNECTION_STATUS.CONNECTED);
    connection.receive().subscribe({
      onNext: frame => {
        try {
          this._receiveFrame(frame);
        } catch (error) {
          this._close(error);
        }
      },
      onSubscribe: subscription => {
        this._receiveSubscription = subscription;
        subscription.request(Number.MAX_SAFE_INTEGER);
      },
    });
  }
github rsocket / rsocket-js / packages / rsocket-websocket-client / src / RSocketWebSocketClient.js View on Github external
_handleOpened = (): void => {
    this._setConnectionStatus(CONNECTION_STATUS.CONNECTED);
  };
github rsocket / rsocket-js / packages / rsocket-tcp-client / src / RSocketTcpClient.js View on Github external
constructor(socket: ?net$Socket, encoders: ?Encoders<*>) {
    this._buffer = createBuffer(0);
    this._encoders = encoders;
    this._receivers = new Set();
    this._senders = new Set();
    this._statusSubscribers = new Set();

    if (socket) {
      this.setupSocket(socket);
      this._status = CONNECTION_STATUS.CONNECTED;
    } else {
      this._socket = null;
      this._status = CONNECTION_STATUS.NOT_CONNECTED;
    }
  }
github rsocket / rsocket-js / packages / rsocket-tcp-client / src / RSocketTcpClient.js View on Github external
_handleOpened = (): void => {
    this.setConnectionStatus(CONNECTION_STATUS.CONNECTED);
  };
}
github rsocket / rsocket-js / packages / rsocket-websocket-server / src / RSocketWebSocketServer.js View on Github external
const onSocketError = error => {
        closeSocket();
        subscriber.onError(error);
        const status = error ? {error, kind: 'ERROR'} : CONNECTION_STATUS.CLOSED;
        this._setConnectionStatus(status);
      };
      const onMessage = (data: Buffer) => {
github rsocket / rsocket-js / packages / rsocket-core / src / RSocketResumableTransport.js View on Github external
_close(error?: Error): void {
    if (this._isTerminated()) {
      return;
    }
    if (error) {
      this._setConnectionStatus({error, kind: 'ERROR'});
    } else {
      this._setConnectionStatus(CONNECTION_STATUS.CLOSED);
    }
    const receivers = this._receivers;
    receivers.forEach(r => r.onComplete());
    receivers.clear();

    const senders = this._senders;
    senders.forEach(s => s.cancel());
    senders.clear();
    this._sentFrames.length = 0;

    this._disconnect();
  }

rsocket-types

RSocket types

Apache-2.0
Latest version published 10 months ago

Package Health Score

77 / 100
Full package analysis

Similar packages