0.0.14 • Published 21 days ago

party.io v0.0.14

Weekly downloads
-
License
ISC
Repository
github
Last release
21 days ago

🎈 Party.IO

Socket.IO server for PartyKit

NB: Experimental!!!

An implementation of the Socket.IO protocol for PartyKit. Based on the incredible work by @darrachequesne at https://github.com/socketio/socket.io-deno/

Table of contents:

Usage

// server.ts

import { createServer } from "party.io";

export default createServer((io) => {
  io.on("connection", (socket) => {
    console.log(`socket ${socket.id} connected`);

    socket.emit("hello", "world");

    socket.on("howdy", (data) => {
      console.log(`socket ${socket.id} says ${data}`);
    });

    socket.on("disconnect", (reason) => {
      console.log(`socket ${socket.id} disconnected due to ${reason}`);
    });
  });
});

In your browser, you can connect to the server with:

// client.ts

import { io } from "socket.io-client";

const socket = io({
  transports: ["websocket"]
});

socket.on("hello", (data) => {
  console.log(`server says ${data}`);
  // => server says world
});

socket.emit("howdy", "y'all");

And then run with:

partykit dev server.ts

Like the Node.js server, you can also provide types for the events sent between the server and the clients:

interface ClientToServerEvents {
  hello: () => void;
}

interface ServerToClientEvents {
  noArg: () => void;
  basicEmit: (a: number, b: string, c: Buffer) => void;
  withAck: (d: string, callback: (e: number) => void) => void;
}

interface InterServerEvents {
  ping: () => void;
}

interface SocketData {
  user_id: string;
}

export default createServer<
  ClientToServerEvents,
  ServerToClientEvents,
  InterServerEvents,
  SocketData
>((io) => {
  // ...
});

How does it work

TODO

Options

path

Default value: /socket.io/

It is the name of the path that is captured on the server side.

Caution! The server and the client values must match (unless you are using a path-rewriting proxy in between).

Example:

export default createServer(
  {
    path: "/my-custom-path/"
  },
  (io) => {
    // ...
  }
);

connectTimeout

Default value: 45000

The number of ms before disconnecting a client that has not successfully joined a namespace.

pingTimeout

Default value: 20000

This value is used in the heartbeat mechanism, which periodically checks if the connection is still alive between the server and the client.

The server sends a ping, and if the client does not answer with a pong within pingTimeout ms, the server considers that the connection is closed.

Similarly, if the client does not receive a ping from the server within pingInterval + pingTimeout ms, the client also considers that the connection is closed.

pingInterval

Default value: 25000

See pingTimeout for more explanation.

upgradeTimeout

Default value: 10000

This is the delay in milliseconds before an uncompleted transport upgrade is cancelled.

maxHttpBufferSize

Default value: 1e6 (1 MB)

This defines how many bytes a single message can be, before closing the socket. You may increase or decrease this value depending on your needs.

allowRequest

Default value: -

A function that receives a given handshake or upgrade request as its first parameter, and can decide whether to continue or not.

Example:

export default createServer(
  {
    allowRequest: (req, lobby, ctx) => {
      return Promise.reject("thou shall not pass");
    }
  },
  (io) => {
    // ...
  }
);

cors

Default value: -

A set of options related to Cross-Origin Resource Sharing (CORS).

Example:

export default createServer(
  {
    cors: {
      origin: ["https://example.com"],
      allowedHeaders: ["my-header"],
      credentials: true
    }
  },
  (io) => {
    // ...
  }
);

editHandshakeHeaders

Default value: -

A function that allows to edit the response headers of the handshake request.

Example:

export default createServer(
  {
    editHandshakeHeaders: (responseHeaders, req, lobby, ctx) => {
      responseHeaders.set("set-cookie", "sid=1234");
    }
  },
  (io) => {
    // ...
  }
);

editResponseHeaders

Default value: -

A function that allows to edit the response headers of all requests.

Example:

export default createServer(
  {
    editResponseHeaders: (responseHeaders, req, lobby, ctx) => {
      responseHeaders.set("my-header", "abcd");
    }
  },
  (io) => {
    // ...
  }
);

