@@ -11,6 +11,8 @@ Reference: https://socket.io/
11
11
12
12
<!-- TOC -->
13
13
* [ How to use] ( #how-to-use )
14
+ * [ With Bun's HTTP server] ( #with-buns-http-server )
15
+ * [ With Hono] ( #with-hono )
14
16
* [ Options] ( #options )
15
17
* [ ` path ` ] ( #path )
16
18
* [ ` pingTimeout ` ] ( #pingtimeout )
@@ -26,6 +28,8 @@ Reference: https://socket.io/
26
28
27
29
## How to use
28
30
31
+ ### With Bun's HTTP server
32
+
29
33
``` js
30
34
import { Server as Engine } from " @socket.io/bun-engine" ;
31
35
import { Server } from " socket.io" ;
@@ -38,17 +42,59 @@ const engine = new Engine({
38
42
39
43
io .bind (engine);
40
44
41
- Bun .serve ({
42
- ... engine .handler (),
45
+ io .on (" connection" , (socket ) => {
46
+ // ...
47
+ });
48
+
49
+ export default {
43
50
port: 3000 ,
44
51
idleTimeout: 30 , // must be greater than the "pingInterval" option of the engine, which defaults to 25 seconds
45
- });
52
+
53
+ ... engine .handler (),
54
+ };
55
+ ```
56
+
57
+ ### With Hono
58
+
59
+ ``` js
60
+ import { Server as Engine } from " @socket.io/bun-engine" ;
61
+ import { Server } from " socket.io" ;
62
+ import { Hono } from " hono" ;
63
+
64
+ const io = new Server ();
65
+
66
+ const engine = new Engine ();
67
+
68
+ io .bind (engine);
46
69
47
70
io .on (" connection" , (socket ) => {
48
71
// ...
49
72
});
73
+
74
+ const app = new Hono ();
75
+
76
+ const { websocket } = engine .handler ();
77
+
78
+ export default {
79
+ port: 3000 ,
80
+ idleTimeout: 30 , // must be greater than the "pingInterval" option of the engine, which defaults to 25 seconds
81
+
82
+ fetch (req , server ) {
83
+ const url = new URL (req .url );
84
+
85
+ if (url .pathname === " /socket.io/" ) {
86
+ return engine .handleRequest (req, server);
87
+ } else {
88
+ return app .fetch (req, server);
89
+ }
90
+ },
91
+
92
+ websocket
93
+ }
50
94
```
51
95
96
+ Reference: https://hono.dev/docs/
97
+
52
98
## Options
53
99
54
100
### ` path `
0 commit comments