x/oak/mod.ts

A middleware framework for handling HTTP with Deno 🐿️ 🦕
Very Popular
Go to Latest
class ServerSentEvent
extends Event
import { ServerSentEvent } from "https://dotland-vbqsvsrpfncg.deno-staging.dev/x/oak@v11.1.0/mod.ts?p=prototype.all&s=ServerSentEvent";

An event which contains information which will be sent to the remote connection and be made available in an EventSource as an event. A server creates new events and dispatches them on the target which will then be sent to a client.

See more about Server-sent events on MDN

Example

import { Application, ServerSentEvent } from "https://deno.land/x/oak/mod.ts";

const app = new Application();

app.use((ctx) => {
  const target = ctx.sendEvents();
  const evt = new ServerSentEvent(
    "message",
    { hello: "world" },
    { id: 1 },
  );
  target.dispatchEvent(evt);
});

Constructors

new
ServerSentEvent(
type: string,
data: unknown,
eventInit?: ServerSentEventInit,
)
[src]

Properties

readonly
data: string
[src]

The data associated with the event, which will be sent to the client and be made available in the EventSource.

readonly
id: number | undefined
[src]

The optional ID associated with the event that will be sent to the client and be made available in the EventSource.