[{"data":1,"prerenderedAt":1443},["ShallowReactive",2],{"navigation":3,"/adapters/sse":56,"/adapters/sse-surround":1439},[4,30],{"title":5,"_path":6,"children":7,"icon":9},"Getting Started","/guide",[8,10,14,18,22,26],{"title":5,"_path":6,"icon":9},"ph:book-open-duotone",{"title":11,"_path":12,"icon":13},"Hooks","/guide/hooks","material-symbols-light:data-object",{"title":15,"_path":16,"icon":17},"Peer","/guide/peer","mynaui:api",{"title":19,"_path":20,"icon":21},"Message","/guide/message","solar:letter-line-duotone",{"title":23,"_path":24,"icon":25},"Pub / Sub","/guide/pubsub","simple-icons:googlepubsub",{"title":27,"_path":28,"icon":29},"Resolver API","/guide/resolver","tabler:route",{"title":31,"_path":32,"children":33,"icon":35},"Adapters","/adapters",[34,36,40,44,48,52],{"title":31,"_path":32,"icon":35},"emojione-monotone:electric-plug",{"title":37,"_path":38,"icon":39},"Bun","/adapters/bun","simple-icons:bun",{"title":41,"_path":42,"icon":43},"Cloudflare","/adapters/cloudflare","devicon-plain:cloudflareworkers",{"title":45,"_path":46,"icon":47},"Deno","/adapters/deno","teenyicons:deno-solid",{"title":49,"_path":50,"icon":51},"Node.js","/adapters/node","akar-icons:node-fill",{"title":53,"_path":54,"icon":55},"SSE","/adapters/sse","clarity:two-way-arrows-line",{"_path":54,"_dir":57,"_draft":58,"_partial":58,"_locale":59,"title":53,"description":60,"icon":55,"body":61,"_type":1433,"_id":1434,"_source":1435,"_file":1436,"_stem":1437,"_extension":1438},"adapters",false,"","Integrate crossws with server-sent events and fetch-api.",{"type":62,"children":63,"toc":1427},"root",[64,101,122,129,136,145,150,645,650,937,943,955,1339,1386,1421],{"type":65,"tag":66,"props":67,"children":68},"element","p",{},[69,72,86,88,99],{"type":70,"value":71},"text","If your deployment target does not supports handling WebSocket upgrades, crossws SSE adapter allows to add integration based on web platform standards (",{"type":65,"tag":73,"props":74,"children":78},"a",{"href":75,"rel":76},"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API",[77],"nofollow",[79],{"type":65,"tag":80,"props":81,"children":83},"code",{"className":82},[],[84],{"type":70,"value":85},"fetch",{"type":70,"value":87}," and ",{"type":65,"tag":73,"props":89,"children":92},{"href":90,"rel":91},"https://developer.mozilla.org/en-US/docs/Web/API/EventSource",[77],[93],{"type":65,"tag":80,"props":94,"children":96},{"className":95},[],[97],{"type":70,"value":98},"EventSource",{"type":70,"value":100},")",{"type":65,"tag":102,"props":103,"children":104},"important",{},[105],{"type":65,"tag":66,"props":106,"children":107},{},[108,110,120],{"type":70,"value":109},"\nThis is an experimental adapter and requires a custom ",{"type":65,"tag":73,"props":111,"children":113},{"href":112},"#client-side",[114],{"type":65,"tag":80,"props":115,"children":117},{"className":116},[],[118],{"type":70,"value":119},"WebsocketSSE",{"type":70,"value":121}," client to connect.",{"type":65,"tag":123,"props":124,"children":126},"h2",{"id":125},"usage",[127],{"type":70,"value":128},"Usage",{"type":65,"tag":130,"props":131,"children":133},"h3",{"id":132},"server-side",[134],{"type":70,"value":135},"Server side",{"type":65,"tag":137,"props":138,"children":139},"note",{},[140],{"type":65,"tag":66,"props":141,"children":142},{},[143],{"type":70,"value":144},"\nHTTP/2 + TLS is recommended in order to increase browser limitations about number of SSE connections (from 6 to 100) and also to allow bidirectional messaging with streaming.",{"type":65,"tag":66,"props":146,"children":147},{},[148],{"type":70,"value":149},"Define adapter:",{"type":65,"tag":151,"props":152,"children":156},"pre",{"className":153,"code":154,"language":155,"meta":59,"style":59},"language-ts shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","import sseAdapter from \"crossws/adapters/sse\";\n\nconst ws = sseAdapter({\n  bidir: true, // Enable bidirectional messaging support\n  hooks: {\n    upgrade(request) {\n      // In case of bidirectional mode, extra auth is recommended based on request\n      // You can return a new Response() instead to abort\n      return {\n        headers: {},\n      };\n    },\n    open(peer) {\n      // Use this hook to send messages to peer\n      peer.send(`Welcome ${peer}`);\n    },\n    message(peer, message) {\n      // Accepting messages from peer (bidirectional mode)\n      console.log(`Message from ${peer}: ${message}`); // Message from \u003Cid>: ping\n    },\n  },\n});\n","ts",[157],{"type":65,"tag":80,"props":158,"children":159},{"__ignoreMap":59},[160,205,215,251,283,301,328,337,346,359,377,386,395,421,430,485,493,527,536,612,620,629],{"type":65,"tag":161,"props":162,"children":165},"span",{"class":163,"line":164},"line",1,[166,172,178,183,189,195,200],{"type":65,"tag":161,"props":167,"children":169},{"style":168},"--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic",[170],{"type":70,"value":171},"import",{"type":65,"tag":161,"props":173,"children":175},{"style":174},"--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8",[176],{"type":70,"value":177}," sseAdapter ",{"type":65,"tag":161,"props":179,"children":180},{"style":168},[181],{"type":70,"value":182},"from",{"type":65,"tag":161,"props":184,"children":186},{"style":185},"--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF",[187],{"type":70,"value":188}," \"",{"type":65,"tag":161,"props":190,"children":192},{"style":191},"--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D",[193],{"type":70,"value":194},"crossws/adapters/sse",{"type":65,"tag":161,"props":196,"children":197},{"style":185},[198],{"type":70,"value":199},"\"",{"type":65,"tag":161,"props":201,"children":202},{"style":185},[203],{"type":70,"value":204},";\n",{"type":65,"tag":161,"props":206,"children":208},{"class":163,"line":207},2,[209],{"type":65,"tag":161,"props":210,"children":212},{"emptyLinePlaceholder":211},true,[213],{"type":70,"value":214},"\n",{"type":65,"tag":161,"props":216,"children":218},{"class":163,"line":217},3,[219,225,230,235,241,246],{"type":65,"tag":161,"props":220,"children":222},{"style":221},"--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA",[223],{"type":70,"value":224},"const",{"type":65,"tag":161,"props":226,"children":227},{"style":174},[228],{"type":70,"value":229}," ws ",{"type":65,"tag":161,"props":231,"children":232},{"style":185},[233],{"type":70,"value":234},"=",{"type":65,"tag":161,"props":236,"children":238},{"style":237},"--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF",[239],{"type":70,"value":240}," sseAdapter",{"type":65,"tag":161,"props":242,"children":243},{"style":174},[244],{"type":70,"value":245},"(",{"type":65,"tag":161,"props":247,"children":248},{"style":185},[249],{"type":70,"value":250},"{\n",{"type":65,"tag":161,"props":252,"children":254},{"class":163,"line":253},4,[255,261,266,272,277],{"type":65,"tag":161,"props":256,"children":258},{"style":257},"--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178",[259],{"type":70,"value":260},"  bidir",{"type":65,"tag":161,"props":262,"children":263},{"style":185},[264],{"type":70,"value":265},":",{"type":65,"tag":161,"props":267,"children":269},{"style":268},"--shiki-light:#FF5370;--shiki-default:#FF9CAC;--shiki-dark:#FF9CAC",[270],{"type":70,"value":271}," true",{"type":65,"tag":161,"props":273,"children":274},{"style":185},[275],{"type":70,"value":276},",",{"type":65,"tag":161,"props":278,"children":280},{"style":279},"--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic",[281],{"type":70,"value":282}," // Enable bidirectional messaging support\n",{"type":65,"tag":161,"props":284,"children":286},{"class":163,"line":285},5,[287,292,296],{"type":65,"tag":161,"props":288,"children":289},{"style":257},[290],{"type":70,"value":291},"  hooks",{"type":65,"tag":161,"props":293,"children":294},{"style":185},[295],{"type":70,"value":265},{"type":65,"tag":161,"props":297,"children":298},{"style":185},[299],{"type":70,"value":300}," {\n",{"type":65,"tag":161,"props":302,"children":304},{"class":163,"line":303},6,[305,310,314,320,324],{"type":65,"tag":161,"props":306,"children":307},{"style":257},[308],{"type":70,"value":309},"    upgrade",{"type":65,"tag":161,"props":311,"children":312},{"style":185},[313],{"type":70,"value":245},{"type":65,"tag":161,"props":315,"children":317},{"style":316},"--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic",[318],{"type":70,"value":319},"request",{"type":65,"tag":161,"props":321,"children":322},{"style":185},[323],{"type":70,"value":100},{"type":65,"tag":161,"props":325,"children":326},{"style":185},[327],{"type":70,"value":300},{"type":65,"tag":161,"props":329,"children":331},{"class":163,"line":330},7,[332],{"type":65,"tag":161,"props":333,"children":334},{"style":279},[335],{"type":70,"value":336},"      // In case of bidirectional mode, extra auth is recommended based on request\n",{"type":65,"tag":161,"props":338,"children":340},{"class":163,"line":339},8,[341],{"type":65,"tag":161,"props":342,"children":343},{"style":279},[344],{"type":70,"value":345},"      // You can return a new Response() instead to abort\n",{"type":65,"tag":161,"props":347,"children":349},{"class":163,"line":348},9,[350,355],{"type":65,"tag":161,"props":351,"children":352},{"style":168},[353],{"type":70,"value":354},"      return",{"type":65,"tag":161,"props":356,"children":357},{"style":185},[358],{"type":70,"value":300},{"type":65,"tag":161,"props":360,"children":362},{"class":163,"line":361},10,[363,368,372],{"type":65,"tag":161,"props":364,"children":365},{"style":257},[366],{"type":70,"value":367},"        headers",{"type":65,"tag":161,"props":369,"children":370},{"style":185},[371],{"type":70,"value":265},{"type":65,"tag":161,"props":373,"children":374},{"style":185},[375],{"type":70,"value":376}," {},\n",{"type":65,"tag":161,"props":378,"children":380},{"class":163,"line":379},11,[381],{"type":65,"tag":161,"props":382,"children":383},{"style":185},[384],{"type":70,"value":385},"      };\n",{"type":65,"tag":161,"props":387,"children":389},{"class":163,"line":388},12,[390],{"type":65,"tag":161,"props":391,"children":392},{"style":185},[393],{"type":70,"value":394},"    },\n",{"type":65,"tag":161,"props":396,"children":398},{"class":163,"line":397},13,[399,404,408,413,417],{"type":65,"tag":161,"props":400,"children":401},{"style":257},[402],{"type":70,"value":403},"    open",{"type":65,"tag":161,"props":405,"children":406},{"style":185},[407],{"type":70,"value":245},{"type":65,"tag":161,"props":409,"children":410},{"style":316},[411],{"type":70,"value":412},"peer",{"type":65,"tag":161,"props":414,"children":415},{"style":185},[416],{"type":70,"value":100},{"type":65,"tag":161,"props":418,"children":419},{"style":185},[420],{"type":70,"value":300},{"type":65,"tag":161,"props":422,"children":424},{"class":163,"line":423},14,[425],{"type":65,"tag":161,"props":426,"children":427},{"style":279},[428],{"type":70,"value":429},"      // Use this hook to send messages to peer\n",{"type":65,"tag":161,"props":431,"children":433},{"class":163,"line":432},15,[434,439,444,449,453,458,463,468,472,477,481],{"type":65,"tag":161,"props":435,"children":436},{"style":174},[437],{"type":70,"value":438},"      peer",{"type":65,"tag":161,"props":440,"children":441},{"style":185},[442],{"type":70,"value":443},".",{"type":65,"tag":161,"props":445,"children":446},{"style":237},[447],{"type":70,"value":448},"send",{"type":65,"tag":161,"props":450,"children":451},{"style":257},[452],{"type":70,"value":245},{"type":65,"tag":161,"props":454,"children":455},{"style":185},[456],{"type":70,"value":457},"`",{"type":65,"tag":161,"props":459,"children":460},{"style":191},[461],{"type":70,"value":462},"Welcome ",{"type":65,"tag":161,"props":464,"children":465},{"style":185},[466],{"type":70,"value":467},"${",{"type":65,"tag":161,"props":469,"children":470},{"style":174},[471],{"type":70,"value":412},{"type":65,"tag":161,"props":473,"children":474},{"style":185},[475],{"type":70,"value":476},"}`",{"type":65,"tag":161,"props":478,"children":479},{"style":257},[480],{"type":70,"value":100},{"type":65,"tag":161,"props":482,"children":483},{"style":185},[484],{"type":70,"value":204},{"type":65,"tag":161,"props":486,"children":488},{"class":163,"line":487},16,[489],{"type":65,"tag":161,"props":490,"children":491},{"style":185},[492],{"type":70,"value":394},{"type":65,"tag":161,"props":494,"children":496},{"class":163,"line":495},17,[497,502,506,510,514,519,523],{"type":65,"tag":161,"props":498,"children":499},{"style":257},[500],{"type":70,"value":501},"    message",{"type":65,"tag":161,"props":503,"children":504},{"style":185},[505],{"type":70,"value":245},{"type":65,"tag":161,"props":507,"children":508},{"style":316},[509],{"type":70,"value":412},{"type":65,"tag":161,"props":511,"children":512},{"style":185},[513],{"type":70,"value":276},{"type":65,"tag":161,"props":515,"children":516},{"style":316},[517],{"type":70,"value":518}," message",{"type":65,"tag":161,"props":520,"children":521},{"style":185},[522],{"type":70,"value":100},{"type":65,"tag":161,"props":524,"children":525},{"style":185},[526],{"type":70,"value":300},{"type":65,"tag":161,"props":528,"children":530},{"class":163,"line":529},18,[531],{"type":65,"tag":161,"props":532,"children":533},{"style":279},[534],{"type":70,"value":535},"      // Accepting messages from peer (bidirectional mode)\n",{"type":65,"tag":161,"props":537,"children":539},{"class":163,"line":538},19,[540,545,549,554,558,562,567,571,575,580,585,589,594,598,602,607],{"type":65,"tag":161,"props":541,"children":542},{"style":174},[543],{"type":70,"value":544},"      console",{"type":65,"tag":161,"props":546,"children":547},{"style":185},[548],{"type":70,"value":443},{"type":65,"tag":161,"props":550,"children":551},{"style":237},[552],{"type":70,"value":553},"log",{"type":65,"tag":161,"props":555,"children":556},{"style":257},[557],{"type":70,"value":245},{"type":65,"tag":161,"props":559,"children":560},{"style":185},[561],{"type":70,"value":457},{"type":65,"tag":161,"props":563,"children":564},{"style":191},[565],{"type":70,"value":566},"Message from ",{"type":65,"tag":161,"props":568,"children":569},{"style":185},[570],{"type":70,"value":467},{"type":65,"tag":161,"props":572,"children":573},{"style":174},[574],{"type":70,"value":412},{"type":65,"tag":161,"props":576,"children":577},{"style":185},[578],{"type":70,"value":579},"}",{"type":65,"tag":161,"props":581,"children":582},{"style":191},[583],{"type":70,"value":584},": ",{"type":65,"tag":161,"props":586,"children":587},{"style":185},[588],{"type":70,"value":467},{"type":65,"tag":161,"props":590,"children":591},{"style":174},[592],{"type":70,"value":593},"message",{"type":65,"tag":161,"props":595,"children":596},{"style":185},[597],{"type":70,"value":476},{"type":65,"tag":161,"props":599,"children":600},{"style":257},[601],{"type":70,"value":100},{"type":65,"tag":161,"props":603,"children":604},{"style":185},[605],{"type":70,"value":606},";",{"type":65,"tag":161,"props":608,"children":609},{"style":279},[610],{"type":70,"value":611}," // Message from \u003Cid>: ping\n",{"type":65,"tag":161,"props":613,"children":615},{"class":163,"line":614},20,[616],{"type":65,"tag":161,"props":617,"children":618},{"style":185},[619],{"type":70,"value":394},{"type":65,"tag":161,"props":621,"children":623},{"class":163,"line":622},21,[624],{"type":65,"tag":161,"props":625,"children":626},{"style":185},[627],{"type":70,"value":628},"  },\n",{"type":65,"tag":161,"props":630,"children":632},{"class":163,"line":631},22,[633,637,641],{"type":65,"tag":161,"props":634,"children":635},{"style":185},[636],{"type":70,"value":579},{"type":65,"tag":161,"props":638,"children":639},{"style":174},[640],{"type":70,"value":100},{"type":65,"tag":161,"props":642,"children":643},{"style":185},[644],{"type":70,"value":204},{"type":65,"tag":66,"props":646,"children":647},{},[648],{"type":70,"value":649},"Inside your web server handler:",{"type":65,"tag":151,"props":651,"children":655},{"className":652,"code":653,"language":654,"meta":59,"style":59},"language-js shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","async fetch(request) {\n  // Handle crossws upgrade\n  if (\n    request.headers.get(\"accept\") === \"text/event-stream\" ||\n    request.headers.has(\"x-crossws-id\")\n  ) {\n    return ws.fetch(request);\n  }\n\n  // Your normal application logic\n  return new Response(\"default page\")\n}\n","js",[656],{"type":65,"tag":80,"props":657,"children":658},{"__ignoreMap":59},[659,680,688,701,772,818,830,867,875,882,890,929],{"type":65,"tag":161,"props":660,"children":661},{"class":163,"line":164},[662,667,671,676],{"type":65,"tag":161,"props":663,"children":664},{"style":174},[665],{"type":70,"value":666},"async ",{"type":65,"tag":161,"props":668,"children":669},{"style":237},[670],{"type":70,"value":85},{"type":65,"tag":161,"props":672,"children":673},{"style":174},[674],{"type":70,"value":675},"(request) ",{"type":65,"tag":161,"props":677,"children":678},{"style":185},[679],{"type":70,"value":250},{"type":65,"tag":161,"props":681,"children":682},{"class":163,"line":207},[683],{"type":65,"tag":161,"props":684,"children":685},{"style":279},[686],{"type":70,"value":687},"  // Handle crossws upgrade\n",{"type":65,"tag":161,"props":689,"children":690},{"class":163,"line":217},[691,696],{"type":65,"tag":161,"props":692,"children":693},{"style":168},[694],{"type":70,"value":695},"  if",{"type":65,"tag":161,"props":697,"children":698},{"style":257},[699],{"type":70,"value":700}," (\n",{"type":65,"tag":161,"props":702,"children":703},{"class":163,"line":253},[704,709,713,718,722,727,731,735,740,744,749,754,758,763,767],{"type":65,"tag":161,"props":705,"children":706},{"style":174},[707],{"type":70,"value":708},"    request",{"type":65,"tag":161,"props":710,"children":711},{"style":185},[712],{"type":70,"value":443},{"type":65,"tag":161,"props":714,"children":715},{"style":174},[716],{"type":70,"value":717},"headers",{"type":65,"tag":161,"props":719,"children":720},{"style":185},[721],{"type":70,"value":443},{"type":65,"tag":161,"props":723,"children":724},{"style":237},[725],{"type":70,"value":726},"get",{"type":65,"tag":161,"props":728,"children":729},{"style":257},[730],{"type":70,"value":245},{"type":65,"tag":161,"props":732,"children":733},{"style":185},[734],{"type":70,"value":199},{"type":65,"tag":161,"props":736,"children":737},{"style":191},[738],{"type":70,"value":739},"accept",{"type":65,"tag":161,"props":741,"children":742},{"style":185},[743],{"type":70,"value":199},{"type":65,"tag":161,"props":745,"children":746},{"style":257},[747],{"type":70,"value":748},") ",{"type":65,"tag":161,"props":750,"children":751},{"style":185},[752],{"type":70,"value":753},"===",{"type":65,"tag":161,"props":755,"children":756},{"style":185},[757],{"type":70,"value":188},{"type":65,"tag":161,"props":759,"children":760},{"style":191},[761],{"type":70,"value":762},"text/event-stream",{"type":65,"tag":161,"props":764,"children":765},{"style":185},[766],{"type":70,"value":199},{"type":65,"tag":161,"props":768,"children":769},{"style":185},[770],{"type":70,"value":771}," ||\n",{"type":65,"tag":161,"props":773,"children":774},{"class":163,"line":285},[775,779,783,787,791,796,800,804,809,813],{"type":65,"tag":161,"props":776,"children":777},{"style":174},[778],{"type":70,"value":708},{"type":65,"tag":161,"props":780,"children":781},{"style":185},[782],{"type":70,"value":443},{"type":65,"tag":161,"props":784,"children":785},{"style":174},[786],{"type":70,"value":717},{"type":65,"tag":161,"props":788,"children":789},{"style":185},[790],{"type":70,"value":443},{"type":65,"tag":161,"props":792,"children":793},{"style":237},[794],{"type":70,"value":795},"has",{"type":65,"tag":161,"props":797,"children":798},{"style":257},[799],{"type":70,"value":245},{"type":65,"tag":161,"props":801,"children":802},{"style":185},[803],{"type":70,"value":199},{"type":65,"tag":161,"props":805,"children":806},{"style":191},[807],{"type":70,"value":808},"x-crossws-id",{"type":65,"tag":161,"props":810,"children":811},{"style":185},[812],{"type":70,"value":199},{"type":65,"tag":161,"props":814,"children":815},{"style":257},[816],{"type":70,"value":817},")\n",{"type":65,"tag":161,"props":819,"children":820},{"class":163,"line":303},[821,826],{"type":65,"tag":161,"props":822,"children":823},{"style":257},[824],{"type":70,"value":825},"  ) ",{"type":65,"tag":161,"props":827,"children":828},{"style":185},[829],{"type":70,"value":250},{"type":65,"tag":161,"props":831,"children":832},{"class":163,"line":330},[833,838,843,847,851,855,859,863],{"type":65,"tag":161,"props":834,"children":835},{"style":168},[836],{"type":70,"value":837},"    return",{"type":65,"tag":161,"props":839,"children":840},{"style":174},[841],{"type":70,"value":842}," ws",{"type":65,"tag":161,"props":844,"children":845},{"style":185},[846],{"type":70,"value":443},{"type":65,"tag":161,"props":848,"children":849},{"style":237},[850],{"type":70,"value":85},{"type":65,"tag":161,"props":852,"children":853},{"style":257},[854],{"type":70,"value":245},{"type":65,"tag":161,"props":856,"children":857},{"style":174},[858],{"type":70,"value":319},{"type":65,"tag":161,"props":860,"children":861},{"style":257},[862],{"type":70,"value":100},{"type":65,"tag":161,"props":864,"children":865},{"style":185},[866],{"type":70,"value":204},{"type":65,"tag":161,"props":868,"children":869},{"class":163,"line":339},[870],{"type":65,"tag":161,"props":871,"children":872},{"style":185},[873],{"type":70,"value":874},"  }\n",{"type":65,"tag":161,"props":876,"children":877},{"class":163,"line":348},[878],{"type":65,"tag":161,"props":879,"children":880},{"emptyLinePlaceholder":211},[881],{"type":70,"value":214},{"type":65,"tag":161,"props":883,"children":884},{"class":163,"line":361},[885],{"type":65,"tag":161,"props":886,"children":887},{"style":279},[888],{"type":70,"value":889},"  // Your normal application logic\n",{"type":65,"tag":161,"props":891,"children":892},{"class":163,"line":379},[893,898,903,908,912,916,921,925],{"type":65,"tag":161,"props":894,"children":895},{"style":168},[896],{"type":70,"value":897},"  return",{"type":65,"tag":161,"props":899,"children":900},{"style":185},[901],{"type":70,"value":902}," new",{"type":65,"tag":161,"props":904,"children":905},{"style":237},[906],{"type":70,"value":907}," Response",{"type":65,"tag":161,"props":909,"children":910},{"style":257},[911],{"type":70,"value":245},{"type":65,"tag":161,"props":913,"children":914},{"style":185},[915],{"type":70,"value":199},{"type":65,"tag":161,"props":917,"children":918},{"style":191},[919],{"type":70,"value":920},"default page",{"type":65,"tag":161,"props":922,"children":923},{"style":185},[924],{"type":70,"value":199},{"type":65,"tag":161,"props":926,"children":927},{"style":257},[928],{"type":70,"value":817},{"type":65,"tag":161,"props":930,"children":931},{"class":163,"line":388},[932],{"type":65,"tag":161,"props":933,"children":934},{"style":185},[935],{"type":70,"value":936},"}\n",{"type":65,"tag":130,"props":938,"children":940},{"id":939},"client-side",[941],{"type":70,"value":942},"Client side",{"type":65,"tag":66,"props":944,"children":945},{},[946,948,953],{"type":70,"value":947},"In order to make communication with server, we need a special ",{"type":65,"tag":80,"props":949,"children":951},{"className":950},[],[952],{"type":70,"value":119},{"type":70,"value":954}," client.",{"type":65,"tag":151,"props":956,"children":958},{"className":652,"code":957,"language":654,"meta":59,"style":59},"import { WebsocketSSE } from \"crossws/websocket/sse\";\n\nconst ws = new WebsocketSSE(\"https://\u003Cserver_address>\", { bdir: true });\n\nws.addEventListener(\"open\", () => {\n  ws.send(\"ping\");\n});\n\nws.addEventListener(\"message\", (event) => {\n  console.log(\"Received:\", event.data);\n});\n",[959],{"type":65,"tag":80,"props":960,"children":961},{"__ignoreMap":59},[962,1006,1013,1086,1093,1145,1186,1201,1208,1265,1324],{"type":65,"tag":161,"props":963,"children":964},{"class":163,"line":164},[965,969,974,979,984,989,993,998,1002],{"type":65,"tag":161,"props":966,"children":967},{"style":168},[968],{"type":70,"value":171},{"type":65,"tag":161,"props":970,"children":971},{"style":185},[972],{"type":70,"value":973}," {",{"type":65,"tag":161,"props":975,"children":976},{"style":174},[977],{"type":70,"value":978}," WebsocketSSE",{"type":65,"tag":161,"props":980,"children":981},{"style":185},[982],{"type":70,"value":983}," }",{"type":65,"tag":161,"props":985,"children":986},{"style":168},[987],{"type":70,"value":988}," from",{"type":65,"tag":161,"props":990,"children":991},{"style":185},[992],{"type":70,"value":188},{"type":65,"tag":161,"props":994,"children":995},{"style":191},[996],{"type":70,"value":997},"crossws/websocket/sse",{"type":65,"tag":161,"props":999,"children":1000},{"style":185},[1001],{"type":70,"value":199},{"type":65,"tag":161,"props":1003,"children":1004},{"style":185},[1005],{"type":70,"value":204},{"type":65,"tag":161,"props":1007,"children":1008},{"class":163,"line":207},[1009],{"type":65,"tag":161,"props":1010,"children":1011},{"emptyLinePlaceholder":211},[1012],{"type":70,"value":214},{"type":65,"tag":161,"props":1014,"children":1015},{"class":163,"line":217},[1016,1020,1024,1028,1032,1036,1040,1044,1049,1053,1057,1061,1066,1070,1074,1078,1082],{"type":65,"tag":161,"props":1017,"children":1018},{"style":221},[1019],{"type":70,"value":224},{"type":65,"tag":161,"props":1021,"children":1022},{"style":174},[1023],{"type":70,"value":229},{"type":65,"tag":161,"props":1025,"children":1026},{"style":185},[1027],{"type":70,"value":234},{"type":65,"tag":161,"props":1029,"children":1030},{"style":185},[1031],{"type":70,"value":902},{"type":65,"tag":161,"props":1033,"children":1034},{"style":237},[1035],{"type":70,"value":978},{"type":65,"tag":161,"props":1037,"children":1038},{"style":174},[1039],{"type":70,"value":245},{"type":65,"tag":161,"props":1041,"children":1042},{"style":185},[1043],{"type":70,"value":199},{"type":65,"tag":161,"props":1045,"children":1046},{"style":191},[1047],{"type":70,"value":1048},"https://\u003Cserver_address>",{"type":65,"tag":161,"props":1050,"children":1051},{"style":185},[1052],{"type":70,"value":199},{"type":65,"tag":161,"props":1054,"children":1055},{"style":185},[1056],{"type":70,"value":276},{"type":65,"tag":161,"props":1058,"children":1059},{"style":185},[1060],{"type":70,"value":973},{"type":65,"tag":161,"props":1062,"children":1063},{"style":257},[1064],{"type":70,"value":1065}," bdir",{"type":65,"tag":161,"props":1067,"children":1068},{"style":185},[1069],{"type":70,"value":265},{"type":65,"tag":161,"props":1071,"children":1072},{"style":268},[1073],{"type":70,"value":271},{"type":65,"tag":161,"props":1075,"children":1076},{"style":185},[1077],{"type":70,"value":983},{"type":65,"tag":161,"props":1079,"children":1080},{"style":174},[1081],{"type":70,"value":100},{"type":65,"tag":161,"props":1083,"children":1084},{"style":185},[1085],{"type":70,"value":204},{"type":65,"tag":161,"props":1087,"children":1088},{"class":163,"line":253},[1089],{"type":65,"tag":161,"props":1090,"children":1091},{"emptyLinePlaceholder":211},[1092],{"type":70,"value":214},{"type":65,"tag":161,"props":1094,"children":1095},{"class":163,"line":285},[1096,1101,1105,1110,1114,1118,1123,1127,1131,1136,1141],{"type":65,"tag":161,"props":1097,"children":1098},{"style":174},[1099],{"type":70,"value":1100},"ws",{"type":65,"tag":161,"props":1102,"children":1103},{"style":185},[1104],{"type":70,"value":443},{"type":65,"tag":161,"props":1106,"children":1107},{"style":237},[1108],{"type":70,"value":1109},"addEventListener",{"type":65,"tag":161,"props":1111,"children":1112},{"style":174},[1113],{"type":70,"value":245},{"type":65,"tag":161,"props":1115,"children":1116},{"style":185},[1117],{"type":70,"value":199},{"type":65,"tag":161,"props":1119,"children":1120},{"style":191},[1121],{"type":70,"value":1122},"open",{"type":65,"tag":161,"props":1124,"children":1125},{"style":185},[1126],{"type":70,"value":199},{"type":65,"tag":161,"props":1128,"children":1129},{"style":185},[1130],{"type":70,"value":276},{"type":65,"tag":161,"props":1132,"children":1133},{"style":185},[1134],{"type":70,"value":1135}," ()",{"type":65,"tag":161,"props":1137,"children":1138},{"style":221},[1139],{"type":70,"value":1140}," =>",{"type":65,"tag":161,"props":1142,"children":1143},{"style":185},[1144],{"type":70,"value":300},{"type":65,"tag":161,"props":1146,"children":1147},{"class":163,"line":303},[1148,1153,1157,1161,1165,1169,1174,1178,1182],{"type":65,"tag":161,"props":1149,"children":1150},{"style":174},[1151],{"type":70,"value":1152},"  ws",{"type":65,"tag":161,"props":1154,"children":1155},{"style":185},[1156],{"type":70,"value":443},{"type":65,"tag":161,"props":1158,"children":1159},{"style":237},[1160],{"type":70,"value":448},{"type":65,"tag":161,"props":1162,"children":1163},{"style":257},[1164],{"type":70,"value":245},{"type":65,"tag":161,"props":1166,"children":1167},{"style":185},[1168],{"type":70,"value":199},{"type":65,"tag":161,"props":1170,"children":1171},{"style":191},[1172],{"type":70,"value":1173},"ping",{"type":65,"tag":161,"props":1175,"children":1176},{"style":185},[1177],{"type":70,"value":199},{"type":65,"tag":161,"props":1179,"children":1180},{"style":257},[1181],{"type":70,"value":100},{"type":65,"tag":161,"props":1183,"children":1184},{"style":185},[1185],{"type":70,"value":204},{"type":65,"tag":161,"props":1187,"children":1188},{"class":163,"line":330},[1189,1193,1197],{"type":65,"tag":161,"props":1190,"children":1191},{"style":185},[1192],{"type":70,"value":579},{"type":65,"tag":161,"props":1194,"children":1195},{"style":174},[1196],{"type":70,"value":100},{"type":65,"tag":161,"props":1198,"children":1199},{"style":185},[1200],{"type":70,"value":204},{"type":65,"tag":161,"props":1202,"children":1203},{"class":163,"line":339},[1204],{"type":65,"tag":161,"props":1205,"children":1206},{"emptyLinePlaceholder":211},[1207],{"type":70,"value":214},{"type":65,"tag":161,"props":1209,"children":1210},{"class":163,"line":348},[1211,1215,1219,1223,1227,1231,1235,1239,1243,1248,1253,1257,1261],{"type":65,"tag":161,"props":1212,"children":1213},{"style":174},[1214],{"type":70,"value":1100},{"type":65,"tag":161,"props":1216,"children":1217},{"style":185},[1218],{"type":70,"value":443},{"type":65,"tag":161,"props":1220,"children":1221},{"style":237},[1222],{"type":70,"value":1109},{"type":65,"tag":161,"props":1224,"children":1225},{"style":174},[1226],{"type":70,"value":245},{"type":65,"tag":161,"props":1228,"children":1229},{"style":185},[1230],{"type":70,"value":199},{"type":65,"tag":161,"props":1232,"children":1233},{"style":191},[1234],{"type":70,"value":593},{"type":65,"tag":161,"props":1236,"children":1237},{"style":185},[1238],{"type":70,"value":199},{"type":65,"tag":161,"props":1240,"children":1241},{"style":185},[1242],{"type":70,"value":276},{"type":65,"tag":161,"props":1244,"children":1245},{"style":185},[1246],{"type":70,"value":1247}," (",{"type":65,"tag":161,"props":1249,"children":1250},{"style":316},[1251],{"type":70,"value":1252},"event",{"type":65,"tag":161,"props":1254,"children":1255},{"style":185},[1256],{"type":70,"value":100},{"type":65,"tag":161,"props":1258,"children":1259},{"style":221},[1260],{"type":70,"value":1140},{"type":65,"tag":161,"props":1262,"children":1263},{"style":185},[1264],{"type":70,"value":300},{"type":65,"tag":161,"props":1266,"children":1267},{"class":163,"line":361},[1268,1273,1277,1281,1285,1289,1294,1298,1302,1307,1311,1316,1320],{"type":65,"tag":161,"props":1269,"children":1270},{"style":174},[1271],{"type":70,"value":1272},"  console",{"type":65,"tag":161,"props":1274,"children":1275},{"style":185},[1276],{"type":70,"value":443},{"type":65,"tag":161,"props":1278,"children":1279},{"style":237},[1280],{"type":70,"value":553},{"type":65,"tag":161,"props":1282,"children":1283},{"style":257},[1284],{"type":70,"value":245},{"type":65,"tag":161,"props":1286,"children":1287},{"style":185},[1288],{"type":70,"value":199},{"type":65,"tag":161,"props":1290,"children":1291},{"style":191},[1292],{"type":70,"value":1293},"Received:",{"type":65,"tag":161,"props":1295,"children":1296},{"style":185},[1297],{"type":70,"value":199},{"type":65,"tag":161,"props":1299,"children":1300},{"style":185},[1301],{"type":70,"value":276},{"type":65,"tag":161,"props":1303,"children":1304},{"style":174},[1305],{"type":70,"value":1306}," event",{"type":65,"tag":161,"props":1308,"children":1309},{"style":185},[1310],{"type":70,"value":443},{"type":65,"tag":161,"props":1312,"children":1313},{"style":174},[1314],{"type":70,"value":1315},"data",{"type":65,"tag":161,"props":1317,"children":1318},{"style":257},[1319],{"type":70,"value":100},{"type":65,"tag":161,"props":1321,"children":1322},{"style":185},[1323],{"type":70,"value":204},{"type":65,"tag":161,"props":1325,"children":1326},{"class":163,"line":379},[1327,1331,1335],{"type":65,"tag":161,"props":1328,"children":1329},{"style":185},[1330],{"type":70,"value":579},{"type":65,"tag":161,"props":1332,"children":1333},{"style":174},[1334],{"type":70,"value":100},{"type":65,"tag":161,"props":1336,"children":1337},{"style":185},[1338],{"type":70,"value":204},{"type":65,"tag":137,"props":1340,"children":1341},{},[1342],{"type":65,"tag":66,"props":1343,"children":1344},{},[1345,1347,1353,1355,1364,1366,1375,1377,1384],{"type":70,"value":1346},"\nBehind the scenes, ",{"type":65,"tag":80,"props":1348,"children":1350},{"className":1349},[],[1351],{"type":70,"value":1352},"WebSocketSSE",{"type":70,"value":1354},", uses ",{"type":65,"tag":73,"props":1356,"children":1358},{"href":90,"rel":1357},[77],[1359],{"type":65,"tag":80,"props":1360,"children":1362},{"className":1361},[],[1363],{"type":70,"value":98},{"type":70,"value":1365}," to receive messages from server. In order to send messages to the server, it tries to make another connection stream using same peer id and if failed, fallback to ",{"type":65,"tag":73,"props":1367,"children":1369},{"href":75,"rel":1368},[77],[1370],{"type":65,"tag":80,"props":1371,"children":1373},{"className":1372},[],[1374],{"type":70,"value":85},{"type":70,"value":1376}," for each message.\nIn theory, it is possible to have communication on a single HTTP/2 connection, however, due to a ",{"type":65,"tag":73,"props":1378,"children":1381},{"href":1379,"rel":1380},"https://github.com/whatwg/fetch/issues/1254",[77],[1382],{"type":70,"value":1383},"current limitation in fetch standard",{"type":70,"value":1385}," we need 2 connections, one for receiving messages and one for sending.",{"type":65,"tag":1387,"props":1388,"children":1389},"read-more",{},[1390],{"type":65,"tag":66,"props":1391,"children":1392},{},[1393,1395,1406,1408,1419],{"type":70,"value":1394},"See ",{"type":65,"tag":73,"props":1396,"children":1399},{"href":1397,"rel":1398},"https://github.com/h3js/crossws/blob/main/test/fixture/sse.ts",[77],[1400],{"type":65,"tag":80,"props":1401,"children":1403},{"className":1402},[],[1404],{"type":70,"value":1405},"test/fixture/sse.ts",{"type":70,"value":1407}," for demo and ",{"type":65,"tag":73,"props":1409,"children":1412},{"href":1410,"rel":1411},"https://github.com/h3js/crossws/blob/main/src/adapters/sse.ts",[77],[1413],{"type":65,"tag":80,"props":1414,"children":1416},{"className":1415},[],[1417],{"type":70,"value":1418},"src/adapters/sse.ts",{"type":70,"value":1420}," for implementation.",{"type":65,"tag":1422,"props":1423,"children":1424},"style",{},[1425],{"type":70,"value":1426},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":59,"searchDepth":207,"depth":207,"links":1428},[1429],{"id":125,"depth":207,"text":128,"children":1430},[1431,1432],{"id":132,"depth":217,"text":135},{"id":939,"depth":217,"text":942},"markdown","content:2.adapters:sse.md","content","2.adapters/sse.md","2.adapters/sse","md",[1440,1442],{"_path":50,"title":49,"description":1441},"Integrate crossws with Node.js using ws or uWebSockets.js",null,1747776031391]