@ghostebony/sse
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

@ghostebony/sse

⚠️ New releases

New versions were released under the next release tag. Install it for new features and bug fixes.

Installation

With npm:

npm i @ghostebony/sse@next

With yarn:

yarn add @ghostebony/sse@next

With pnpm:

pnpm add @ghostebony/sse@next

@next docs


v0.1.4 Examples

SvelteKit

client

src/routes/+(page|layout).svelte

<script lang="ts">
    import { onDestroy, onMount } from "svelte";
    import { Client } from "@ghostebony/sse/client";

    let eventSource: Client;

    onMount(() => {
        eventSource = new Client({
            source: { url: "/sse" },
            listeners: [
                {
                    channel: "custom-channel",
                    listener: ({ data }) => {
                        console.log(data);
                    },
                    parseJson: true,
                }
            ],
        });
    });

    onDestroy(() => eventSource?.close());
</script>

server

src/routes/sse/+server.ts

import { ServerManager } from "@ghostebony/sse/server";
import type { RequestHandler } from "./$types";

const sse = ServerManager.addRoom("custom-room");

export const GET: RequestHandler = (event) =>
	sse.server(event.getClientAddress() /* or user id */, {
		connect: ({ user }) => {
			// DO SOMETHING
		},
		disconnect: ({ user }) => {
			// DO SOMETHING
		},
	});

somewhere on the server

import { ServerManager } from "@ghostebony/sse/server";

ServerManager.sendRoom(
	"custom-room",
	clientAddress /* or user id */,
	1, // message id
	"custom-channel", // channel that you're listening
	data, // message data
);

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.40latest
1.0.0-next.101next

Version History

VersionDownloads (Last 7 Days)Published
1.0.0-next.101
1.0.0-next.90
1.0.0-next.80
1.0.0-next.70
1.0.0-next.60
0.1.40
1.0.0-next.40
1.0.0-next.30
1.0.0-next.20
1.0.0-next.10
1.0.0-next.00
0.1.30
0.1.20
0.1.00
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i @ghostebony/sse

Weekly Downloads

1

Version

0.1.4

License

MIT

Unpacked Size

11.3 kB

Total Files

11

Last publish

Collaborators

  • ghostebony