Skip to main content

WebSocket script API reference

In operation scripts for WebSocket operations, despite the operation script API, the definitions below are available through the kreyaWebSocket namespace. For example:

import { expect } from 'chai';

let responseCount = 0;

kreyaWebSocket.onResponseMessage(response => {
responseCount++;
kreya.test('Response content', () => expect(response.content).to.contain(`Message ${responseCount}`));
});

kreyaWebSocket.onCallCompleted(call => {
kreya.trace('The WebSocket call completed.');

kreya.test('Status code', () => expect(call.status.code).to.equal(1000));
});

Functions

onCallCompleted()

function onCallCompleted(callback: (arg: WebSocketScriptCallCompletedContext) => void | Promise<void>): void;

Hook which is called when the web socket call completes.

Parameters

ParameterTypeDescription
callback(arg: WebSocketScriptCallCompletedContext) => void | Promise<void>The callback to be invoked.

Returns

void


onResponseMessage()

function onResponseMessage(callback: (arg: WebSocketScriptResponseMessageContext) => void | Promise<void>): void;

Hook which is called when a web socket response message arrives.

Parameters

ParameterTypeDescription
callback(arg: WebSocketScriptResponseMessageContext) => void | Promise<void>The callback to be invoked.

Returns

void

Type Aliases

WebSocketScriptCallCompletedContext

type WebSocketScriptCallCompletedContext = {
durationMillis: number;
responseMessageCount: number;
status: WebSocketScriptStatus;
};

Callback context of gRPC completed call callback.

Properties

durationMillis
readonly durationMillis: number;

Duration of the call in milliseconds.

responseMessageCount
readonly responseMessageCount: number;

The number of received response messages.

status
readonly status: WebSocketScriptStatus;

The status of the call.


WebSocketScriptResponseMessageContext

type WebSocketScriptResponseMessageContext = {
content: string;
index: number;
isBinary: boolean;
size: number;
};

Callback context of the callback when a gRPC response message has arrived.

Properties

content
readonly content: string;

The content of the message.

index
readonly index: number;

The index of the response.

isBinary
readonly isBinary: boolean;

Whether the message is binary. If true, the content is encoded as Base64.

size
readonly size: number;

The size of the message in bytes.


WebSocketScriptStatus

type WebSocketScriptStatus = {
code: number;
detail: string;
};

Status of a web socket call.

Properties

code
readonly code: number;

The status code.

detail?
readonly optional detail: string;

The status detail.