Example #1
0
  _onConnection(socket: WS): void {
    logger.debug('WebSocket connecting');

    let client: ?RpcConnection<QueuedTransport> = null;

    const errorSubscription = attachEvent(socket, 'error', e =>
      logger.error('WebSocket error before first message', e),
    );

    socket.once('message', (clientId: string) => {
      errorSubscription.dispose();
      client = this._clients.get(clientId);
      const transport = new WebSocketTransport(clientId, socket);
      if (client == null) {
        client = RpcConnection.createServer(
          this._rpcServiceRegistry,
          new QueuedTransport(clientId, transport),
        );
        this._clients.set(clientId, client);
      } else {
        invariant(clientId === client.getTransport().id);
        client.getTransport().reconnect(transport);
      }
    });
  }
Example #2
0
 onNotification(
   callback: (notifyName: string, notify: Object) => mixed,
 ): IDisposable {
   return attachEvent(this._emitter, DBGP_SOCKET_NOTIFICATION_EVENT, callback);
 }
Example #3
0
 onStatus(callback: (status: string) => mixed): IDisposable {
   return attachEvent(this._emitter, DBGP_SOCKET_STATUS_EVENT, callback);
 }