MCPcopy Create free account
hub / github.com/FunAudioLLM/Fun-Audio-Chat / encodeMessage

Function encodeMessage

web_demo/client/src/protocol/encoder.ts:9–35  ·  view source on GitHub ↗
(message: WSMessage)

Source from the content-addressed store, hash-verified

7} from "./types";
8
9export const encodeMessage = (message: WSMessage): Uint8Array => {
10 switch (message.type) {
11 case "handshake":
12 return new Uint8Array([
13 0x00,
14 VERSIONS_MAP[message.version],
15 MODELS_MAP[message.model],
16 ]);
17 case "audio":
18 return new Uint8Array([0x01, ...message.data]);
19 case "text":
20 return new Uint8Array([0x02, ...new TextEncoder().encode(message.data)]);
21 case "coloredtext":
22 return new Uint8Array([0x02, 0x05, ...new TextEncoder().encode(message.data)]);
23 case "control":
24 return new Uint8Array([0x03, CONTROL_MESSAGES_MAP[message.action]]);
25 case "metadata":
26 return new Uint8Array([
27 0x04,
28 ...new TextEncoder().encode(JSON.stringify(message.data)),
29 ]);
30 case "error":
31 return new Uint8Array([0x05, ...new TextEncoder().encode(message.data)]);
32 case "ping":
33 return new Uint8Array([0x06]);
34 }
35};
36
37export const decodeMessage = (data: Uint8Array): WSMessage => {
38 const type = data[0];

Callers 1

useSocketFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected