当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript mock-socket.Server类代码示例

本文整理汇总了TypeScript中mock-socket.Server的典型用法代码示例。如果您正苦于以下问题:TypeScript Server类的具体用法?TypeScript Server怎么用?TypeScript Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Server类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: before

        before(function () {
            const fakeURL = 'ws://localhost:8080/peerjs?key=peerjs&id=1&token=testToken';
            mockServer = new Server(fakeURL);

            mockServer.on('connection', socket => {
                //@ts-ignore
                socket.on('message', data => {
                    socket.send('test message from mock server');
                });

                socket.send(ServerMessageType.Open);
            });
        });
开发者ID:peers,项目名称:peerjs,代码行数:13,代码来源:peer.ts

示例2: it

        it('should connect', (done) => {
            mockwebSocketServer.on('connection', () => {
                done();
            });

            dotEventsSocket.connect().subscribe(() => {});
        });
开发者ID:dotCMS,项目名称:core-web,代码行数:7,代码来源:dot-event-socket.spec.ts

示例3: it

        it('should send a request', done => {
            const brayns = new Client(host);

            mockServer.on('connection', socket => {
                // TODO: (socket as any) is due to https://github.com/thoov/mock-socket/issues/224,
                // remove when fixed
                (socket as any).on('message', (data: any) => {
                    const json = fromJson<JsonRpcRequest>(data);
                    expect(isJsonRpcRequest(json)).toBe(true);
                    expect(json.id).toBeDefined();
                    expect(json.method).toBe(INSPECT);
                    expect(json.params).toEqual({
                        ping: true
                    });

                    const response = toResponseJson(json, true);
                    socket.send(response);
                });
            });

            brayns.request(INSPECT, {ping: true} as any)
                .then(() => {
                    done();
                });
        });
开发者ID:chevtche,项目名称:Brayns,代码行数:25,代码来源:client.spec.ts

示例4: callback

  const addServerHandler = (
    method: string, 
    path: string, 
    responseData: Omit<RequestSuccessResponse, 'callback_id'> | Omit<RequestErrorResponse, 'callback_id'>, 
    callback: Callback
  ) => {
    const handler = (jsonRequest: string) => {
      const requestObj: OutgoingRequest = JSON.parse(jsonRequest);

      if (requestObj.path !== path || requestObj.method !== method) {
        //console.log(requestObj, requestObj.path, path);
        return;
      }

      if (callback) {
        callback(requestObj);
      }

      const response: RequestSuccessResponse | RequestErrorResponse = {
        callback_id: requestObj.callback_id,
        ...responseData,
      };

      mockServer.send(JSON.stringify(response));
    };

    mockServer.addEventListener('message', handler);
  };
开发者ID:airdcpp-web,项目名称:airdcpp-apisocket-js,代码行数:28,代码来源:helpers.ts

示例5:

 mockServer.on('connection', socket => {
     mockServer.close({
         code: 1005,
         reason: 'Why not?',
         wasClean: false
     });
 });
开发者ID:chevtche,项目名称:Brayns,代码行数:7,代码来源:client.spec.ts

示例6: describe

    describe('{ready}', () => {
        let mockServer: Server;
        beforeEach(() => {
            mockServer = new Server(wsHost);
        });
        afterEach(done => {
            mockServer.stop(done);
        });

        it('should emit false by default', done => {
            const brayns = new Client(host);
            brayns.ready.pipe(take(1))
                .subscribe(ready => {
                    expect(ready).toBe(false);
                    done();
                });
        });

        it('should emit true when the socket establishes a connection with the ws server', done => {
            const brayns = new Client(host);
            brayns.ready.pipe(skip(1), take(1))
                .subscribe(ready => {
                    expect(ready).toBe(true);
                    done();
                });
        });

        it('should emit false when the socket connection with the ws server is closed', done => {
            const brayns = new Client(host);

            brayns.ready.pipe(skip(2), take(1))
                .subscribe(ready => {
                    expect(ready).toBe(false);
                    done();
                });

            mockServer.on('connection', socket => {
                socket.close(0, 'Why not?');
            });
        });

        it('should emit false when the socket connection with the ws server errored', done => {
            const brayns = new Client(host);

            brayns.ready.pipe(skip(2), take(1))
                .subscribe(ready => {
                    expect(ready).toBe(false);
                    done();
                });

            mockServer.on('connection', socket => {
                mockServer.close({
                    code: 1005,
                    reason: 'Why not?',
                    wasClean: false
                });
            });
        });
    });
开发者ID:chevtche,项目名称:Brayns,代码行数:59,代码来源:client.spec.ts

示例7: beforeEach

 beforeEach(async () => {
   mockServer = new Server("ws://localhost:6868");
   p = new Promise((resolve, reject) => { res = resolve; rej = reject; });
   const serverInfo = (jsonmsg: string) => {
     const msg: Messages.ButtplugMessage = FromJSON(jsonmsg)[0] as Messages.ButtplugMessage;
     if (msg.Type === Messages.RequestServerInfo) {
       delaySend(new Messages.ServerInfo(0, 0, 0, 1, 0, "Test Server", msg.Id));
     }
     if (msg.Type === Messages.RequestDeviceList) {
       delaySend(new Messages.DeviceList([], msg.Id));
       // (socket as any).removeListener("message", serverInfo);
     }
   };
   mockServer.on("connection", (aSocket: WebSocket) => {
     socket = aSocket;
     // TODO Bug in typescript defs for mock-socket 8 means we can't use the
     // socket type as it was meant. See
     // https://github.com/thoov/mock-socket/issues/224
     (socket as any).on("message", (data: string) => serverInfo(data));
   });
   bp = new ButtplugClient("Test Buttplug Client");
   await bp.Connect(new ButtplugBrowserWebsocketClientConnector("ws://localhost:6868"));
 });
开发者ID:metafetish,项目名称:buttplug-js,代码行数:23,代码来源:test-websocketclient.ts


注:本文中的mock-socket.Server类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。