Logs

// TODO:

License

ISC

0.0.0-2f7a2e6

21 days ago

0.0.0-16ec02f

21 days ago

0.0.0-8f5800c

24 days ago

0.0.0-83fec4f

23 days ago

0.0.0-634725e

29 days ago

0.0.0-b337e86

30 days ago

0.0.0-8d27fcb

1 month ago

0.0.0-19379aa

1 month ago

0.0.0-4c435c2

1 month ago

0.0.0-1b06f14

1 month ago

0.0.0-aef1adf

1 month ago

0.0.0-608d6f6

1 month ago

0.0.0-483095c

1 month ago

0.0.0-3abd989

1 month ago

0.0.0-7275433

1 month ago

0.0.0-085bb8f

1 month ago

0.0.14

1 month ago

0.0.0-379b7b5

1 month ago

0.0.0-f2e8f6f

1 month ago

0.0.0-949f8a5

1 month ago

0.0.0-479e6b5

2 months ago

0.0.0-16045ba

2 months ago

0.0.0-01f311d

2 months ago

0.0.0-19c27dc

2 months ago

0.0.0-77a7e73

2 months ago

0.0.0-a7531e3

2 months ago

0.0.13

2 months ago

0.0.0-60ead9c

2 months ago

0.0.0-b00061a

2 months ago

0.0.0-5b70636

2 months ago

0.0.0-515aec2

2 months ago

0.0.0-32f881b

2 months ago

0.0.0-274179a

2 months ago

0.0.0-86840f2

2 months ago

0.0.0-f15d9e2

2 months ago

0.0.0-1905f70

2 months ago

0.0.0-d2a0ac5

2 months ago

0.0.0-1c4c3b3

2 months ago

0.0.0-9b4a1ed

2 months ago

0.0.0-f897bac

2 months ago

0.0.0-6c2256f

2 months ago

0.0.0-e135cc6

2 months ago

0.0.0-c3f0ba9

2 months ago

0.0.0-4e039c8

2 months ago

0.0.0-30117ab

2 months ago

0.0.0-8ffc6c5

2 months ago

0.0.0-b799677

2 months ago

0.0.0-a6c868c

3 months ago

0.0.0-b159f03

3 months ago

0.0.0-d38bd27

3 months ago

0.0.0-c6c4317

3 months ago

0.0.0-122c480

3 months ago

0.0.0-d54d23a

3 months ago

0.0.0-16c22b9

3 months ago

0.0.12

3 months ago

0.0.0-2bc85ab

3 months ago

0.0.0-ae19a84

3 months ago

0.0.0-125660

3 months ago

0.0.0-b2d06df

3 months ago

0.0.0-f448798

3 months ago

0.0.0-4b85c68

3 months ago

0.0.0-d50c04b

3 months ago

0.0.0-fda7510

3 months ago

0.0.0-135094a

3 months ago

0.0.0-c2bf581

3 months ago

0.0.0-b097ea8

3 months ago

0.0.0-4e3050e

3 months ago

0.0.0-1083ef9

3 months ago

0.0.0-a972601

3 months ago

0.0.0-fcea256

3 months ago

0.0.0-52448cb

3 months ago

0.0.0-e63b148

3 months ago

0.0.0-a807289

3 months ago

0.0.0-91b48a6

3 months ago

0.0.0-547dd1e

3 months ago

0.0.0-367b5c8

3 months ago

0.0.0-182c00d

3 months ago

0.0.0-44c2e94

3 months ago

0.0.0-f47d310

3 months ago

0.0.0-fb07b5d

3 months ago

0.0.0-1ae9ca1

3 months ago

0.0.0-32f2a11

3 months ago

0.0.0-3ae1669

3 months ago

0.0.11

3 months ago

0.0.0-6bca688

3 months ago

0.0.0-6033bc0

3 months ago

0.0.0-9a109ce

3 months ago

0.0.0-b92960d

3 months ago

0.0.0-9f58128

3 months ago

0.0.0-625c8a2

3 months ago

0.0.10

3 months ago

0.0.0-b5a4202

3 months ago

