本文整理汇总了TypeScript中rockets-client.isJsonRpcRequest函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isJsonRpcRequest函数的具体用法?TypeScript isJsonRpcRequest怎么用?TypeScript isJsonRpcRequest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isJsonRpcRequest函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: expect
mockServer.on('connection', () => {
const task = brayns.request(INSPECT, [0, 1]);
expect(isJsonRpcRequest(task.request)).toBe(true);
expect(isFunction(task.then)).toBe(true);
expect(isFunction(task.on)).toBe(true);
expect(isFunction(task.cancel)).toBe(true);
done();
});
示例2: toResponseErrorJson
(socket as any).on('message', (data: any) => {
if (isString(data)) {
const json = fromJson<JsonRpcRequest<BinaryParams> | JsonRpcNotification<ChunkParams>>(data);
if (isJsonRpcRequest(json)) {
const response = toResponseErrorJson(json, {
code: -1,
message: 'Oops :('
});
socket.send(response);
} else if (isJsonRpcNotification(json)) {
notifications.push(json);
}
} else {
chunks.push(data);
}
});
示例3: toResponseJson
(socket as any).on('message', (data: any) => {
messages.push(data);
if (isString(data)) {
const json = fromJson<JsonRpcRequest<BinaryParams> | JsonRpcNotification<ChunkParams>>(data);
if (isJsonRpcRequest(json)) {
request = json;
}
} else {
chunks.push(data);
if (chunks.length === expectedLength) {
// Received all chunks,
// respond so the request can complete
const response = toResponseJson(request, true);
socket.send(response);
}
}
});
示例4: fromJson
}).then(() => {
const [requestJson, ...objects] = messages;
const request = fromJson(requestJson);
expect(isJsonRpcRequest(request)).toBe(true);
const notifications = objects.filter((obj, index) => index % 2 === 0)
.map(json => fromJson<JsonRpcNotification<ChunkParams>>(json));
const chunks = objects.filter((obj, index) => index % 2 !== 0);
expect(notifications).toHaveLength(expectedLength);
expect(notifications.every(({method, params}) => method === CHUNK && isString(params!.id))).toBe(true);
expect(chunks).toHaveLength(expectedLength);
expect(chunks.every(chunk => chunk instanceof ArrayBuffer)).toBe(true);
const json = decodeChunks(chunks);
expect(json).toEqual(data);
done();
});