Allow Use client from client-resources from NodeJS (#545)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2021-12-06 17:57:35 +01:00
committed by GitHub
parent 420fc93967
commit beecb23c79
16 changed files with 207 additions and 93 deletions
+21 -1
View File
@@ -30,6 +30,25 @@ export const clientId = 'client' as Plugin
*/
export type ClientHook = (client: Client) => Promise<Client>
/**
* @public
*/
export type ClientSocketFactory = (url: string) => ClientSocket
/**
* @public
*/
export interface ClientSocket {
onmessage?: ((this: ClientSocket, ev: MessageEvent) => any) | null
onclose?: ((this: ClientSocket, ev: CloseEvent) => any) | null
onopen?: ((this: ClientSocket, ev: Event) => any) | null
onerror?: ((this: ClientSocket, ev: Event) => any) | null
send: (data: string | ArrayBufferLike | Blob | ArrayBufferView) => void
close: () => void
}
/**
* @public
*/
@@ -38,7 +57,8 @@ export type ClientFactory = (token: string, endpoint: string) => Promise<Client>
export default plugin(clientId,
{
metadata: {
ClientHook: '' as Metadata<Resource<ClientHook>>
ClientHook: '' as Metadata<Resource<ClientHook>>,
ClientSocketFactory: '' as Metadata<ClientSocketFactory>
},
function: {
GetClient: '' as Resource<ClientFactory>