@litert/televoke 0.4.7 → 1.0.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +4 -2
- package/README.md +13 -8
- package/lib/client/Client.decl.d.ts +47 -0
- package/lib/client/Client.decl.d.ts.map +1 -0
- package/lib/client/Client.decl.js +18 -0
- package/lib/client/Client.decl.js.map +1 -0
- package/lib/client/JsonApiClient.impl.d.ts +28 -0
- package/lib/client/JsonApiClient.impl.d.ts.map +1 -0
- package/lib/client/JsonApiClient.impl.js +169 -0
- package/lib/client/JsonApiClient.impl.js.map +1 -0
- package/lib/client/LegacyHttpClient.impl.d.ts +62 -0
- package/lib/client/LegacyHttpClient.impl.d.ts.map +1 -0
- package/lib/client/LegacyHttpClient.impl.js +163 -0
- package/lib/client/LegacyHttpClient.impl.js.map +1 -0
- package/lib/client/index.d.ts +19 -0
- package/lib/client/index.d.ts.map +1 -0
- package/lib/client/index.js +35 -0
- package/lib/client/index.js.map +1 -0
- package/lib/index.d.ts +18 -20
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +19 -20
- package/lib/index.js.map +1 -1
- package/lib/server/LegacyServerChannel.impl.d.ts +38 -0
- package/lib/server/LegacyServerChannel.impl.d.ts.map +1 -0
- package/lib/server/LegacyServerChannel.impl.js +51 -0
- package/lib/server/LegacyServerChannel.impl.js.map +1 -0
- package/lib/server/Server.decl.d.ts +81 -0
- package/lib/server/Server.decl.d.ts.map +1 -0
- package/lib/server/Server.decl.js +18 -0
- package/lib/server/Server.decl.js.map +1 -0
- package/lib/server/Server.impl.d.ts +33 -0
- package/lib/server/Server.impl.d.ts.map +1 -0
- package/lib/server/Server.impl.js +58 -0
- package/lib/server/Server.impl.js.map +1 -0
- package/lib/server/ServerChannel.d.ts +20 -0
- package/lib/server/ServerChannel.d.ts.map +1 -0
- package/lib/server/ServerChannel.js +23 -0
- package/lib/server/ServerChannel.js.map +1 -0
- package/lib/server/SimpleJsonApiRouter.d.ts +28 -0
- package/lib/server/SimpleJsonApiRouter.d.ts.map +1 -0
- package/lib/server/SimpleJsonApiRouter.js +92 -0
- package/lib/server/SimpleJsonApiRouter.js.map +1 -0
- package/lib/server/index.d.ts +19 -0
- package/lib/server/index.d.ts.map +1 -0
- package/lib/server/index.js +35 -0
- package/lib/server/index.js.map +1 -0
- package/lib/shared/BinaryStream.d.ts +36 -0
- package/lib/shared/BinaryStream.d.ts.map +1 -0
- package/lib/shared/BinaryStream.js +100 -0
- package/lib/shared/BinaryStream.js.map +1 -0
- package/lib/shared/BinaryStreamManager.d.ts +52 -0
- package/lib/shared/BinaryStreamManager.d.ts.map +1 -0
- package/lib/shared/BinaryStreamManager.js +105 -0
- package/lib/shared/BinaryStreamManager.js.map +1 -0
- package/lib/shared/Channel.impl.d.ts +79 -0
- package/lib/shared/Channel.impl.d.ts.map +1 -0
- package/lib/shared/Channel.impl.js +448 -0
- package/lib/shared/Channel.impl.js.map +1 -0
- package/lib/shared/Constants.d.ts +32 -0
- package/lib/shared/Constants.d.ts.map +1 -0
- package/lib/shared/Constants.js +35 -0
- package/lib/shared/Constants.js.map +1 -0
- package/lib/shared/Encodings/index.d.ts +18 -0
- package/lib/shared/Encodings/index.d.ts.map +1 -0
- package/lib/shared/Encodings/index.js +21 -0
- package/lib/shared/Encodings/index.js.map +1 -0
- package/lib/shared/Encodings/v1/EncoderV1.d.ts +22 -0
- package/lib/shared/Encodings/v1/EncoderV1.d.ts.map +1 -0
- package/lib/shared/Encodings/v1/EncoderV1.js +47 -0
- package/lib/shared/Encodings/v1/EncoderV1.js.map +1 -0
- package/lib/shared/Encodings/v1/Protocol.v1.decls.d.ts +78 -0
- package/lib/shared/Encodings/v1/Protocol.v1.decls.d.ts.map +1 -0
- package/lib/shared/Encodings/v1/Protocol.v1.decls.js +53 -0
- package/lib/shared/Encodings/v1/Protocol.v1.decls.js.map +1 -0
- package/lib/shared/Encodings/v1/index.d.ts +18 -0
- package/lib/shared/Encodings/v1/index.d.ts.map +1 -0
- package/lib/shared/Encodings/v1/index.js +34 -0
- package/lib/shared/Encodings/v1/index.js.map +1 -0
- package/lib/shared/Encodings/v2/Constants.v2.d.ts +29 -0
- package/lib/shared/Encodings/v2/Constants.v2.d.ts.map +1 -0
- package/lib/shared/Encodings/v2/Constants.v2.js +34 -0
- package/lib/shared/Encodings/v2/Constants.v2.js.map +1 -0
- package/lib/shared/Encodings/v2/DecoderV2.d.ts +27 -0
- package/lib/shared/Encodings/v2/DecoderV2.d.ts.map +1 -0
- package/lib/shared/Encodings/v2/DecoderV2.js +281 -0
- package/lib/shared/Encodings/v2/DecoderV2.js.map +1 -0
- package/lib/shared/Encodings/v2/EncoderV2.d.ts +21 -0
- package/lib/shared/Encodings/v2/EncoderV2.d.ts.map +1 -0
- package/lib/shared/Encodings/v2/EncoderV2.js +177 -0
- package/lib/shared/Encodings/v2/EncoderV2.js.map +1 -0
- package/lib/shared/Encodings/v2/Encoding.v2.decl.d.ts +99 -0
- package/lib/shared/Encodings/v2/Encoding.v2.decl.d.ts.map +1 -0
- package/lib/shared/Encodings/v2/Encoding.v2.decl.js +18 -0
- package/lib/shared/Encodings/v2/Encoding.v2.decl.js.map +1 -0
- package/lib/shared/Encodings/v2/index.d.ts +20 -0
- package/lib/shared/Encodings/v2/index.d.ts.map +1 -0
- package/lib/shared/Encodings/v2/index.js +35 -0
- package/lib/shared/Encodings/v2/index.js.map +1 -0
- package/lib/shared/Errors.d.ts +61 -0
- package/lib/shared/Errors.d.ts.map +1 -0
- package/lib/shared/Errors.js +76 -0
- package/lib/shared/Errors.js.map +1 -0
- package/lib/shared/Shared.decl.d.ts +313 -0
- package/lib/shared/Shared.decl.d.ts.map +1 -0
- package/lib/shared/Shared.decl.js +18 -0
- package/lib/shared/Shared.decl.js.map +1 -0
- package/lib/shared/Utils.d.ts +25 -0
- package/lib/shared/Utils.d.ts.map +1 -0
- package/lib/shared/Utils.js +46 -0
- package/lib/shared/Utils.js.map +1 -0
- package/lib/shared/index.d.ts +23 -0
- package/lib/shared/index.d.ts.map +1 -0
- package/lib/shared/index.js +39 -0
- package/lib/shared/index.js.map +1 -0
- package/lib/transporters/Transporter.decl.d.ts +90 -0
- package/lib/transporters/Transporter.decl.d.ts.map +1 -0
- package/lib/transporters/Transporter.decl.js +18 -0
- package/lib/transporters/Transporter.decl.js.map +1 -0
- package/lib/transporters/http-listener/AbstractHttpListener.d.ts +32 -0
- package/lib/transporters/http-listener/AbstractHttpListener.d.ts.map +1 -0
- package/lib/transporters/http-listener/AbstractHttpListener.js +46 -0
- package/lib/transporters/http-listener/AbstractHttpListener.js.map +1 -0
- package/lib/transporters/http-listener/Http.Decl.d.ts +95 -0
- package/lib/transporters/http-listener/Http.Decl.d.ts.map +1 -0
- package/lib/transporters/http-listener/Http.Decl.js +52 -0
- package/lib/transporters/http-listener/Http.Decl.js.map +1 -0
- package/lib/transporters/http-listener/HttpListener.d.ts +18 -0
- package/lib/transporters/http-listener/HttpListener.d.ts.map +1 -0
- package/lib/transporters/http-listener/HttpListener.js +73 -0
- package/lib/transporters/http-listener/HttpListener.js.map +1 -0
- package/lib/transporters/http-listener/HttpUnixSocketListener.d.ts +18 -0
- package/lib/transporters/http-listener/HttpUnixSocketListener.d.ts.map +1 -0
- package/lib/transporters/http-listener/HttpUnixSocketListener.js +72 -0
- package/lib/transporters/http-listener/HttpUnixSocketListener.js.map +1 -0
- package/lib/transporters/http-listener/HttpsListener.d.ts +18 -0
- package/lib/transporters/http-listener/HttpsListener.d.ts.map +1 -0
- package/lib/transporters/http-listener/HttpsListener.js +73 -0
- package/lib/transporters/http-listener/HttpsListener.js.map +1 -0
- package/lib/transporters/http-listener/index.d.ts +20 -0
- package/lib/transporters/http-listener/index.d.ts.map +1 -0
- package/lib/transporters/http-listener/index.js +36 -0
- package/lib/transporters/http-listener/index.js.map +1 -0
- package/lib/transporters/index.d.ts +17 -0
- package/lib/transporters/index.d.ts.map +1 -0
- package/lib/transporters/index.js +18 -0
- package/lib/transporters/index.js.map +1 -0
- package/lib/transporters/legacy-http/LegacyHttp.Server.d.ts +24 -0
- package/lib/transporters/legacy-http/LegacyHttp.Server.d.ts.map +1 -0
- package/lib/transporters/legacy-http/LegacyHttp.Server.js +167 -0
- package/lib/transporters/legacy-http/LegacyHttp.Server.js.map +1 -0
- package/lib/transporters/legacy-http/LegacyHttp.Transporter.d.ts +28 -0
- package/lib/transporters/legacy-http/LegacyHttp.Transporter.d.ts.map +1 -0
- package/lib/transporters/legacy-http/LegacyHttp.Transporter.js +55 -0
- package/lib/transporters/legacy-http/LegacyHttp.Transporter.js.map +1 -0
- package/lib/transporters/legacy-http/index.d.ts +18 -0
- package/lib/transporters/legacy-http/index.d.ts.map +1 -0
- package/lib/transporters/legacy-http/index.js +34 -0
- package/lib/transporters/legacy-http/index.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Client.d.ts +19 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Client.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Client.js +33 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Client.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Server.d.ts +21 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Server.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Server.js +64 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Server.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Client.d.ts +19 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Client.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Client.js +33 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Client.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Server.d.ts +21 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Server.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Server.js +64 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Server.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Transporter.d.ts +34 -0
- package/lib/transporters/lwdfx/LwDFX.Transporter.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Transporter.js +78 -0
- package/lib/transporters/lwdfx/LwDFX.Transporter.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Client.d.ts +19 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Client.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Client.js +33 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Client.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Server.d.ts +21 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Server.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Server.js +64 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Server.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.decl.d.ts +18 -0
- package/lib/transporters/lwdfx/LwDFX.decl.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.decl.js +18 -0
- package/lib/transporters/lwdfx/LwDFX.decl.js.map +1 -0
- package/lib/transporters/lwdfx/index.d.ts +23 -0
- package/lib/transporters/lwdfx/index.d.ts.map +1 -0
- package/lib/transporters/lwdfx/index.js +39 -0
- package/lib/transporters/lwdfx/index.js.map +1 -0
- package/lib/transporters/memory/Memory.Impl.d.ts +43 -0
- package/lib/transporters/memory/Memory.Impl.d.ts.map +1 -0
- package/lib/transporters/memory/Memory.Impl.js +227 -0
- package/lib/transporters/memory/Memory.Impl.js.map +1 -0
- package/lib/transporters/memory/index.d.ts +17 -0
- package/lib/transporters/memory/index.d.ts.map +1 -0
- package/lib/transporters/memory/index.js +33 -0
- package/lib/transporters/memory/index.js.map +1 -0
- package/lib/transporters/websocket/WebSocket.Client.d.ts +20 -0
- package/lib/transporters/websocket/WebSocket.Client.d.ts.map +1 -0
- package/lib/transporters/websocket/WebSocket.Client.js +68 -0
- package/lib/transporters/websocket/WebSocket.Client.js.map +1 -0
- package/lib/transporters/websocket/WebSocket.Server.d.ts +25 -0
- package/lib/transporters/websocket/WebSocket.Server.d.ts.map +1 -0
- package/lib/transporters/websocket/WebSocket.Server.js +87 -0
- package/lib/transporters/websocket/WebSocket.Server.js.map +1 -0
- package/lib/transporters/websocket/WebSocket.Transporter.d.ts +34 -0
- package/lib/transporters/websocket/WebSocket.Transporter.d.ts.map +1 -0
- package/lib/transporters/websocket/WebSocket.Transporter.js +106 -0
- package/lib/transporters/websocket/WebSocket.Transporter.js.map +1 -0
- package/lib/transporters/websocket/WebSocket.decl.d.ts +19 -0
- package/lib/transporters/websocket/WebSocket.decl.d.ts.map +1 -0
- package/lib/transporters/websocket/WebSocket.decl.js +22 -0
- package/lib/transporters/websocket/WebSocket.decl.js.map +1 -0
- package/lib/transporters/websocket/index.d.ts +19 -0
- package/lib/transporters/websocket/index.d.ts.map +1 -0
- package/lib/transporters/websocket/index.js +35 -0
- package/lib/transporters/websocket/index.js.map +1 -0
- package/package.json +12 -12
- package/src/lib/client/Client.decl.ts +61 -0
- package/src/lib/client/JsonApiClient.impl.ts +258 -0
- package/src/lib/client/LegacyHttpClient.impl.ts +278 -0
- package/src/lib/client/index.ts +19 -0
- package/src/lib/index.ts +18 -20
- package/src/lib/server/LegacyServerChannel.impl.ts +71 -0
- package/src/lib/server/Server.decl.ts +109 -0
- package/src/lib/server/Server.impl.ts +90 -0
- package/src/lib/server/ServerChannel.ts +20 -0
- package/src/lib/server/SimpleJsonApiRouter.ts +135 -0
- package/src/lib/server/index.ts +19 -0
- package/src/lib/shared/BinaryStream.ts +141 -0
- package/src/lib/shared/BinaryStreamManager.ts +142 -0
- package/src/lib/shared/Channel.impl.ts +658 -0
- package/src/lib/shared/Constants.ts +35 -0
- package/src/lib/shared/Encodings/index.ts +18 -0
- package/src/lib/shared/Encodings/v1/EncoderV1.ts +66 -0
- package/src/lib/shared/Encodings/v1/Protocol.v1.decls.ts +96 -0
- package/src/lib/shared/Encodings/v1/index.ts +18 -0
- package/src/lib/shared/Encodings/v2/Constants.v2.ts +31 -0
- package/src/lib/shared/Encodings/v2/DecoderV2.ts +406 -0
- package/src/lib/shared/Encodings/v2/EncoderV2.ts +284 -0
- package/src/lib/shared/Encodings/v2/Encoding.v2.decl.ts +138 -0
- package/src/lib/shared/Encodings/v2/index.ts +20 -0
- package/src/lib/shared/Errors.ts +95 -0
- package/src/lib/shared/Shared.decl.ts +366 -0
- package/src/lib/shared/Utils.ts +51 -0
- package/src/lib/shared/index.ts +23 -0
- package/src/lib/transporters/Transporter.decl.ts +117 -0
- package/src/lib/transporters/http-listener/AbstractHttpListener.ts +57 -0
- package/src/lib/transporters/http-listener/Http.Decl.ts +141 -0
- package/src/lib/transporters/http-listener/HttpListener.ts +102 -0
- package/src/lib/transporters/http-listener/HttpUnixSocketListener.ts +97 -0
- package/src/lib/transporters/http-listener/HttpsListener.ts +102 -0
- package/src/lib/transporters/http-listener/index.ts +20 -0
- package/src/lib/transporters/index.ts +17 -0
- package/src/lib/transporters/legacy-http/LegacyHttp.Server.ts +262 -0
- package/src/lib/transporters/legacy-http/LegacyHttp.Transporter.ts +66 -0
- package/src/lib/transporters/legacy-http/index.ts +18 -0
- package/src/lib/transporters/lwdfx/LwDFX.Tcp.Client.ts +34 -0
- package/src/lib/transporters/lwdfx/LwDFX.Tcp.Server.ts +94 -0
- package/src/lib/transporters/lwdfx/LwDFX.Tls.Client.ts +34 -0
- package/src/lib/transporters/lwdfx/LwDFX.Tls.Server.ts +94 -0
- package/src/lib/transporters/lwdfx/LwDFX.Transporter.ts +100 -0
- package/src/lib/transporters/lwdfx/LwDFX.UnixSocket.Client.ts +34 -0
- package/src/lib/transporters/lwdfx/LwDFX.UnixSocket.Server.ts +94 -0
- package/src/lib/transporters/lwdfx/LwDFX.decl.ts +19 -0
- package/src/lib/transporters/lwdfx/index.ts +23 -0
- package/src/lib/transporters/memory/Memory.Impl.ts +363 -0
- package/src/lib/transporters/memory/index.ts +17 -0
- package/src/lib/transporters/websocket/WebSocket.Client.ts +76 -0
- package/src/lib/transporters/websocket/WebSocket.Server.ts +118 -0
- package/src/lib/transporters/websocket/WebSocket.Transporter.ts +132 -0
- package/src/lib/transporters/websocket/WebSocket.decl.ts +21 -0
- package/src/lib/transporters/websocket/index.ts +19 -0
- package/lib/Client/BuiltInRIDGenerator.d.ts +0 -4
- package/lib/Client/BuiltInRIDGenerator.d.ts.map +0 -1
- package/lib/Client/BuiltInRIDGenerator.js +0 -18
- package/lib/Client/BuiltInRIDGenerator.js.map +0 -1
- package/lib/Client/Common.d.ts +0 -47
- package/lib/Client/Common.d.ts.map +0 -1
- package/lib/Client/Common.js +0 -18
- package/lib/Client/Common.js.map +0 -1
- package/lib/Client/Errors.d.ts +0 -26
- package/lib/Client/Errors.d.ts.map +0 -1
- package/lib/Client/Errors.js +0 -80
- package/lib/Client/Errors.js.map +0 -1
- package/lib/Client/HttpClient.d.ts +0 -37
- package/lib/Client/HttpClient.d.ts.map +0 -1
- package/lib/Client/HttpClient.js +0 -148
- package/lib/Client/HttpClient.js.map +0 -1
- package/lib/Client/HttpsClient.d.ts +0 -40
- package/lib/Client/HttpsClient.d.ts.map +0 -1
- package/lib/Client/HttpsClient.js +0 -144
- package/lib/Client/HttpsClient.js.map +0 -1
- package/lib/Client/TCPClient.d.ts +0 -34
- package/lib/Client/TCPClient.d.ts.map +0 -1
- package/lib/Client/TCPClient.js +0 -271
- package/lib/Client/TCPClient.js.map +0 -1
- package/lib/Client/TLSClient.d.ts +0 -34
- package/lib/Client/TLSClient.d.ts.map +0 -1
- package/lib/Client/TLSClient.js +0 -265
- package/lib/Client/TLSClient.js.map +0 -1
- package/lib/Client/index.d.ts +0 -23
- package/lib/Client/index.d.ts.map +0 -1
- package/lib/Client/index.js +0 -39
- package/lib/Client/index.js.map +0 -1
- package/lib/Common/API.d.ts +0 -19
- package/lib/Common/API.d.ts.map +0 -1
- package/lib/Common/API.js +0 -18
- package/lib/Common/API.js.map +0 -1
- package/lib/Common/Encoding.d.ts +0 -32
- package/lib/Common/Encoding.d.ts.map +0 -1
- package/lib/Common/Encoding.js +0 -20
- package/lib/Common/Encoding.js.map +0 -1
- package/lib/Common/Request.d.ts +0 -23
- package/lib/Common/Request.d.ts.map +0 -1
- package/lib/Common/Request.js +0 -18
- package/lib/Common/Request.js.map +0 -1
- package/lib/Common/Response.d.ts +0 -60
- package/lib/Common/Response.d.ts.map +0 -1
- package/lib/Common/Response.js +0 -42
- package/lib/Common/Response.js.map +0 -1
- package/lib/Common/index.d.ts +0 -20
- package/lib/Common/index.d.ts.map +0 -1
- package/lib/Common/index.js +0 -36
- package/lib/Common/index.js.map +0 -1
- package/lib/Encoder/Decoder.d.ts +0 -18
- package/lib/Encoder/Decoder.d.ts.map +0 -1
- package/lib/Encoder/Decoder.js +0 -136
- package/lib/Encoder/Decoder.js.map +0 -1
- package/lib/Encoder/Encoder.d.ts +0 -18
- package/lib/Encoder/Encoder.d.ts.map +0 -1
- package/lib/Encoder/Encoder.js +0 -35
- package/lib/Encoder/Encoder.js.map +0 -1
- package/lib/Encoder/Errors.d.ts +0 -17
- package/lib/Encoder/Errors.d.ts.map +0 -1
- package/lib/Encoder/Errors.js +0 -26
- package/lib/Encoder/Errors.js.map +0 -1
- package/lib/Errors.d.ts +0 -20
- package/lib/Errors.d.ts.map +0 -1
- package/lib/Errors.js +0 -40
- package/lib/Errors.js.map +0 -1
- package/lib/Server/Common/Gateway.d.ts +0 -26
- package/lib/Server/Common/Gateway.d.ts.map +0 -1
- package/lib/Server/Common/Gateway.js +0 -18
- package/lib/Server/Common/Gateway.js.map +0 -1
- package/lib/Server/Common/Request.d.ts +0 -21
- package/lib/Server/Common/Request.d.ts.map +0 -1
- package/lib/Server/Common/Request.js +0 -18
- package/lib/Server/Common/Request.js.map +0 -1
- package/lib/Server/Common/Router.d.ts +0 -41
- package/lib/Server/Common/Router.d.ts.map +0 -1
- package/lib/Server/Common/Router.js +0 -18
- package/lib/Server/Common/Router.js.map +0 -1
- package/lib/Server/Common/Server.d.ts +0 -57
- package/lib/Server/Common/Server.d.ts.map +0 -1
- package/lib/Server/Common/Server.js +0 -18
- package/lib/Server/Common/Server.js.map +0 -1
- package/lib/Server/Common/index.d.ts +0 -20
- package/lib/Server/Common/index.d.ts.map +0 -1
- package/lib/Server/Common/index.js +0 -36
- package/lib/Server/Common/index.js.map +0 -1
- package/lib/Server/Errors.d.ts +0 -25
- package/lib/Server/Errors.d.ts.map +0 -1
- package/lib/Server/Errors.js +0 -74
- package/lib/Server/Errors.js.map +0 -1
- package/lib/Server/Gateways/Http.d.ts +0 -18
- package/lib/Server/Gateways/Http.d.ts.map +0 -1
- package/lib/Server/Gateways/Http.js +0 -148
- package/lib/Server/Gateways/Http.js.map +0 -1
- package/lib/Server/Gateways/TCP.d.ts +0 -23
- package/lib/Server/Gateways/TCP.d.ts.map +0 -1
- package/lib/Server/Gateways/TCP.js +0 -146
- package/lib/Server/Gateways/TCP.js.map +0 -1
- package/lib/Server/Server.d.ts +0 -18
- package/lib/Server/Server.d.ts.map +0 -1
- package/lib/Server/Server.js +0 -200
- package/lib/Server/Server.js.map +0 -1
- package/lib/Server/SimpleRouter.d.ts +0 -41
- package/lib/Server/SimpleRouter.d.ts.map +0 -1
- package/lib/Server/SimpleRouter.js +0 -54
- package/lib/Server/SimpleRouter.js.map +0 -1
- package/lib/Server/index.d.ts +0 -22
- package/lib/Server/index.d.ts.map +0 -1
- package/lib/Server/index.js +0 -38
- package/lib/Server/index.js.map +0 -1
- package/src/lib/Client/BuiltInRIDGenerator.ts +0 -21
- package/src/lib/Client/Common.ts +0 -63
- package/src/lib/Client/Errors.ts +0 -87
- package/src/lib/Client/HttpClient.ts +0 -232
- package/src/lib/Client/HttpsClient.ts +0 -238
- package/src/lib/Client/TCPClient.ts +0 -420
- package/src/lib/Client/TLSClient.ts +0 -422
- package/src/lib/Client/index.ts +0 -23
- package/src/lib/Common/API.ts +0 -20
- package/src/lib/Common/Encoding.ts +0 -42
- package/src/lib/Common/Request.ts +0 -28
- package/src/lib/Common/Response.ts +0 -67
- package/src/lib/Common/index.ts +0 -20
- package/src/lib/Encoder/Decoder.ts +0 -206
- package/src/lib/Encoder/Encoder.ts +0 -41
- package/src/lib/Encoder/Errors.ts +0 -24
- package/src/lib/Errors.ts +0 -40
- package/src/lib/Server/Common/Gateway.ts +0 -37
- package/src/lib/Server/Common/Request.ts +0 -24
- package/src/lib/Server/Common/Router.ts +0 -52
- package/src/lib/Server/Common/Server.ts +0 -68
- package/src/lib/Server/Common/index.ts +0 -20
- package/src/lib/Server/Errors.ts +0 -80
- package/src/lib/Server/Gateways/Http.ts +0 -209
- package/src/lib/Server/Gateways/TCP.ts +0 -221
- package/src/lib/Server/Server.ts +0 -268
- package/src/lib/Server/SimpleRouter.ts +0 -95
- package/src/lib/Server/index.ts +0 -22
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Angus.Fenying <fenying@litert.org>
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import * as Shared from './Shared.decl';
|
|
18
|
+
import * as E from './Errors';
|
|
19
|
+
import type * as dT from '../transporters/Transporter.decl';
|
|
20
|
+
import { EventEmitter } from 'node:events';
|
|
21
|
+
import * as v2 from './Encodings/v2';
|
|
22
|
+
import { once } from './Utils';
|
|
23
|
+
|
|
24
|
+
export interface IChannelEvents extends Shared.IDefaultEvents {
|
|
25
|
+
|
|
26
|
+
close(): void;
|
|
27
|
+
|
|
28
|
+
['api_call'](
|
|
29
|
+
callback: (response: v2.IDataChunkField | E.TelevokeError | E.TvErrorResponse) => void,
|
|
30
|
+
name: string,
|
|
31
|
+
args: Buffer[],
|
|
32
|
+
sequence: number,
|
|
33
|
+
): void;
|
|
34
|
+
|
|
35
|
+
['push_message'](
|
|
36
|
+
message: Buffer[],
|
|
37
|
+
sequence: number,
|
|
38
|
+
): void;
|
|
39
|
+
|
|
40
|
+
end(): void;
|
|
41
|
+
|
|
42
|
+
finish(): void;
|
|
43
|
+
|
|
44
|
+
warning(e: unknown): void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const DEFAULT_PING_MESSAGE = Buffer.from('PING');
|
|
48
|
+
|
|
49
|
+
export const decoder = new v2.TvDecoderV2();
|
|
50
|
+
export const encoder = new v2.TvEncoderV2();
|
|
51
|
+
|
|
52
|
+
export interface IPendingRequests {
|
|
53
|
+
|
|
54
|
+
cmd: v2.ECommand;
|
|
55
|
+
|
|
56
|
+
seq: number;
|
|
57
|
+
|
|
58
|
+
timer?: NodeJS.Timeout;
|
|
59
|
+
|
|
60
|
+
callback: (cmd: v2.ICommandPacket) => void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
enum EState {
|
|
64
|
+
ACTIVE,
|
|
65
|
+
ENDING,
|
|
66
|
+
ENDED,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export abstract class AbstractTvChannelV2
|
|
70
|
+
extends EventEmitter
|
|
71
|
+
implements Shared.IChannelBase<IChannelEvents> {
|
|
72
|
+
|
|
73
|
+
protected _seqCounter = 0;
|
|
74
|
+
|
|
75
|
+
public readonly context: Record<string, unknown> = {};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The context of requests sent out, waiting for replies.
|
|
79
|
+
*/
|
|
80
|
+
protected _sentRequests: Record<string, IPendingRequests> = {};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The qty of received and not responded requests, waiting for replies.
|
|
84
|
+
*/
|
|
85
|
+
protected _recvRequests: number = 0;
|
|
86
|
+
|
|
87
|
+
private _state: EState = EState.ACTIVE;
|
|
88
|
+
|
|
89
|
+
public ended: boolean = false;
|
|
90
|
+
|
|
91
|
+
public get finished(): boolean {
|
|
92
|
+
|
|
93
|
+
return this._state === EState.ENDED;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public get writable(): boolean {
|
|
97
|
+
|
|
98
|
+
return this._state === EState.ACTIVE && this.transporter.writable;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public readonly streams: Shared.IStreamManager;
|
|
102
|
+
|
|
103
|
+
public constructor(
|
|
104
|
+
public readonly id: number,
|
|
105
|
+
public readonly transporter: dT.ITransporter & Shared.ITransporter,
|
|
106
|
+
public timeout: number,
|
|
107
|
+
streamManagerFactory: Shared.IStreamManagerFactory
|
|
108
|
+
) {
|
|
109
|
+
|
|
110
|
+
super();
|
|
111
|
+
|
|
112
|
+
this.streams = streamManagerFactory(this as any);
|
|
113
|
+
|
|
114
|
+
this._setup();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private readonly _onData = (frameChunks: Buffer[]): void => {
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
|
|
121
|
+
const packet = decoder.decode(frameChunks);
|
|
122
|
+
|
|
123
|
+
switch (packet.typ) {
|
|
124
|
+
case v2.EPacketType.REQUEST:
|
|
125
|
+
this._onRequest(packet);
|
|
126
|
+
break;
|
|
127
|
+
case v2.EPacketType.ERROR_RESPONSE:
|
|
128
|
+
case v2.EPacketType.SUCCESS_RESPONSE:
|
|
129
|
+
|
|
130
|
+
this._onResponse(packet);
|
|
131
|
+
break;
|
|
132
|
+
default:
|
|
133
|
+
this.emit('error', new E.errors.invalid_packet({
|
|
134
|
+
reason: 'invalid_packet_type',
|
|
135
|
+
packet,
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
|
|
141
|
+
this._end();
|
|
142
|
+
|
|
143
|
+
this.emit('error', e);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
private readonly _onConnError = (e: unknown): void => {
|
|
148
|
+
|
|
149
|
+
this.emit('error', e);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
private readonly _onConnClose = (): void => {
|
|
153
|
+
|
|
154
|
+
for (const k of Object.keys(this._sentRequests)) {
|
|
155
|
+
|
|
156
|
+
const req = this._sentRequests[k];
|
|
157
|
+
delete this._sentRequests[k];
|
|
158
|
+
|
|
159
|
+
if (req.timer) {
|
|
160
|
+
|
|
161
|
+
clearTimeout(req.timer);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
|
|
166
|
+
req.callback({
|
|
167
|
+
'cmd': req.cmd,
|
|
168
|
+
'typ': v2.EPacketType.ERROR_RESPONSE,
|
|
169
|
+
'seq': req.seq,
|
|
170
|
+
'ct': new E.errors.channel_closed(),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
|
|
175
|
+
this.emit('warning', e);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
this.ended = true;
|
|
180
|
+
this._state = EState.ENDED;
|
|
181
|
+
this.emit('close');
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
private readonly _onRemoteEnded = (): void => {
|
|
185
|
+
|
|
186
|
+
if (this.ended) { return; }
|
|
187
|
+
|
|
188
|
+
this.ended = true;
|
|
189
|
+
this._state = EState.ENDING;
|
|
190
|
+
|
|
191
|
+
this.emit('end');
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
private readonly _onLocalEnded = (): void => {
|
|
195
|
+
|
|
196
|
+
if (this._state === EState.ENDED) { return; }
|
|
197
|
+
|
|
198
|
+
this._state = EState.ENDED;
|
|
199
|
+
this.emit('finish');
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
private _setup(): void {
|
|
203
|
+
|
|
204
|
+
this.transporter
|
|
205
|
+
.on('frame', this._onData)
|
|
206
|
+
.on('error', this._onConnError)
|
|
207
|
+
.on('close', this._onConnClose)
|
|
208
|
+
.on('end', this._onRemoteEnded)
|
|
209
|
+
.on('finish', this._onLocalEnded);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private _end(): void {
|
|
213
|
+
|
|
214
|
+
// for (const id of Object.keys(this._streams)) {
|
|
215
|
+
|
|
216
|
+
// this._streams[id].abort();
|
|
217
|
+
// delete this._streams[id];
|
|
218
|
+
// }
|
|
219
|
+
|
|
220
|
+
if (this._isIdle()) {
|
|
221
|
+
|
|
222
|
+
this._state = EState.ENDED;
|
|
223
|
+
|
|
224
|
+
this.transporter.end();
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
|
|
228
|
+
this._state = EState.ENDING;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private _tryClean(): void {
|
|
233
|
+
|
|
234
|
+
if (this._state !== EState.ENDING) {
|
|
235
|
+
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (this._isIdle()) {
|
|
240
|
+
|
|
241
|
+
this._state = EState.ENDED;
|
|
242
|
+
|
|
243
|
+
this.transporter.end();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
private _isIdle(): boolean {
|
|
248
|
+
|
|
249
|
+
return Object.keys(this._sentRequests).length === 0 && this._recvRequests === 0;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
private _onResponse(packet: v2.ICommandPacket): void {
|
|
253
|
+
|
|
254
|
+
const request = this._sentRequests[packet.seq];
|
|
255
|
+
|
|
256
|
+
if (!request) {
|
|
257
|
+
|
|
258
|
+
// Timeout response, drop it.
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
delete this._sentRequests[request.seq];
|
|
263
|
+
|
|
264
|
+
if (request.timer !== undefined) {
|
|
265
|
+
|
|
266
|
+
clearTimeout(request.timer);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (request.cmd !== packet.cmd) {
|
|
270
|
+
|
|
271
|
+
request.callback({
|
|
272
|
+
typ: v2.EPacketType.ERROR_RESPONSE,
|
|
273
|
+
seq: request.seq,
|
|
274
|
+
cmd: request.cmd,
|
|
275
|
+
ct: new E.errors.invalid_response({
|
|
276
|
+
reason: 'mismatched_command',
|
|
277
|
+
packet,
|
|
278
|
+
})
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
this._end();
|
|
282
|
+
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
request.callback(packet);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
private _reply(packet: v2.ICommandPacket): void {
|
|
290
|
+
|
|
291
|
+
try {
|
|
292
|
+
|
|
293
|
+
this.transporter.write(encoder.encode(packet));
|
|
294
|
+
}
|
|
295
|
+
catch (e) {
|
|
296
|
+
|
|
297
|
+
// ignore errors here.
|
|
298
|
+
this.emit('warning', e);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
private _onRequest(packet: v2.ICommandPacket): void {
|
|
303
|
+
|
|
304
|
+
if (this._state !== EState.ACTIVE) {
|
|
305
|
+
|
|
306
|
+
this._reply({
|
|
307
|
+
'cmd': packet.cmd,
|
|
308
|
+
'typ': v2.EPacketType.ERROR_RESPONSE,
|
|
309
|
+
'seq': packet.seq,
|
|
310
|
+
'ct': new E.errors.channel_inactive()
|
|
311
|
+
});
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
switch (packet.cmd) {
|
|
316
|
+
|
|
317
|
+
default:
|
|
318
|
+
|
|
319
|
+
this._reply({
|
|
320
|
+
'cmd': packet.cmd,
|
|
321
|
+
'typ': v2.EPacketType.ERROR_RESPONSE,
|
|
322
|
+
'seq': packet.seq,
|
|
323
|
+
'ct': new E.errors.invalid_packet({
|
|
324
|
+
reason: 'unknown_command',
|
|
325
|
+
packet,
|
|
326
|
+
})
|
|
327
|
+
});
|
|
328
|
+
return;
|
|
329
|
+
|
|
330
|
+
case v2.ECommand.CLOSE:
|
|
331
|
+
|
|
332
|
+
this.on('finish', () => {
|
|
333
|
+
|
|
334
|
+
this._reply({
|
|
335
|
+
'cmd': v2.ECommand.CLOSE,
|
|
336
|
+
'typ': v2.EPacketType.SUCCESS_RESPONSE,
|
|
337
|
+
'seq': packet.seq,
|
|
338
|
+
'ct': new E.errors.invalid_packet({
|
|
339
|
+
reason: 'unknown_command',
|
|
340
|
+
packet,
|
|
341
|
+
})
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
this._end();
|
|
346
|
+
return;
|
|
347
|
+
|
|
348
|
+
case v2.ECommand.PING:
|
|
349
|
+
|
|
350
|
+
this._reply({
|
|
351
|
+
'cmd': v2.ECommand.PING,
|
|
352
|
+
'typ': v2.EPacketType.SUCCESS_RESPONSE,
|
|
353
|
+
'seq': packet.seq,
|
|
354
|
+
'ct': packet.ct,
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
this.emit('ping');
|
|
358
|
+
|
|
359
|
+
return;
|
|
360
|
+
|
|
361
|
+
case v2.ECommand.PUSH_MESSAGE:
|
|
362
|
+
|
|
363
|
+
if (!this.listenerCount('push_message')) {
|
|
364
|
+
|
|
365
|
+
this._reply({
|
|
366
|
+
'cmd': v2.ECommand.PUSH_MESSAGE,
|
|
367
|
+
'typ': v2.EPacketType.ERROR_RESPONSE,
|
|
368
|
+
'seq': packet.seq,
|
|
369
|
+
'ct': new E.errors.cmd_not_impl()
|
|
370
|
+
});
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
this._reply({
|
|
375
|
+
'cmd': v2.ECommand.PUSH_MESSAGE,
|
|
376
|
+
'typ': v2.EPacketType.SUCCESS_RESPONSE,
|
|
377
|
+
'seq': packet.seq,
|
|
378
|
+
'ct': null,
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
this.emit('push_message', packet.ct as Buffer[], packet.seq);
|
|
382
|
+
|
|
383
|
+
break;
|
|
384
|
+
|
|
385
|
+
case v2.ECommand.API_CALL:
|
|
386
|
+
|
|
387
|
+
if (!this.listenerCount('api_call')) {
|
|
388
|
+
|
|
389
|
+
this._reply({
|
|
390
|
+
'cmd': v2.ECommand.API_CALL,
|
|
391
|
+
'typ': v2.EPacketType.ERROR_RESPONSE,
|
|
392
|
+
'seq': packet.seq,
|
|
393
|
+
'ct': new E.errors.cmd_not_impl()
|
|
394
|
+
});
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
this._recvRequests++;
|
|
399
|
+
|
|
400
|
+
this.emit(
|
|
401
|
+
'api_call',
|
|
402
|
+
once((response: v2.IDataChunkField | E.TelevokeError) => {
|
|
403
|
+
|
|
404
|
+
this._recvRequests--;
|
|
405
|
+
|
|
406
|
+
this._reply({
|
|
407
|
+
'cmd': v2.ECommand.API_CALL,
|
|
408
|
+
'typ': response instanceof E.TelevokeError ?
|
|
409
|
+
v2.EPacketType.ERROR_RESPONSE :
|
|
410
|
+
v2.EPacketType.SUCCESS_RESPONSE,
|
|
411
|
+
'seq': packet.seq,
|
|
412
|
+
'ct': response,
|
|
413
|
+
});
|
|
414
|
+
this._tryClean();
|
|
415
|
+
}),
|
|
416
|
+
(packet as v2.IApiRequestPacket).ct.name,
|
|
417
|
+
(packet as v2.IApiRequestPacket).ct.body,
|
|
418
|
+
packet.seq
|
|
419
|
+
);
|
|
420
|
+
|
|
421
|
+
break;
|
|
422
|
+
|
|
423
|
+
case v2.ECommand.BINARY_CHUNK: {
|
|
424
|
+
|
|
425
|
+
const stream = this.streams.get((packet as v2.IBinaryChunkRequestPacket).ct.streamId)!;
|
|
426
|
+
|
|
427
|
+
if (!stream) {
|
|
428
|
+
|
|
429
|
+
this._reply({
|
|
430
|
+
'cmd': v2.ECommand.BINARY_CHUNK,
|
|
431
|
+
'typ': v2.EPacketType.ERROR_RESPONSE,
|
|
432
|
+
'seq': packet.seq,
|
|
433
|
+
'ct': new E.errors.stream_not_found({
|
|
434
|
+
'sid': (packet as v2.IBinaryChunkRequestPacket).ct.streamId,
|
|
435
|
+
'chId': this.id,
|
|
436
|
+
}),
|
|
437
|
+
});
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const chunkSegments = (packet as v2.IBinaryChunkRequestPacket).ct.body as Buffer[];
|
|
442
|
+
|
|
443
|
+
const chunkIndex = (packet as v2.IBinaryChunkRequestPacket).ct.index;
|
|
444
|
+
|
|
445
|
+
if (chunkIndex === 0xFFFFFFFF) {
|
|
446
|
+
|
|
447
|
+
stream.abort();
|
|
448
|
+
}
|
|
449
|
+
else if (chunkIndex !== stream.nextIndex) {
|
|
450
|
+
|
|
451
|
+
this._reply({
|
|
452
|
+
'cmd': v2.ECommand.BINARY_CHUNK,
|
|
453
|
+
'typ': v2.EPacketType.ERROR_RESPONSE,
|
|
454
|
+
'seq': packet.seq,
|
|
455
|
+
'ct': new E.errors.stream_index_mismatch({
|
|
456
|
+
'sid': (packet as v2.IBinaryChunkRequestPacket).ct.streamId,
|
|
457
|
+
'chId': this.id,
|
|
458
|
+
}),
|
|
459
|
+
});
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
else if (!chunkSegments[0]?.byteLength) {
|
|
463
|
+
|
|
464
|
+
stream.close();
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
|
|
468
|
+
stream.append(chunkSegments);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
this._reply({
|
|
472
|
+
'cmd': v2.ECommand.BINARY_CHUNK,
|
|
473
|
+
'typ': v2.EPacketType.SUCCESS_RESPONSE,
|
|
474
|
+
'seq': packet.seq,
|
|
475
|
+
'ct': null,
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
protected _setTimeout(cmd: v2.ECommand, seq: number, callback: (packet: v2.ICommandPacket) => any): void {
|
|
484
|
+
|
|
485
|
+
const req: IPendingRequests = this._sentRequests[seq] = {
|
|
486
|
+
'cmd': cmd,
|
|
487
|
+
'seq': seq,
|
|
488
|
+
'callback': callback,
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
if (this.timeout < 1 || !req) {
|
|
492
|
+
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
req.timer = setTimeout(() => {
|
|
497
|
+
|
|
498
|
+
if (!req.timer) {
|
|
499
|
+
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
delete this._sentRequests[req.seq];
|
|
504
|
+
|
|
505
|
+
req.callback({
|
|
506
|
+
'cmd': req.cmd,
|
|
507
|
+
'typ': v2.EPacketType.ERROR_RESPONSE,
|
|
508
|
+
'seq': req.seq,
|
|
509
|
+
'ct': new E.errors.timeout(),
|
|
510
|
+
});
|
|
511
|
+
}, this.timeout);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
public openBinaryStream(): Shared.IBinaryReadStream {
|
|
515
|
+
|
|
516
|
+
if (!this.writable || !this.streams) {
|
|
517
|
+
|
|
518
|
+
throw new E.errors.channel_inactive();
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
return this.streams.create();
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
public ping(message?: Buffer | string): Promise<Buffer> {
|
|
525
|
+
|
|
526
|
+
if (!this.writable) {
|
|
527
|
+
|
|
528
|
+
return Promise.reject(new E.errors.channel_inactive());
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
message ??= DEFAULT_PING_MESSAGE;
|
|
532
|
+
|
|
533
|
+
const seq = this._seqCounter++;
|
|
534
|
+
|
|
535
|
+
this.transporter.write(encoder.encode({
|
|
536
|
+
'cmd': v2.ECommand.PING,
|
|
537
|
+
'typ': v2.EPacketType.REQUEST,
|
|
538
|
+
'seq': seq,
|
|
539
|
+
'ct': message,
|
|
540
|
+
} satisfies v2.IPingRequestPacket));
|
|
541
|
+
|
|
542
|
+
return new Promise((resolve, reject) => {
|
|
543
|
+
|
|
544
|
+
this._setTimeout(v2.ECommand.PING, seq, (p) => {
|
|
545
|
+
|
|
546
|
+
if (p.typ === v2.EPacketType.SUCCESS_RESPONSE) {
|
|
547
|
+
|
|
548
|
+
if (Array.isArray(p.ct)) {
|
|
549
|
+
|
|
550
|
+
resolve(Buffer.concat(p.ct as Buffer[]));
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
|
|
554
|
+
resolve(p.ct as Buffer);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
else {
|
|
558
|
+
|
|
559
|
+
reject(p.ct);
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
public sendBinaryChunk(streamId: number, index: number | false, chunk: Buffer | null): Promise<void> {
|
|
566
|
+
|
|
567
|
+
if (!this.writable) {
|
|
568
|
+
|
|
569
|
+
return Promise.reject(new E.errors.channel_inactive());
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const seq = this._seqCounter++;
|
|
573
|
+
|
|
574
|
+
this.transporter.write(encoder.encode({
|
|
575
|
+
'cmd': v2.ECommand.BINARY_CHUNK,
|
|
576
|
+
'typ': v2.EPacketType.REQUEST,
|
|
577
|
+
'seq': seq,
|
|
578
|
+
'ct': {
|
|
579
|
+
streamId,
|
|
580
|
+
'index': index === false ? 0xFFFFFFFF : index,
|
|
581
|
+
'body': chunk ?? [],
|
|
582
|
+
}
|
|
583
|
+
} satisfies v2.IBinaryChunkRequestPacket));
|
|
584
|
+
|
|
585
|
+
return new Promise((resolve, reject) => {
|
|
586
|
+
|
|
587
|
+
this._setTimeout(v2.ECommand.BINARY_CHUNK, seq, (p) => {
|
|
588
|
+
|
|
589
|
+
if (p.typ === v2.EPacketType.SUCCESS_RESPONSE) {
|
|
590
|
+
|
|
591
|
+
resolve();
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
|
|
595
|
+
reject(p.ct);
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
public sendMessage(message: string | Buffer): Promise<void> {
|
|
602
|
+
|
|
603
|
+
if (!this.writable) {
|
|
604
|
+
|
|
605
|
+
return Promise.reject(new E.errors.channel_inactive());
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
const seq = this._seqCounter++;
|
|
609
|
+
|
|
610
|
+
this.transporter.write(encoder.encode({
|
|
611
|
+
'cmd': v2.ECommand.PUSH_MESSAGE,
|
|
612
|
+
'typ': v2.EPacketType.REQUEST,
|
|
613
|
+
'seq': seq,
|
|
614
|
+
'ct': message,
|
|
615
|
+
} satisfies v2.IPushMessageRequestPacket));
|
|
616
|
+
|
|
617
|
+
return new Promise((resolve, reject) => {
|
|
618
|
+
|
|
619
|
+
this._setTimeout(v2.ECommand.PUSH_MESSAGE, seq, (p) => {
|
|
620
|
+
|
|
621
|
+
if (p.typ === v2.EPacketType.SUCCESS_RESPONSE) {
|
|
622
|
+
|
|
623
|
+
resolve();
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
|
|
627
|
+
reject(p.ct);
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
public close(): void {
|
|
634
|
+
|
|
635
|
+
if (!this.writable) {
|
|
636
|
+
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
const seq = this._seqCounter++;
|
|
641
|
+
|
|
642
|
+
try {
|
|
643
|
+
|
|
644
|
+
this.transporter.write(encoder.encode({
|
|
645
|
+
'cmd': v2.ECommand.CLOSE,
|
|
646
|
+
'typ': v2.EPacketType.REQUEST,
|
|
647
|
+
'seq': seq,
|
|
648
|
+
'ct': null,
|
|
649
|
+
} satisfies v2.ICloseRequestPacket));
|
|
650
|
+
}
|
|
651
|
+
catch {
|
|
652
|
+
|
|
653
|
+
// ignore errors here.
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
this._end();
|
|
657
|
+
}
|
|
658
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Angus.Fenying <fenying@litert.org>
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The namespace of protocol errors.
|
|
19
|
+
*/
|
|
20
|
+
export const PROTOCOL_ERROR_NAMESPACE = 'tv_error';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The namespace of application layer errors.
|
|
24
|
+
*/
|
|
25
|
+
export const APP_ERROR_NAMESPACE = 'app_error';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The default timeout value of each new binary stream.
|
|
29
|
+
*/
|
|
30
|
+
export const DEFAULT_STREAM_TIMEOUT = 30_000;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The default maximum number of streams of a stream manager.
|
|
34
|
+
*/
|
|
35
|
+
export const DEFAULT_MAX_STREAMS = 10;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Angus.Fenying <fenying@litert.org>
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export * as v1 from './v1';
|
|
18
|
+
export * as v2 from './v2';
|