๐Ÿ“ฆ socketio / socket.io-deno

๐Ÿ“„ mod.ts ยท 72 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72/**
 * @example
 * import { Server } from "https://deno.land/x/socket_io@x.y.z/mod.ts";
 *
 * const io = new Server();
 *
 * io.on("connection", (socket) => {
 *   console.log(`socket ${socket.id} connected`);
 *
 *   // send an event to the client
 *   socket.emit("foo", "bar");
 *
 *   socket.on("foobar", () => {
 *     // an event was received from the client
 *   });
 *
 *   // upon disconnection
 *   socket.on("disconnect", (reason) => {
 *     console.log(`socket ${socket.id} disconnected due to ${reason}`);
 *   });
 * });
 *
 * Deno.serve({
 *   handler: io.handler(),
 *   port: 3000,
 * });
 */
export {
  Adapter,
  type BroadcastOptions,
  type Namespace,
  Server,
  type ServerOptions,
  type Socket,
} from "./packages/socket.io/mod.ts";

/**
 * The Redis adapter, to broadcast packets between several Socket.IO servers
 *
 * Documentation: https://socket.io/docs/v4/redis-adapter/
 *
 * @example
 * import { Server, createRedisAdapter, createRedisClient } from "https://deno.land/x/socket_io/mod.ts";
 *
 * const [pubClient, subClient] = await Promise.all([
 *   createRedisClient({
 *     hostname: "localhost",
 *   }),
 *   createRedisClient({
 *     hostname: "localhost",
 *   })
 * ]);
 *
 * const io = new Server({
 *     adapter: createRedisAdapter(pubClient, subClient)
 * });
 *
 * Deno.serve({
 *   handler: io.handler(),
 *   port: 3000
 * });
 */
export {
  createAdapter as createRedisAdapter,
  type RedisAdapterOptions,
} from "./packages/socket.io-redis-adapter/mod.ts";

/**
 * Temporary export to provide a workaround for https://github.com/denodrivers/redis/issues/335
 */
export { connect as createRedisClient } from "./vendor/deno.land/x/redis@v0.27.1/mod.ts";