0.0.0-855b313

3 months ago

0.0.0-63a9603

3 months ago

0.0.0-95cc02a

3 months ago

0.0.0-19e9996

3 months ago

0.0.0-4c4d80b

3 months ago

0.0.0-fd87e26

3 months ago

0.0.0-dc8e960

3 months ago

0.0.0-dc91b54

3 months ago

0.0.9

3 months ago

0.0.0-d9bf4b2

3 months ago

0.0.0-270eb11

3 months ago

0.0.0-13bf590

3 months ago

0.0.0-2fd3555

3 months ago

0.0.0-00bc826

3 months ago

0.0.0-5c1b343

3 months ago

0.0.0-1d35748

3 months ago

0.0.0-7885ced

3 months ago

0.0.0-4c6f92d

3 months ago

0.0.0-aedaead

3 months ago

0.0.0-197f5e9

4 months ago

0.0.0-32f3ee3

4 months ago

0.0.0-4a1cad5

4 months ago

0.0.0-7cf43ed

4 months ago

0.0.0-9400e40

4 months ago

0.0.0-a22b4bc

4 months ago

0.0.0-ccf6f14

4 months ago

0.0.0-5337ba7

4 months ago

0.0.0-e8aa911

4 months ago

0.0.0-b5ffa13

4 months ago

0.0.0-b182165

4 months ago

0.0.0-297cfb1

4 months ago

0.0.0-8139965

4 months ago

0.0.0-aa408aa

4 months ago

0.0.0-24636b4

4 months ago

0.0.0-7b845d6

4 months ago

0.0.0-63a2548

4 months ago

0.0.0-cf944ab

4 months ago

0.0.0-60d6b17

4 months ago

0.0.0-850c77d

4 months ago

0.0.0-ac6d857

4 months ago

0.0.0-68789f0

4 months ago

0.0.0-f6c5389

4 months ago

0.0.0-b32fe31

4 months ago

0.0.0-62c8471

4 months ago

0.0.0-5a9a489

4 months ago

0.0.0-d0fbe2e

4 months ago

0.0.0-429311f

4 months ago

0.0.0-9d407bf

4 months ago

0.0.0-c5a77f9

4 months ago

0.0.0-746d4bf

4 months ago

0.0.8

4 months ago

0.0.0-004e645

4 months ago

0.0.0-fca54cb

4 months ago

0.0.0-6883221

4 months ago

0.0.0-faccb30

4 months ago

0.0.0-ffdd842

4 months ago

0.0.0-6a38b57

4 months ago

0.0.0-11d3035

4 months ago

0.0.0-eeb49d2

4 months ago

0.0.0-571e657

4 months ago

0.0.0-d2e49d2

4 months ago

0.0.0-90a202f

4 months ago

0.0.0-402125b

4 months ago

0.0.0-e461a3b

4 months ago

0.0.0-4c0be51

4 months ago

0.0.0-fcb8587

4 months ago

0.0.0-61232c8

4 months ago

0.0.0-8acd082

4 months ago

0.0.0-b6a8f43

4 months ago

0.0.0-34d5233

4 months ago

0.0.0-70d50fd

4 months ago

0.0.0-9fc8f6f

4 months ago

0.0.0-8ac1f0b

4 months ago

0.0.0-23931b1

4 months ago

0.0.0-76c5d50

4 months ago

0.0.0-dde6000

4 months ago

0.0.0-b354b19

4 months ago

0.0.0-cb38252

4 months ago

0.0.0-b145542

4 months ago

0.0.0-43c83f5

4 months ago

0.0.0-b22bed4

4 months ago

0.0.0-b95984b

4 months ago

0.0.0-225d257

4 months ago

0.0.0-64db332

4 months ago

0.0.0-3ebde9d

4 months ago

0.0.0-9b1e29c

4 months ago

0.0.0-28dab83

4 months ago

0.0.0-f70538f

4 months ago

0.0.0-ccf7ebe

4 months ago

0.0.0-4657bc3

4 months ago

0.0.0-075525d

4 months ago

0.0.0-7fc2814

4 months ago

0.0.7

4 months ago

