D
Deno

help

Server Sent Events with Fresh

Nnotiggsam4/6/2023
Hi! I am trying to use Server Sent Events (SSE) with fresh. I understand I should have an island that holds the connection to the server but how can I broadcast the notifications to other islands?
UUUnknown User4/6/2023
Message Not Public
Sign In & Join Server To View
Nnotiggsam4/6/2023
My question was about client-side with Fresh's islands. On server side you don't need any particular support, as it is plain HTTP. You just have to stream your events with content-type: text/event-stream
ABAltair 680b4/6/2023
Client side would use an EventSource to subscribe to the stream, and POST to the server to publish messages. When you say other islands, do you mean other islands in the same browser tab, or other instances of the Deploy isolate, or other instances of the same deploy isolate in different browser tab? If same tab, just us browser BroadcastChannel. If different isolates, use Deno BroadcastChannel on the server.
ABAltair 680b4/6/2023
The following api code uses SSE + BroadcastChannel as a WRTC signalling service to connect two players over a WebRTC-Datachannel. https://github.com/nhrones/FreshDiceRTC/tree/master/routes/api
Nnotiggsam4/9/2023
Thank you @ndh3193 ! I would never have thought about using BroadcastChannel, I will definitely try it. My use case was different islands in the same tab.
𝕒𝕣𝕤𝕙4/11/2023
there's no standard for a server-side api
IioB4/11/2023
There's nothing super special about the SSE api. It looks like skye made a polyfill at https://deno.land/x/eventsource
𝕒𝕣𝕤𝕙4/11/2023
yep it's just a ReadableStream i made a stream-like abstraction for it
const readableStream = serverSentEvents(async sendEvent => {
sendEvent('message one')
...
sendEvent('message two')
sendEvent(0)
})
const readableStream = serverSentEvents(async sendEvent => {
sendEvent('message one')
...
sendEvent('message two')
sendEvent(0)
})
worth noting this allows deno to read a SSE from another server, like the Web API, rather create and send its own

Looking for more? Join the community!

Recommended Posts
Twind intellisense stop workingOut of the blue, intellisense stopped working even though I installed the twind and deno extensions How use namespace on Denoi am trying to use the same namespace in multiple modules but what used to work in node, doesn't worRestart Deno process on crashHello, The following Node snippet allows a script to restart on crash : ```js import { spawn } fbest practice when spawning commands that require sudo?I am building a command line utility in deno that leverages data coming from `tcpdump`. To get any mChaining Tasks and using --watchIs there a way to chain Deno tasks or something to that accord? I'd like to run esbuild from the comHow to setup deno for Lunarvim?I've followed the steps to install the LSP for deno, but the completion and formatter doesn't work Unexpected token 'export' (deno_core)Playing around with ModuleLoaders, but doesn't seem to make a difference Scripts containing the expglobal is not definedWhy Deno doesn't have global like node.js? There is globalThis, but some things from npm packages arUsing querySelector on NodeI am doing something like: ```ts const nodeList: NodeList = document.querySelectorAll(".foo"); constSimpler way to read a file relative to current module?So I wrote a little helper function for reading the text content of a file relative to the current merror: BadResource: Bad resource IDI'm writing tests for https://github.com/deno-libs/tinyhttp/pull/9. ```js import { describe, expectRecent deployment not working?Hi there I have an api that was working just fine not sure what happen but new deployments are not wHow do you get the path to a file relative to the module which is referencing it?```ts const GET_PROGRAM_QUERY = Deno.readFileSync("./GetProgram.gql"); ``` GetProgram.gql is a fileInvestigating memory leak after adding new app dependencyHi, I added an OpenTelemetry metrics reporting loop to a Deno program and found that Deno began leakVScode deno lint blew up again after update.It seems every time there's an extension update VScode lint blows up and will stop recognizing top limport cache not workingI can't install cache of my http imports:Why isn't this error caught?Basic code example: ``` try { Deno.remove("fakefile"); } catch (err) { console.log("File doesn'tUsing dynamic import with npm compatibility gives intermittent error "__DENO_NODE_GLOBAL_THIS_167935This is pretty hard to google because the number at the end of the error changes everytime it happenGraphql codegendoes anyone have a solution to generate the sdk using graphq-request with Deno?Deno Third Party Modules Web HooksIs there a way to see the webhook payload URL a package you have published is listening for?