Preparing search index...

    Client-side WebSocket connection that can send and receive data over a WebSocket connection.

        const WS = await import('LensStudio:WebSocket');
    const Network = await import('LensStudio:Network');
    const ws = WS.WebSocket.create();
    this.connections.push(
    ws.onConnect.connect(() => {
    console.log('WebSocket connected');
    ws.send('hello from plugin');
    })
    );
    this.connections.push(
    ws.onData.connect((data) => {
    console.log(`Received data: ${data.toString()}`);
    })
    );
    this.connections.push(
    ws.onError.connect((code) => {
    console.log(`WebSocket error: ${code}`);
    })
    );
    const addr = new Network.Address();
    addr.address = 'localhost';
    addr.port = 8080;
    ws.connect(addr);

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    localAddress: Address

    The local address bound to this socket.

    onConnect: signal0<void>

    Signal fired when the socket successfully establishes a connection.

    onData: signal1<Buffer, void>

    Signal fired when data is received on the socket, carrying the received buffer.

    onEnd: signal0<void>

    Signal fired when the remote end signals the end of transmission.

    onError: signal1<number, void>

    Signal fired when a socket error occurs.

    remoteAddress: Address

    The remote address this socket is connected to.

    Methods

    • Closes the socket connection gracefully.

      Returns void

    • Connects to a remote address using the WebSocket protocol.

      Parameters

      Returns void

    • Destroys the socket and releases all associated resources immediately.

      Returns void

    • Returns the name of this object's type.

      Returns string

    • Returns true if the object is of the specified type.

      Parameters

      • type: string

      Returns boolean

    • Sends binary or text data over the WebSocket connection, returning the number of bytes sent.

      Parameters

      • data: string | Uint8Array

      Returns number