0.0.0-4ee25aa

4 months ago

0.0.0-87541fb

4 months ago

0.0.0-ecbe61b

4 months ago

0.0.0-b5cd7e6

4 months ago

0.0.0-7eb3351

4 months ago

0.0.0-399d324

4 months ago

0.0.0-60b4090

4 months ago

0.0.0-1b06bbe

4 months ago

0.0.0-bc7cdcd

4 months ago

0.0.0-2a8026d

4 months ago

0.0.0-9927c51

4 months ago

0.0.0-964e129

4 months ago

0.0.0-5ba5c33

4 months ago

0.0.0-445372e

4 months ago

0.0.0-290c794

4 months ago

0.0.0-baa1da5

4 months ago

0.0.0-b1ff9bd

4 months ago

0.0.0-b2891f2

4 months ago

0.0.0-4f623ae

4 months ago

0.0.0-2de0a9c

4 months ago

0.0.0-520be9d

4 months ago

0.0.0-ca4dff2

4 months ago

0.0.0-9b62989

4 months ago

0.0.0-1ab7910

4 months ago

0.0.0-83f97e9

4 months ago

0.0.0-46b2f5c

4 months ago

0.0.0-2b73b2d

4 months ago

0.0.0-85dd588

4 months ago

0.0.0-4be8509

4 months ago

0.0.6

4 months ago

0.0.0-f92dcb9

4 months ago

0.0.0-afda7dd

4 months ago

0.0.0-bb3800f

4 months ago

0.0.0-2911efe

4 months ago

0.0.0-a6e4e84

4 months ago

0.0.0-9775153

4 months ago

0.0.0-cd789d4

4 months ago

0.0.0-0f81796

4 months ago

0.0.0-1c55295

4 months ago

0.0.0-5ee0943

4 months ago

0.0.0-21d6703

4 months ago

0.0.0-13e296e

4 months ago

0.0.0-7401a5d

4 months ago

0.0.0-04887f0

5 months ago

0.0.0-d68f09b

5 months ago

0.0.0-879a9de

5 months ago

0.0.0-5bd0a23

5 months ago

0.0.0-2e92b57

5 months ago

0.0.0-d4d5ea7

5 months ago

0.0.0-304fc35

5 months ago

0.0.0-20b2286

5 months ago

0.0.0-7b7bc9b

5 months ago

0.0.0-7787db8

5 months ago

0.0.0-675ab5d

5 months ago

0.0.0-c8e26e7

5 months ago

0.0.0-22b620f

5 months ago

0.0.0-ac4dc08

5 months ago

0.0.0-6523e92

5 months ago

0.0.5

5 months ago

0.0.0-24954e1

5 months ago

0.0.0-ffe8727

5 months ago

0.0.0-463f44c

5 months ago

0.0.0-2a711eb

5 months ago

0.0.0-431492a

5 months ago

0.0.0-c03660b

5 months ago

0.0.0-5b4bed3

5 months ago

0.0.0-b190d1d

5 months ago

0.0.0-ba2e4c1

5 months ago

0.0.0-31b4359

5 months ago

0.0.0-94f3891

5 months ago

0.0.0-17dcf4c

5 months ago

0.0.0-955455e

5 months ago

0.0.0-35eac21

5 months ago

0.0.0-e644680

5 months ago

0.0.0-c9b992c

5 months ago

0.0.0-1dfa367

5 months ago

0.0.0-fc6922c

5 months ago

0.0.0-5fa22e5

5 months ago

0.0.0-6053def

5 months ago

0.0.0-769692c

5 months ago

0.0.0-1738741

5 months ago

0.0.0-9141aee

5 months ago

0.0.0-d49bd65

5 months ago

0.0.0-a670852

5 months ago

0.0.4

5 months ago

0.0.0-ebb0afa

5 months ago

0.0.0-c237dc5

5 months ago

0.0.0-52e04aa

5 months ago

0.0.0-e5caa4f

5 months ago

0.0.0-0ed34cf

5 months ago

0.0.0-5d795d9

5 months ago

0.0.0-597e4dd

5 months ago

