bilibili/flv.js · error · RuntimeException

Unsupported WebSocket message type: ' + e.data.constructor.n

Error message

Unsupported WebSocket message type: ' + e.data.constructor.name

What it means

WebSocketLoader._onWebSocketMessage expects binary frames (ArrayBuffer/Blob per loader config) carrying FLV data. If a frame's data constructor is not a recognized binary type (e.g. a string frame from the server), the loader marks itself errored and, lacking an onError callback, throws RuntimeException with the unexpected constructor name. It indicates the server sent a message type the loader cannot parse as media data.

Source

Thrown at src/io/websocket-loader.js:119

    }

    _onWebSocketMessage(e) {
        if (e.data instanceof ArrayBuffer) {
            this._dispatchArrayBuffer(e.data);
        } else if (e.data instanceof Blob) {
            let reader = new FileReader();
            reader.onload = () => {
                this._dispatchArrayBuffer(reader.result);
            };
            reader.readAsArrayBuffer(e.data);
        } else {
            this._status = LoaderStatus.kError;
            let info = {code: -1, msg: 'Unsupported WebSocket message type: ' + e.data.constructor.name};

            if (this._onError) {
                this._onError(LoaderErrors.EXCEPTION, info);
            } else {
                throw new RuntimeException(info.msg);
            }
        }
    }

    _dispatchArrayBuffer(arraybuffer) {
        let chunk = arraybuffer;
        let byteStart = this._receivedLength;
        this._receivedLength += chunk.byteLength;

        if (this._onDataArrival) {
            this._onDataArrival(chunk, byteStart, this._receivedLength);
        }
    }

    _onWebSocketError(e) {
        this._status = LoaderStatus.kError;

        let info = {

View on GitHub (pinned to 42343088f2)

Solutions

  1. Ensure the WebSocket server sends only binary frames containing FLV stream data (set binaryType and send ArrayBuffer/Blob).
  2. Register onError on the loader/player so failures surface through the error callback rather than an exception.
  3. Verify the ws URL targets a FLV-over-WebSocket proxy/endpoint, not a generic chat/JSON socket.

Example fix

// before (server)
ws.send(JSON.stringify({type: 'heartbeat'}));
// after (server)
ws.send(flvtChunkArrayBuffer); // binary FLV data only
Defensive patterns

Strategy: validation

Validate before calling

// Client-side guard: only feed binary frames to the loader
ws.binaryType = 'arraybuffer';
ws.onmessage = (e) => {
    if (typeof e.data === 'string') {
        console.warn('Ignoring non-binary WS frame');
        return; // never forward text frames to the player pipeline
    }
    handleBinaryChunk(e.data);
};

Type guard

function isBinaryWsFrame(data) {
    return data instanceof ArrayBuffer || (typeof Blob !== 'undefined' && data instanceof Blob);
}

Try / catch

try {
    wsLoader.load();
} catch (e) {
    if (/Unsupported WebSocket message type/.test(e.message)) {
        console.error('Server sent non-binary frame; check WS endpoint protocol', e.message);
    } else throw e;
}

Prevention

When it happens

Trigger: The WebSocket server sends text frames (typeof e.data === 'string', e.g. JSON control messages) or frames whose payload is not converted to ArrayBuffer while the loader is in binary mode, in _onWebSocketMessage (src/io/websocket-loader.js:119).

Common situations: Pointing the ws:// loader at a WebSocket endpoint that does not stream raw FLV binary chunks (custom protocol sending JSON heartbeats/text), or server misconfiguration after protocol/version change.

Related errors


AI-assisted analysis of bilibili/flv.js@42343088f2 (2026-09-01). Data as JSON: /api/errors/6e5a0fb59d497092. Report an issue: GitHub.