|
22 | 22 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23 | 23 | */
|
24 | 24 |
|
25 |
| -import * as ws from "ws" |
26 |
| -import * as http from "node:http" |
27 |
| -import * as HAPI from "@hapi/hapi" |
| 25 | +import { Plugin, Request, ReqRef, ReqRefDefaults } from "@hapi/hapi" |
| 26 | +import { Podium } from "@hapi/podium" |
| 27 | +import * as ws from "ws" |
| 28 | +import * as http from "node:http" |
28 | 29 |
|
29 |
| -interface HapiWebsocketPluginState { |
30 |
| - mode: "websocket" |
31 |
| - ctx: Record<string, any> |
32 |
| - wss: ws.Server |
33 |
| - ws: ws.WebSocket |
34 |
| - wsf: any |
35 |
| - req: http.IncomingMessage |
36 |
| - peers: ws.WebSocket[] |
37 |
| - initially: boolean |
38 |
| -} |
| 30 | +declare namespace HAPIPluginWebSockets { |
| 31 | + interface PluginState { |
| 32 | + mode: "websocket" |
| 33 | + ctx: Record<string, any> |
| 34 | + wss: ws.Server |
| 35 | + ws: ws.WebSocket |
| 36 | + wsf: any |
| 37 | + req: http.IncomingMessage |
| 38 | + peers: ws.WebSocket[] |
| 39 | + initially: boolean |
| 40 | + } |
| 41 | + |
| 42 | + interface PluginSpecificConfiguration { |
| 43 | + only?: boolean |
| 44 | + subprotocol?: string |
| 45 | + error?: ( |
| 46 | + this: PluginState["ctx"], |
| 47 | + pluginState: PluginState, |
| 48 | + error: Error |
| 49 | + ) => void |
| 50 | + connect?: ( |
| 51 | + this: PluginState["ctx"], |
| 52 | + pluginState: PluginState |
| 53 | + ) => void |
| 54 | + disconnect?: ( |
| 55 | + this: PluginState["ctx"], |
| 56 | + pluginState: PluginState |
| 57 | + ) => void |
| 58 | + request?: ( |
| 59 | + ctx: any, |
| 60 | + request: any, |
| 61 | + h?: any |
| 62 | + ) => void |
| 63 | + response?: ( |
| 64 | + ctx: any, |
| 65 | + request: any, |
| 66 | + h?: any |
| 67 | + ) => void |
| 68 | + frame?: boolean |
| 69 | + frameEncoding?: "json" | string |
| 70 | + frameRequest?: "REQUEST" | string |
| 71 | + frameResponse?: "RESPONSE" | string |
| 72 | + frameMessage?: ( |
| 73 | + this: PluginState["ctx"], |
| 74 | + pluginState: PluginState, |
| 75 | + frame: any |
| 76 | + ) => void |
| 77 | + autoping?: number |
| 78 | + initially?: boolean |
| 79 | + } |
39 | 80 |
|
40 |
| -interface HapiWebsocketPluginSpecificConfiguration { |
41 |
| - only?: boolean |
42 |
| - subprotocol?: string |
43 |
| - error?: ( |
44 |
| - this: HapiWebsocketPluginState["ctx"], |
45 |
| - pluginState: HapiWebsocketPluginState, |
46 |
| - error: Error |
47 |
| - ) => void |
48 |
| - connect?: ( |
49 |
| - this: HapiWebsocketPluginState["ctx"], |
50 |
| - pluginState: HapiWebsocketPluginState |
51 |
| - ) => void |
52 |
| - disconnect?: ( |
53 |
| - this: HapiWebsocketPluginState["ctx"], |
54 |
| - pluginState: HapiWebsocketPluginState |
55 |
| - ) => void |
56 |
| - request?: ( |
57 |
| - ctx: any, |
58 |
| - request: any, |
59 |
| - h?: any |
60 |
| - ) => void |
61 |
| - response?: ( |
62 |
| - ctx: any, |
63 |
| - request: any, |
64 |
| - h?: any |
65 |
| - ) => void |
66 |
| - frame?: boolean |
67 |
| - frameEncoding?: "json" | string |
68 |
| - frameRequest?: "REQUEST" | string |
69 |
| - frameResponse?: "RESPONSE" | string |
70 |
| - frameMessage?: ( |
71 |
| - this: HapiWebsocketPluginState["ctx"], |
72 |
| - pluginState: HapiWebsocketPluginState, |
73 |
| - frame: any |
74 |
| - ) => void |
75 |
| - autoping?: number |
76 |
| - initially?: boolean |
| 81 | + interface OptionalRegistrationOptions { |
| 82 | + } |
77 | 83 | }
|
78 | 84 |
|
| 85 | +declare const HAPIPluginDucky: Plugin<HAPIPluginWebSockets.OptionalRegistrationOptions> |
| 86 | + |
| 87 | +export = HAPIPluginWebSockets |
| 88 | + |
79 | 89 | declare module "@hapi/hapi" {
|
80 | 90 | export interface Request<Refs extends ReqRef = ReqRefDefaults> extends Podium {
|
81 |
| - websocket(): HapiWebsocketPluginState |
| 91 | + websocket(): HAPIPluginWebSockets.PluginState |
82 | 92 | }
|
83 | 93 | export interface PluginsStates {
|
84 |
| - websocket: HapiWebsocketPluginState |
| 94 | + websocket: HAPIPluginWebSockets.PluginState |
85 | 95 | }
|
86 | 96 | export interface PluginSpecificConfiguration {
|
87 |
| - websocket?: HapiWebsocketPluginSpecificConfiguration |
| 97 | + websocket?: HAPIPluginWebSockets.PluginSpecificConfiguration |
88 | 98 | }
|
89 | 99 | }
|
90 | 100 |
|
0 commit comments