diff --git a/docs/sources/next/javascript-api/k6-experimental/websockets/_index.md b/docs/sources/next/javascript-api/k6-experimental/websockets/_index.md index afed9a9e45..6b5e2986af 100644 --- a/docs/sources/next/javascript-api/k6-experimental/websockets/_index.md +++ b/docs/sources/next/javascript-api/k6-experimental/websockets/_index.md @@ -1,7 +1,6 @@ --- title: 'websockets' -descriptiontion: "k6 websockets experimental API" -weight: 05 +description: "k6 websockets experimental API" weight: 05 --- @@ -16,31 +15,32 @@ A global event loop lets a single VU have multiple concurrent connections, which The `WebSocket API` is not fully implemented, and we're working on it, but we believe it's usable for most users. So whether you're writing a new WebSocket test, or currently using the `k6/ws` module, we invite you to give it a try, and report any issues in the project's [issue tracker](https://github.com/grafana/xk6-websockets/). Our midterm goal is to make this module part of k6 core, and long-term to replace the [`k6/ws`](https://grafana.com/docs/k6//javascript-api/k6-ws) module. -| Class/Method | Description | -| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | -| [Params](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/params) | Used for setting various WebSocket connection parameters such as headers, cookie jar, compression, etc. | -| [WebSocket(url, protocols, params)](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket) | Constructs a new WebSocket connection. | -| [WebSocket.close()](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-close) | Close the WebSocket connection. | -| [WebSocket.ping()](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-ping) | Send a ping. | -| [WebSocket.send(data)](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-send) | Send string data. | -| [WebSocket.addEventListener(event, handler)](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-addeventlistener) | Add an event listener on the connection for specific event. | +| Class/Method | Description | +|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [Params](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/params) | Used for setting various WebSocket connection parameters such as headers, cookie jar, compression, etc. | +| [WebSocket(url, protocols, params)](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket) | Constructs a new WebSocket connection. | +| [WebSocket.close()](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-close) | Close the WebSocket connection. | +| [WebSocket.ping()](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-ping) | Send a ping. | +| [WebSocket.send(data)](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-send) | Send string data. | +| [WebSocket.addEventListener(event, handler)](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-addeventlistener) | Add an event listener on the connection for specific event. | +| [Blob](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/blob) | Interface that represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data, or converted into a [ReadableStream](https://grafana.com/docs/k6//javascript-api/k6-experimental/streams/readablestream). | A WebSocket instance also has the following properties: -| Class/Property | Description | -| --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| WebSocket.readyState | The current state of the connection. Could be one of [the four states](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState). | -| WebSocket.url | The URL of the connection as resolved by the constructor. | -| WebSocket.bufferedAmount | The number of bytes of data that have been queued using calls to `send()` but not yet transmitted to the network. | -| WebSocket.binaryType | The [`binaryType`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType) is by default `""`. If a binary message is received it will be automatically set to `"arraybuffer"` if empty and warning will be printed. In the future it will move to default to `"blob"`. If you want to have the same behaviour - you should always be setting it to `"arraybuffer"`. | -| [WebSocket.onmessage](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-onmessage) | A handler for `message` events. | -| [WebSocket.onerror](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-onerror) | A handler for `error` events. | -| [WebSocket.onopen](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-onopen) | A handler for `open` events. | -| [WebSocket.onclose](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-onclose) | A handler for `close` events. | -| [WebSocket.onping](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-onping) | A handler for `ping` events. | -| [WebSocket.onpong](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-onpong) | A handler for `pong` events. | +| Class/Property | Description | +|-----------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| WebSocket.readyState | The current state of the connection. Could be one of [the four states](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState). | +| WebSocket.url | The URL of the connection as resolved by the constructor. | +| WebSocket.bufferedAmount | The number of bytes of data that have been queued using calls to `send()` but not yet transmitted to the network. | +| WebSocket.binaryType | _Required_. The [`binaryType`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType) controls the type of binary data being received over the WebSocket connection. Use `"blob"` to receive it as `Blob`, or `"arraybuffer"` to receive it as `ArrayBuffer`. The default value is empty. That will change to default to `"blob"` in the future. If you want to keep the same behavior, we recommend setting it to `"arraybuffer"`. | +| [WebSocket.onmessage](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-onmessage) | A handler for `message` events. | +| [WebSocket.onerror](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-onerror) | A handler for `error` events. | +| [WebSocket.onopen](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-onopen) | A handler for `open` events. | +| [WebSocket.onclose](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-onclose) | A handler for `close` events. | +| [WebSocket.onping](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-onping) | A handler for `ping` events. | +| [WebSocket.onpong](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-onpong) | A handler for `pong` events. | diff --git a/docs/sources/next/javascript-api/k6-experimental/websockets/blob/_index.md b/docs/sources/next/javascript-api/k6-experimental/websockets/blob/_index.md new file mode 100644 index 0000000000..3291fd90df --- /dev/null +++ b/docs/sources/next/javascript-api/k6-experimental/websockets/blob/_index.md @@ -0,0 +1,27 @@ +--- +title: 'Blob' +description: 'Interface that represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data, or converted into a ReadableStream.' +weight: 10 +--- + +# Blob + +`Blob` is an interface that represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data, or converted into a [ReadableStream](https://grafana.com/docs/k6//javascript-api/k6-experimental/streams/readablestream). + +It's the type of the data received on [WebSocket.onmessage](https://grafana.com/docs/k6//javascript-api/k6-experimental/websockets/websocket/websocket-onmessage) when `WebSocket.binaryType` is set to `"blob"`. + +A `Blob` instance has the following methods/properties: + + + +| Class/Property | Description | +|--------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Blob.size | The number of bytes of data contained within the `Blob`. | +| Blob.type | A string containing the MIME type, or an empty string if the type could not be determined. | +| Blob.arrayBuffer() | Returns a `Promise` that resolves with the contents of the blob as binary data contained in an `ArrayBuffer`. | +| Blob.bytes() | Returns a `Promise` that resolves with a `Uint8Array` containing the contents of the blob as an array of bytes. | +| Blob.slice() | Returns a new `Blob` object which contains data from a subset of the blob on which it's called. | +| Blob.stream() | Returns a [ReadableStream](https://grafana.com/docs/k6//javascript-api/k6-experimental/streams/readablestream) which upon reading returns the data contained within the `Blob`. | +| Blob.text() | Returns a `Promise` that resolves with a string containing the contents of the blob, interpreted as `UTF-8`. | + + diff --git a/docs/sources/next/javascript-api/k6-experimental/websockets/params.md b/docs/sources/next/javascript-api/k6-experimental/websockets/params.md index b55ed82814..8ed8bf8881 100644 --- a/docs/sources/next/javascript-api/k6-experimental/websockets/params.md +++ b/docs/sources/next/javascript-api/k6-experimental/websockets/params.md @@ -1,7 +1,6 @@ --- title: 'Params' description: 'Used for setting various WebSocket request-specific parameters such as headers, tags, etc.' -description: 'Used for setting various WebSocket request-specific parameters such as headers, tags, etc.' weight: 20 --- diff --git a/docs/sources/next/javascript-api/k6-experimental/websockets/websocket/_index.md b/docs/sources/next/javascript-api/k6-experimental/websockets/websocket/_index.md index b97042d43f..068cdaa45d 100644 --- a/docs/sources/next/javascript-api/k6-experimental/websockets/websocket/_index.md +++ b/docs/sources/next/javascript-api/k6-experimental/websockets/websocket/_index.md @@ -1,8 +1,6 @@ --- title: 'WebSocket' description: 'Create a WebSocket connection, and provides a WebSocket instance to interact with the service.' -description: 'Create a WebSocket connection, and provides a WebSocket instance to interact with the service.' -weight: 10 weight: 10 ---