本文整理匯總了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();
});