import { type ServerSentEventTarget } from "https://deno.land/x/capi@v0.1.1-beta.1/deps/std/http.ts";
Methods
Send a comment to the remote connection. Comments are not exposed to the
client EventSource
but are used for diagnostics and helping ensure a
connection is kept alive.
import { ServerSentEventStreamTarget } from "https://deno.land/std@0.224.0/http/server_sent_event.ts";
import { serve } from "https://deno.land/std@0.224.0/http/server.ts";
await serve((request) => {
const target = new ServerSentEventStreamTarget();
target.dispatchComment("this is a comment");
return target.asResponse();
}, { port: 8000 });
Dispatch a message to the client. This message will contain data:
only
and be available on the client EventSource
on the onmessage
or an event
listener of type "message"
.
Dispatch a server sent event to the client. The event type
will be
sent as event:
to the client which will be raised as a MessageEvent
on the EventSource
in the client.
Any local event handlers will be dispatched to first, and if the event is cancelled, it will not be sent to the client.
import {
ServerSentEvent,
ServerSentEventStreamTarget,
} from "https://deno.land/std@0.224.0/http/server_sent_event.ts";
import { serve } from "https://deno.land/std@0.224.0/http/server.ts";
await serve((request) => {
const target = new ServerSentEventStreamTarget();
const evt = new ServerSentEvent("ping", { data: "hello" });
target.dispatchEvent(evt);
return target.asResponse();
}, { port: 8000 });
Dispatch a server sent event to the client. The event type
will be
sent as event:
to the client which will be raised as a MessageEvent
on the EventSource
in the client.
Any local event handlers will be dispatched to first, and if the event is cancelled, it will not be sent to the client.
import {
ServerSentEvent,
ServerSentEventStreamTarget,
} from "https://deno.land/std@0.224.0/http/server_sent_event.ts";
import { serve } from "https://deno.land/std@0.224.0/http/server.ts";
await serve((request) => {
const target = new ServerSentEventStreamTarget();
const evt = new ServerSentEvent("ping", { data: "hello" });
target.dispatchEvent(evt);
return target.asResponse();
}, { port: 8000 });