MCPcopy Create free account
hub / github.com/vercel/examples / parseFrame

Function parseFrame

websockets/next-chat/lib/protocol.ts:52–63  ·  view source on GitHub ↗
(raw: unknown)

Source from the content-addressed store, hash-verified

50
51/** Parse an incoming WebSocket payload into a typed frame, or null if invalid. */
52export function parseFrame<T extends { type: string }>(raw: unknown): T | null {
53 if (typeof raw !== 'string') return null
54 try {
55 const obj = JSON.parse(raw)
56 if (obj && typeof obj === 'object' && typeof obj.type === 'string') {
57 return obj as T
58 }
59 } catch {
60 /* malformed JSON — ignore */
61 }
62 return null
63}

Callers 2

useChatSocketFunction · 0.90
handleMessageMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected