Skip to content

Commit 4a312fa

Browse files
committed
start typescript definition
1 parent dc8ce2d commit 4a312fa

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

hapi-plugin-websocket.d.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
** hapi-plugin-websocket -- HAPI plugin for seamless WebSocket integration
3+
** Copyright (c) 2016-2022 Dr. Ralf S. Engelschall <[email protected]>
4+
**
5+
** Permission is hereby granted, free of charge, to any person obtaining
6+
** a copy of this software and associated documentation files (the
7+
** "Software"), to deal in the Software without restriction, including
8+
** without limitation the rights to use, copy, modify, merge, publish,
9+
** distribute, sublicense, and/or sell copies of the Software, and to
10+
** permit persons to whom the Software is furnished to do so, subject to
11+
** the following conditions:
12+
**
13+
** The above copyright notice and this permission notice shall be included
14+
** in all copies or substantial portions of the Software.
15+
**
16+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*/
24+
25+
import * as ws from "ws"
26+
import * as http from "node:http"
27+
28+
interface HapiWebsocketPluginState<WSF = any> {
29+
mode: "websocket"
30+
ctx: Record<string, any>
31+
wss: ws.Server
32+
ws: ws.WebSocket
33+
wsf: WSF
34+
req: http.IncomingMessage
35+
peers: ws.WebSocket[]
36+
initially: boolean
37+
}
38+
39+
interface HapiWebsocketPluginSpecificConfiguration {
40+
only?: boolean
41+
subprotocol?: string
42+
error?: (
43+
this: HapiWebsocketPluginState["ctx"],
44+
pluginState: HapiWebsocketPluginState,
45+
error: Error
46+
) => void
47+
connect?: (
48+
this: HapiWebsocketPluginState["ctx"],
49+
pluginState: HapiWebsocketPluginState
50+
) => void
51+
disconnect?: (
52+
this: HapiWebsocketPluginState["ctx"],
53+
pluginState: HapiWebsocketPluginState
54+
) => void
55+
request?: (
56+
ctx: any,
57+
request: any,
58+
h?: any
59+
) => void
60+
response?: (
61+
ctx: any,
62+
request: any,
63+
h?: any
64+
) => void
65+
frame?: boolean
66+
frameEncoding?: "json" | string
67+
frameRequest?: "REQUEST" | string
68+
frameResponse?: "RESPONSE" | string
69+
frameMessage?: (
70+
this: HapiWebsocketPluginState["ctx"],
71+
pluginState: HapiWebsocketPluginState,
72+
frame: any
73+
) => void
74+
autoping?: number
75+
initially?: boolean
76+
}
77+
78+
declare module "@hapi/hapi" {
79+
export interface PluginsStates {
80+
websocket: HapiWebsocketPluginState
81+
}
82+
export interface PluginSpecificConfiguration {
83+
websocket: HapiWebsocketPluginSpecificConfiguration
84+
}
85+
}
86+

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "HAPI plugin for seamless WebSocket integration",
55
"keywords": [ "hapi", "plugin", "websocket" ],
66
"main": "./hapi-plugin-websocket.js",
7+
"types": "./hapi-plugin-websocket.d.ts",
78
"license": "MIT",
89
"repository": {
910
"type": "git",
@@ -24,7 +25,9 @@
2425
"@hapi/hoek": "11.0.2",
2526
"@hapi/boom": "10.0.0",
2627
"ws": "8.12.0",
27-
"websocket-framed": "1.2.9"
28+
"websocket-framed": "1.2.9",
29+
"@types/node": "18.11.18",
30+
"@types/ws": "8.5.4"
2831
},
2932
"devDependencies": {
3033
"@hapi/hapi": "21.2.0",

0 commit comments

Comments
 (0)