{"record":{"id":"6e5a0fb59d497092","repo":"bilibili/flv.js","slug":"unsupported-websocket-message-type-e-data-con","errorCode":null,"errorMessage":"Unsupported WebSocket message type: ' + e.data.constructor.name","messagePattern":"Unsupported WebSocket message type: ' \\+ e\\.data\\.constructor\\.name","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/io/websocket-loader.js","lineNumber":119,"sourceCode":"    }\n\n    _onWebSocketMessage(e) {\n        if (e.data instanceof ArrayBuffer) {\n            this._dispatchArrayBuffer(e.data);\n        } else if (e.data instanceof Blob) {\n            let reader = new FileReader();\n            reader.onload = () => {\n                this._dispatchArrayBuffer(reader.result);\n            };\n            reader.readAsArrayBuffer(e.data);\n        } else {\n            this._status = LoaderStatus.kError;\n            let info = {code: -1, msg: 'Unsupported WebSocket message type: ' + e.data.constructor.name};\n\n            if (this._onError) {\n                this._onError(LoaderErrors.EXCEPTION, info);\n            } else {\n                throw new RuntimeException(info.msg);\n            }\n        }\n    }\n\n    _dispatchArrayBuffer(arraybuffer) {\n        let chunk = arraybuffer;\n        let byteStart = this._receivedLength;\n        this._receivedLength += chunk.byteLength;\n\n        if (this._onDataArrival) {\n            this._onDataArrival(chunk, byteStart, this._receivedLength);\n        }\n    }\n\n    _onWebSocketError(e) {\n        this._status = LoaderStatus.kError;\n\n        let info = {","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/bilibili/flv.js/blob/42343088f22619cf014a057b3878fe3d320016a6/src/io/websocket-loader.js#L101-L137","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Ensure the WebSocket server sends only binary frames containing FLV stream data (set binaryType and send ArrayBuffer/Blob).","Register onError on the loader/player so failures surface through the error callback rather than an exception.","Verify the ws URL targets a FLV-over-WebSocket proxy/endpoint, not a generic chat/JSON socket."],"exampleFix":"// before (server)\nws.send(JSON.stringify({type: 'heartbeat'}));\n// after (server)\nws.send(flvtChunkArrayBuffer); // binary FLV data only","handlingStrategy":"validation","validationCode":"// Client-side guard: only feed binary frames to the loader\nws.binaryType = 'arraybuffer';\nws.onmessage = (e) => {\n    if (typeof e.data === 'string') {\n        console.warn('Ignoring non-binary WS frame');\n        return; // never forward text frames to the player pipeline\n    }\n    handleBinaryChunk(e.data);\n};","typeGuard":"function isBinaryWsFrame(data) {\n    return data instanceof ArrayBuffer || (typeof Blob !== 'undefined' && data instanceof Blob);\n}","tryCatchPattern":"try {\n    wsLoader.load();\n} catch (e) {\n    if (/Unsupported WebSocket message type/.test(e.message)) {\n        console.error('Server sent non-binary frame; check WS endpoint protocol', e.message);\n    } else throw e;\n}","preventionTips":["Ensure the WS server sends only binary FLV chunks; send control messages on a separate channel or encode them out-of-band.","Set ws.binaryType = 'arraybuffer' on the client.","Test the endpoint with a raw WS client before wiring it to the player."],"tags":["websocket","protocol","loader","binary-data"],"backgroundTag":"unsupported-websocket-message","analyzedSha":"42343088f22619cf014a057b3878fe3d320016a6","analyzedAt":"2026-09-01T00:27:28.147Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}