0.0.0-ac69445

5 months ago

0.0.0-ef18e36

5 months ago

0.0.0-f83a20b

5 months ago

0.0.0-5df79a6

5 months ago

0.0.0-d9bb04b

5 months ago

0.0.0-99e99e9

5 months ago

0.0.0-29ec788

5 months ago

0.0.0-6a05342

5 months ago

0.0.0-a2f3545

5 months ago

0.0.0-f04ca93

5 months ago

0.0.0-b0f773c

5 months ago

0.0.0-afbdbd2

5 months ago

0.0.0-cfaab8e

5 months ago

0.0.0-2cb1530

5 months ago

0.0.0-44bc94a

5 months ago

0.0.3

5 months ago

0.0.0-1005644

5 months ago

0.0.0-3f014ca

5 months ago

0.0.0-c54b4fe

5 months ago

0.0.0-5b3ea1e

5 months ago

0.0.0-24a6dd5

5 months ago

0.0.0-1487c3c

5 months ago

0.0.0-b1647df

7 months ago

0.0.0-6141df6

5 months ago

0.0.0-a5d4518

6 months ago

0.0.0-998b28f

6 months ago

0.0.0-d53203d

5 months ago

0.0.0-4ce4dde

5 months ago

0.0.0-4e72a05

6 months ago

0.0.0-8047007

5 months ago

0.0.0-ef2a1c4

6 months ago

0.0.0-e749c93

6 months ago

0.0.0-9dc5e5f

7 months ago

0.0.0-923141

6 months ago

0.0.0-dff84bc

6 months ago

0.0.0-671c021

6 months ago

0.0.0-bbdb6bf

6 months ago

0.0.0-54a00ac

7 months ago

0.0.0-22afd35

5 months ago

0.0.0-0a92715

6 months ago

0.0.0-6037f3f

7 months ago

0.0.0-4c022c1

6 months ago

0.0.0-cacd163

6 months ago

0.0.0-39911e8

5 months ago

0.0.0-0c0df6c

6 months ago

0.0.0-5f37340

7 months ago

0.0.0-6978adb

5 months ago

0.0.0-29ea729

5 months ago

0.0.0-364ef78

5 months ago

0.0.0-f412b0f

6 months ago

0.0.0-73762d7

5 months ago

0.0.0-f9911df

6 months ago

0.0.0-03c7069

5 months ago

0.0.0-81a943e

6 months ago

0.0.0-764f98c

5 months ago

0.0.0-082319e

7 months ago

0.0.0-0e781d7

7 months ago

0.0.0-dfecc90

6 months ago

0.0.0-a09c544

6 months ago

0.0.0-f652575

6 months ago

0.0.0-a91fcd3

7 months ago

0.0.0-79dfe8f

6 months ago

0.0.0-098365b

7 months ago

0.0.0-3d4012c

5 months ago

0.0.0-c55d2c3

5 months ago

0.0.0-d26b736

5 months ago

0.0.0-c16fabd

6 months ago

0.0.0-ac5d63c

5 months ago

0.0.0-bdd6f69

6 months ago

0.0.0-34f5f9f

6 months ago

0.0.0-bc4eb4c

7 months ago

0.0.0-4697342

5 months ago

0.0.0-62da41b

7 months ago

0.0.0-1a5ebf5

5 months ago

0.0.0-669d9ea

5 months ago

0.0.0-c440c15

5 months ago

0.0.0-5a7fdcf

6 months ago

0.0.0-a93429f

6 months ago

0.0.1

6 months ago

0.0.0-d214049

6 months ago

0.0.0-556bf6e

5 months ago

0.0.2

6 months ago

0.0.0-a8ab761

5 months ago

0.0.0-6b36063

7 months ago

0.0.0-2d8c3bc

5 months ago

0.0.0-70dbd60

6 months ago

0.0.0-1d3b98d

6 months ago

0.0.0-8d87575

5 months ago

0.0.0-a6bfedc

6 months ago

0.0.0-98d0072

6 months ago

0.0.0-3c4af33

7 months ago

0.0.0-d1a4198

6 months ago

0.0.0

1 year ago