forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(websockets) extract web sockets drivers
- Loading branch information
1 parent
03b0cf8
commit 53687ba
Showing
59 changed files
with
616 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 15 additions & 10 deletions
25
packages/common/interfaces/websockets/web-socket-adapter.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
import { Observable } from 'rxjs'; | ||
|
||
export interface WebSocketAdapter<T = any> { | ||
create(port: number, options?: T): any; | ||
bindClientConnect(server: any, callback: (...args: any[]) => void): any; | ||
bindClientDisconnect?(client: any, callback: (...args: any[]) => void): any; | ||
export interface WsMessageHandler<T = string> { | ||
message: T; | ||
callback: (...args: any[]) => Observable<any> | Promise<any>; | ||
} | ||
export interface WebSocketAdapter< | ||
TServer = any, | ||
TClient = any, | ||
TOptions = any | ||
> { | ||
create(port: number, options?: TOptions): TServer; | ||
bindClientConnect(server: TServer, callback: Function): any; | ||
bindClientDisconnect?(client: TClient, callback: Function): any; | ||
bindMessageHandlers( | ||
client: any, | ||
handlers: Array<{ | ||
message: any; | ||
callback: (...args: any[]) => Observable<any> | Promise<any> | any; | ||
}>, | ||
client: TClient, | ||
handlers: WsMessageHandler[], | ||
transform: (data: any) => Observable<any>, | ||
): any; | ||
close(server: any): any; | ||
close(server: TServer): any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Logger } from '@nestjs/common'; | ||
|
||
const MISSING_REQUIRED_DEPENDENCY = ( | ||
defaultPlatform: string, | ||
transport: string, | ||
) => | ||
`No driver (${transport}) has been selected. In order to take advantage of the default driver, please, ensure to install the "${defaultPlatform}" package ($ npm install ${defaultPlatform}).`; | ||
|
||
const logger = new Logger('PackageLoader'); | ||
|
||
export function loadAdapter(defaultPlatform: string, transport: string) { | ||
try { | ||
return require(defaultPlatform); | ||
} catch (e) { | ||
logger.error(MISSING_REQUIRED_DEPENDENCY(defaultPlatform, transport)); | ||
process.exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.