WebsocketResource

Websocket Resources are core websocket connections between a client and server.

The WebsocketResource class is returned from window.waitForResource. It contains all properties of a Resource in addition to an ability to subscribe to messages sent back and forth.

Properties

request

The Http Upgrade request used to create this Websocket.

ReturnsResourceRequest

response

A simulation of an HTTP response pieced together from the socket headers returned during a normal HTTP upgrade.

ReturnsResourceResponse

url

The Http Upgrade url.

Returnsstring

type

The type of resource.

ReturnsResourceType=WebSocket

isRedirect

Was this request redirected

Returnsboolean

data

Invalid call. Throws an Error. To subscribe to messages, see on('message', callback)

ReturnsPromise<Buffer>

Methods

on('message', callback: WebsocketMessage => any)

Called on each websocket message returned.

WebsocketMessage contain:

  • message string | Buffer - the contents of the message
  • source server | client - where the message originated

ReturnsPromise<void>

off('message', callback: WebsocketMessage => any)

Unsubscribe to messages.

ReturnsPromise<void>

once('message', callback: WebsocketMessage => any)

Subscribe to a single websocket message

ReturnsPromise<void>

addEventListener('message', callback: WebsocketMessage => any)

Alias for on('message', callback')

ReturnsPromise<void>

removeEventListener('message', callback: WebsocketMessage => any)

Alias for off('message', callback')

ReturnsPromise<void>

text()

Invalid call. Throws an Error. To subscribe to messages, see on('message', callback)

ReturnsPromise<string>

json()

Invalid call. Throws an Error. To subscribe to messages, see on('message', callback)

ReturnsPromise<json>

Edit this page on GitHub