A Stream that speaks objects instead of bytes.
send(value) marshals with JSON.stringify, and ev.data in an onmessage handler is the parsed object rather than an ArrayBuffer. Pairs with StreamConn.SendJSON / ReceiveJSON on the Go side.
send(value)
JSON.stringify
ev.data
onmessage
ArrayBuffer
StreamConn.SendJSON
ReceiveJSON
const s = JSONStream("telemetry");s.onmessage = (ev) => console.log(ev.data.temperature);s.onopen = () => s.send({ subscribe: "sensors" }); Copy
const s = JSONStream("telemetry");s.onmessage = (ev) => console.log(ev.data.temperature);s.onopen = () => s.send({ subscribe: "sensors" });
A frame that is not valid JSON raises an error event and is dropped, rather than throwing from the poll loop and taking the connection down with it.
error
A Stream that speaks objects instead of bytes.
send(value)marshals withJSON.stringify, andev.datain anonmessagehandler is the parsed object rather than anArrayBuffer. Pairs withStreamConn.SendJSON/ReceiveJSONon the Go side.A frame that is not valid JSON raises an
errorevent and is dropped, rather than throwing from the poll loop and taking the connection down with it.