Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

RPCSocketServer.d.ts 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { Socket } from "./RPCSocketServer";
  2. declare type rpcType = 'hook' | 'unhook' | 'call';
  3. declare type visibility = 'public' | 'private';
  4. export declare type Outcome = "Success" | "Error";
  5. export declare class Response {
  6. message?: string | undefined;
  7. constructor(message?: string | undefined);
  8. }
  9. export declare class SuccessResponse extends Response {
  10. result: Outcome;
  11. constructor(message?: string);
  12. }
  13. export declare class ErrorResponse extends Response {
  14. result: Outcome;
  15. constructor(message?: string);
  16. }
  17. export declare class SubscriptionResponse extends SuccessResponse {
  18. uid: string;
  19. constructor(uid: string, message?: string);
  20. }
  21. export declare type UnhookFunction = (uid: string) => Promise<SuccessResponse | ErrorResponse>;
  22. export declare type callbackFunction = (...args: any[]) => Promise<SubscriptionResponse | ErrorResponse>;
  23. export declare type AsyncFunction = (...args: any[]) => Promise<any>;
  24. export interface RPCExporter {
  25. name: string;
  26. exportRPCs(): socketioRPC[];
  27. }
  28. declare type baseRPC = {
  29. type: rpcType;
  30. name: string;
  31. visibility: visibility;
  32. };
  33. declare type hookRPC = baseRPC & {
  34. type: 'hook';
  35. func: callbackFunction;
  36. unhook: UnhookFunction;
  37. };
  38. declare type unhookRPC = baseRPC & {
  39. type: 'unhook';
  40. func: UnhookFunction;
  41. };
  42. declare type callRPC = baseRPC & {
  43. type: 'call';
  44. func: (...args: any[]) => Promise<any>;
  45. };
  46. export declare type socketioRPC = callRPC | unhookRPC | hookRPC;
  47. export declare type baseInfo = {
  48. owner: string;
  49. argNames: string[];
  50. };
  51. declare type HookInfo = baseRPC & baseInfo & {
  52. type: 'hook';
  53. generator: (socket: any) => callbackFunction;
  54. unhook: UnhookFunction;
  55. };
  56. declare type UnhookInfo = baseRPC & baseInfo & {
  57. type: 'unhook';
  58. func: UnhookFunction;
  59. };
  60. declare type CallInfo = baseRPC & baseInfo & {
  61. type: 'call';
  62. func: AsyncFunction;
  63. };
  64. declare type RpcInfo = HookInfo | UnhookInfo | CallInfo;
  65. export declare type ExtendedRpcInfo = RpcInfo & {
  66. uniqueName: string;
  67. };
  68. export declare const rpcToRpcinfo: (rpc: socketioRPC, owner: string) => RpcInfo;
  69. export declare const rpcHooker: (socket: Socket, owner: string, RPCs: socketioRPC[], makeUnique?: boolean) => ExtendedRpcInfo[];
  70. declare type OnFunction = (type: 'error' | 'close', f: (e?: any) => void) => Socket;
  71. export declare type Socket = {
  72. port: number;
  73. hook: (rpcname: string, ...args: any[]) => Socket;
  74. unhook: (rpcname: string) => Socket;
  75. call: (rpcname: string, ...args: any[]) => Promise<any>;
  76. fire: (rpcname: string, ...args: any[]) => Promise<any>;
  77. on: OnFunction;
  78. destroy: () => void;
  79. close: () => void;
  80. };
  81. export declare type RPCSocketConf = {
  82. connectionHandler: (socket: Socket) => void;
  83. errorHandler: (socket: Socket) => (error: any) => void;
  84. closeHandler: (socket: Socket) => () => void;
  85. };
  86. export declare class RPCSocketServer {
  87. private port;
  88. private rpcExporters;
  89. private conf;
  90. private io;
  91. private wsServer;
  92. constructor(port: number, rpcExporters?: RPCExporter[], conf?: RPCSocketConf);
  93. private startWebsocket;
  94. protected initApis(socket: any): void;
  95. }
  96. export {};