camstreamerlib 4.0.0-beta.2 → 4.0.0-beta.4

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.
Files changed (162) hide show
  1. package/cjs/CamOverlayAPI.js +176 -0
  2. package/cjs/CamOverlayDrawingAPI.js +235 -0
  3. package/cjs/CamOverlayPainter/Frame.js +301 -0
  4. package/{CamOverlayPainter → cjs/CamOverlayPainter}/Painter.d.ts +14 -3
  5. package/cjs/CamOverlayPainter/Painter.js +171 -0
  6. package/cjs/CamOverlayPainter/ResourceManager.js +46 -0
  7. package/cjs/CamScripterAPI.js +70 -0
  8. package/cjs/CamScripterAPICameraEventsGenerator.js +162 -0
  9. package/cjs/CamStreamerAPI.js +65 -0
  10. package/{CamSwitcherAPI.d.ts → cjs/CamSwitcherAPI.d.ts} +3 -3
  11. package/cjs/CamSwitcherAPI.js +350 -0
  12. package/{CamSwitcherEvents.d.ts → cjs/CamSwitcherEvents.d.ts} +1 -1
  13. package/cjs/CamSwitcherEvents.js +67 -0
  14. package/cjs/CreatePackage.js +106 -0
  15. package/{VapixAPI.d.ts → cjs/VapixAPI.d.ts} +9 -9
  16. package/cjs/VapixAPI.js +462 -0
  17. package/cjs/VapixEvents.js +88 -0
  18. package/cjs/errors/errors.js +79 -0
  19. package/cjs/events/AxisCameraStationEvents.js +48 -0
  20. package/cjs/events/GenetecAgent.js +123 -0
  21. package/cjs/index.d.ts +11 -0
  22. package/cjs/index.js +31 -0
  23. package/cjs/internal/Digest.js +42 -0
  24. package/cjs/internal/ProxyClient.js +44 -0
  25. package/{internal → cjs/internal}/common.d.ts +0 -1
  26. package/cjs/internal/common.js +27 -0
  27. package/cjs/internal/constants.js +4 -0
  28. package/cjs/internal/transformers.js +32 -0
  29. package/cjs/internal/utils.js +46 -0
  30. package/cjs/internal/versionCompare.js +53 -0
  31. package/cjs/node/DefaultClient.js +54 -0
  32. package/cjs/node/HttpRequestSender.js +89 -0
  33. package/cjs/node/HttpServer.js +96 -0
  34. package/cjs/node/WsClient.js +149 -0
  35. package/cjs/node/WsEventClient.js +22 -0
  36. package/cjs/node/index.d.ts +2 -0
  37. package/cjs/node/index.js +7 -0
  38. package/cjs/types/CamOverlayAPI.js +47 -0
  39. package/cjs/types/CamScripterAPI.js +20 -0
  40. package/cjs/types/CamStreamerAPI.js +28 -0
  41. package/cjs/types/CamSwitcherAPI.js +137 -0
  42. package/cjs/types/CamSwitcherEvents.js +62 -0
  43. package/{types → cjs/types}/VapixAPI.d.ts +40 -61
  44. package/cjs/types/VapixAPI.js +130 -0
  45. package/cjs/types/common.js +14 -0
  46. package/cjs/web/DefaultClient.js +20 -0
  47. package/cjs/web/WsClient.js +62 -0
  48. package/cjs/web/index.d.ts +2 -0
  49. package/cjs/web/index.js +7 -0
  50. package/esm/CamOverlayAPI.d.ts +31 -0
  51. package/esm/CamOverlayDrawingAPI.d.ts +86 -0
  52. package/{CamOverlayDrawingAPI.js → esm/CamOverlayDrawingAPI.js} +6 -3
  53. package/esm/CamOverlayPainter/Frame.d.ts +96 -0
  54. package/esm/CamOverlayPainter/Painter.d.ts +48 -0
  55. package/{CamOverlayPainter → esm/CamOverlayPainter}/Painter.js +4 -1
  56. package/esm/CamOverlayPainter/ResourceManager.d.ts +14 -0
  57. package/{CamOverlayPainter → esm/CamOverlayPainter}/ResourceManager.js +6 -10
  58. package/esm/CamScripterAPI.d.ts +19 -0
  59. package/esm/CamScripterAPICameraEventsGenerator.d.ts +74 -0
  60. package/{CamScripterAPICameraEventsGenerator.js → esm/CamScripterAPICameraEventsGenerator.js} +6 -3
  61. package/esm/CamStreamerAPI.d.ts +16 -0
  62. package/esm/CamSwitcherAPI.d.ts +48 -0
  63. package/{CamSwitcherAPI.js → esm/CamSwitcherAPI.js} +19 -23
  64. package/esm/CamSwitcherEvents.d.ts +18 -0
  65. package/{CamSwitcherEvents.js → esm/CamSwitcherEvents.js} +1 -1
  66. package/esm/CreatePackage.d.ts +1 -0
  67. package/esm/VapixAPI.d.ts +66 -0
  68. package/{VapixAPI.js → esm/VapixAPI.js} +20 -16
  69. package/esm/VapixEvents.d.ts +43 -0
  70. package/{VapixEvents.js → esm/VapixEvents.js} +3 -3
  71. package/esm/errors/errors.d.ts +34 -0
  72. package/esm/events/AxisCameraStationEvents.d.ts +9 -0
  73. package/esm/events/GenetecAgent.d.ts +174 -0
  74. package/esm/index.d.ts +11 -0
  75. package/esm/index.js +11 -0
  76. package/esm/internal/Digest.d.ts +4 -0
  77. package/{internal → esm/internal}/Digest.js +6 -6
  78. package/esm/internal/ProxyClient.d.ts +11 -0
  79. package/esm/internal/common.d.ts +39 -0
  80. package/{internal → esm/internal}/common.js +0 -3
  81. package/esm/internal/constants.d.ts +1 -0
  82. package/esm/internal/transformers.d.ts +5 -0
  83. package/esm/internal/utils.d.ts +11 -0
  84. package/esm/internal/versionCompare.d.ts +6 -0
  85. package/esm/node/DefaultClient.d.ts +15 -0
  86. package/{node → esm/node}/DefaultClient.js +1 -1
  87. package/esm/node/HttpRequestSender.d.ts +28 -0
  88. package/esm/node/HttpServer.d.ts +21 -0
  89. package/{node → esm/node}/HttpServer.js +1 -1
  90. package/esm/node/WsClient.d.ts +39 -0
  91. package/esm/node/WsEventClient.d.ts +13 -0
  92. package/esm/node/index.d.ts +2 -0
  93. package/esm/node/index.js +2 -0
  94. package/esm/types/CamOverlayAPI.d.ts +188 -0
  95. package/esm/types/CamScripterAPI.d.ts +67 -0
  96. package/esm/types/CamStreamerAPI.d.ts +139 -0
  97. package/esm/types/CamSwitcherAPI.d.ts +814 -0
  98. package/esm/types/CamSwitcherEvents.d.ts +491 -0
  99. package/esm/types/VapixAPI.d.ts +1683 -0
  100. package/{types → esm/types}/VapixAPI.js +10 -12
  101. package/esm/types/common.d.ts +37 -0
  102. package/esm/web/DefaultClient.d.ts +6 -0
  103. package/esm/web/WsClient.d.ts +13 -0
  104. package/esm/web/index.d.ts +2 -0
  105. package/esm/web/index.js +2 -0
  106. package/package.json +6 -5
  107. package/README.md +0 -97
  108. /package/{CamOverlayAPI.d.ts → cjs/CamOverlayAPI.d.ts} +0 -0
  109. /package/{CamOverlayDrawingAPI.d.ts → cjs/CamOverlayDrawingAPI.d.ts} +0 -0
  110. /package/{CamOverlayPainter → cjs/CamOverlayPainter}/Frame.d.ts +0 -0
  111. /package/{CamOverlayPainter → cjs/CamOverlayPainter}/ResourceManager.d.ts +0 -0
  112. /package/{CamScripterAPI.d.ts → cjs/CamScripterAPI.d.ts} +0 -0
  113. /package/{CamScripterAPICameraEventsGenerator.d.ts → cjs/CamScripterAPICameraEventsGenerator.d.ts} +0 -0
  114. /package/{CamStreamerAPI.d.ts → cjs/CamStreamerAPI.d.ts} +0 -0
  115. /package/{CreatePackage.d.ts → cjs/CreatePackage.d.ts} +0 -0
  116. /package/{VapixEvents.d.ts → cjs/VapixEvents.d.ts} +0 -0
  117. /package/{errors → cjs/errors}/errors.d.ts +0 -0
  118. /package/{events → cjs/events}/AxisCameraStationEvents.d.ts +0 -0
  119. /package/{events → cjs/events}/GenetecAgent.d.ts +0 -0
  120. /package/{internal → cjs/internal}/Digest.d.ts +0 -0
  121. /package/{internal → cjs/internal}/ProxyClient.d.ts +0 -0
  122. /package/{internal → cjs/internal}/constants.d.ts +0 -0
  123. /package/{internal → cjs/internal}/transformers.d.ts +0 -0
  124. /package/{internal → cjs/internal}/utils.d.ts +0 -0
  125. /package/{internal → cjs/internal}/versionCompare.d.ts +0 -0
  126. /package/{node → cjs/node}/DefaultClient.d.ts +0 -0
  127. /package/{node → cjs/node}/HttpRequestSender.d.ts +0 -0
  128. /package/{node → cjs/node}/HttpServer.d.ts +0 -0
  129. /package/{node → cjs/node}/WsClient.d.ts +0 -0
  130. /package/{node → cjs/node}/WsEventClient.d.ts +0 -0
  131. /package/{types → cjs/types}/CamOverlayAPI.d.ts +0 -0
  132. /package/{types → cjs/types}/CamScripterAPI.d.ts +0 -0
  133. /package/{types → cjs/types}/CamStreamerAPI.d.ts +0 -0
  134. /package/{types → cjs/types}/CamSwitcherAPI.d.ts +0 -0
  135. /package/{types/CamswitcherEvents.d.ts → cjs/types/CamSwitcherEvents.d.ts} +0 -0
  136. /package/{types → cjs/types}/common.d.ts +0 -0
  137. /package/{web → cjs/web}/DefaultClient.d.ts +0 -0
  138. /package/{web → cjs/web}/WsClient.d.ts +0 -0
  139. /package/{CamOverlayAPI.js → esm/CamOverlayAPI.js} +0 -0
  140. /package/{CamOverlayPainter → esm/CamOverlayPainter}/Frame.js +0 -0
  141. /package/{CamScripterAPI.js → esm/CamScripterAPI.js} +0 -0
  142. /package/{CamStreamerAPI.js → esm/CamStreamerAPI.js} +0 -0
  143. /package/{CreatePackage.js → esm/CreatePackage.js} +0 -0
  144. /package/{errors → esm/errors}/errors.js +0 -0
  145. /package/{events → esm/events}/AxisCameraStationEvents.js +0 -0
  146. /package/{events → esm/events}/GenetecAgent.js +0 -0
  147. /package/{internal → esm/internal}/ProxyClient.js +0 -0
  148. /package/{internal → esm/internal}/constants.js +0 -0
  149. /package/{internal → esm/internal}/transformers.js +0 -0
  150. /package/{internal → esm/internal}/utils.js +0 -0
  151. /package/{internal → esm/internal}/versionCompare.js +0 -0
  152. /package/{node → esm/node}/HttpRequestSender.js +0 -0
  153. /package/{node → esm/node}/WsClient.js +0 -0
  154. /package/{node → esm/node}/WsEventClient.js +0 -0
  155. /package/{types → esm/types}/CamOverlayAPI.js +0 -0
  156. /package/{types → esm/types}/CamScripterAPI.js +0 -0
  157. /package/{types → esm/types}/CamStreamerAPI.js +0 -0
  158. /package/{types → esm/types}/CamSwitcherAPI.js +0 -0
  159. /package/{types/CamswitcherEvents.js → esm/types/CamSwitcherEvents.js} +0 -0
  160. /package/{types → esm/types}/common.js +0 -0
  161. /package/{web → esm/web}/DefaultClient.js +0 -0
  162. /package/{web → esm/web}/WsClient.js +0 -0
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultClient = void 0;
4
+ const utils_1 = require("../internal/utils");
5
+ const HttpRequestSender_1 = require("./HttpRequestSender");
6
+ class DefaultClient {
7
+ tls;
8
+ ip;
9
+ port;
10
+ user;
11
+ pass;
12
+ httpRequestSender;
13
+ constructor(opt = {}) {
14
+ this.tls = opt.tls ?? false;
15
+ this.ip = opt.ip ?? '127.0.0.1';
16
+ this.port = opt.port ?? (this.tls ? 443 : 80);
17
+ this.user = opt.user ?? '';
18
+ this.pass = opt.pass ?? '';
19
+ let agentOptions;
20
+ if (opt.tlsInsecure !== undefined || opt.keepAlive !== undefined) {
21
+ agentOptions = {
22
+ rejectUnaurhorized: !opt.tlsInsecure,
23
+ keepAlive: opt.keepAlive,
24
+ };
25
+ }
26
+ this.httpRequestSender = new HttpRequestSender_1.HttpRequestSender(agentOptions);
27
+ }
28
+ get url() {
29
+ return `${this.tls ? 'https' : 'http'}://${this.user}:${this.pass}@${this.ip}:${this.port}`;
30
+ }
31
+ async get(path, parameters = {}, headers) {
32
+ const options = this.getBaseConnectionParams('GET', path, parameters);
33
+ options.headers = headers;
34
+ return this.httpRequestSender.sendRequest(options);
35
+ }
36
+ async post(path, data, parameters = {}, headers) {
37
+ const options = this.getBaseConnectionParams('POST', path, parameters);
38
+ options.headers = headers;
39
+ return this.httpRequestSender.sendRequest(options, data);
40
+ }
41
+ getBaseConnectionParams(method, path, params) {
42
+ const pathName = (0, utils_1.addParametersToPath)(path, params);
43
+ return {
44
+ method: method,
45
+ protocol: this.tls ? 'https:' : 'http:',
46
+ host: this.ip,
47
+ port: this.port,
48
+ path: pathName,
49
+ user: this.user,
50
+ pass: this.pass,
51
+ };
52
+ }
53
+ }
54
+ exports.DefaultClient = DefaultClient;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpRequestSender = void 0;
4
+ const Digest_1 = require("../internal/Digest");
5
+ const undici_1 = require("undici");
6
+ class HttpRequestSender {
7
+ agent;
8
+ authData;
9
+ constructor(agentOptions) {
10
+ this.agent = new undici_1.Agent({
11
+ connect: { rejectUnauthorized: agentOptions?.rejectUnaurhorized, keepAlive: agentOptions?.keepAlive },
12
+ });
13
+ }
14
+ sendRequest(options, postData) {
15
+ return this.sendRequestWithAuth(options, postData);
16
+ }
17
+ async sendRequestWithAuth(options, postData, wwwAuthenticateHeader) {
18
+ options.timeout ??= 10000;
19
+ const url = HttpRequestSender.getURL(options);
20
+ const authorization = this.getAuthorization(options, wwwAuthenticateHeader);
21
+ if (authorization !== undefined) {
22
+ options.headers ??= {};
23
+ options.headers['Authorization'] = authorization;
24
+ }
25
+ const req = new undici_1.Request(url, { body: postData, method: options.method, headers: options.headers });
26
+ const res = await (0, undici_1.fetch)(req, { signal: AbortSignal.timeout(options.timeout), dispatcher: this.agent });
27
+ if (!res.ok) {
28
+ this.invalidateAuthorization();
29
+ }
30
+ if (res.status === 401) {
31
+ const authenticateHeader = res.headers.get('www-authenticate');
32
+ if (authenticateHeader !== null &&
33
+ authenticateHeader.indexOf('Digest') !== -1 &&
34
+ wwwAuthenticateHeader === undefined) {
35
+ return this.sendRequestWithAuth(options, postData, authenticateHeader);
36
+ }
37
+ else {
38
+ return res;
39
+ }
40
+ }
41
+ else {
42
+ return res;
43
+ }
44
+ }
45
+ static getURL(options) {
46
+ const url = new URL(`${options.protocol}//${options.host}:${options.port}${options.path}`);
47
+ return url.toString();
48
+ }
49
+ getAuthorization(options, wwwAuthenticateHeader) {
50
+ if (options.user === undefined || options.pass === undefined) {
51
+ this.authData = undefined;
52
+ return;
53
+ }
54
+ if (this.authData &&
55
+ (this.authData.host !== options.host ||
56
+ this.authData.port !== options.port ||
57
+ this.authData.user !== options.user ||
58
+ this.authData.pass !== options.pass ||
59
+ (wwwAuthenticateHeader !== undefined && this.authData.wwwAuthenticateHeader !== wwwAuthenticateHeader))) {
60
+ this.authData = undefined;
61
+ }
62
+ if (this.authData === undefined) {
63
+ this.authData = {
64
+ host: options.host,
65
+ port: options.port,
66
+ user: options.user,
67
+ pass: options.pass,
68
+ wwwAuthenticateHeader,
69
+ digest: new Digest_1.Digest(),
70
+ };
71
+ }
72
+ return HttpRequestSender.getAuthHeader(options, this.authData);
73
+ }
74
+ invalidateAuthorization() {
75
+ this.authData = undefined;
76
+ }
77
+ static getAuthHeader(options, authData) {
78
+ if (options.user === undefined || options.pass === undefined) {
79
+ throw new Error('No credentials found');
80
+ }
81
+ if (authData.wwwAuthenticateHeader !== undefined && authData.wwwAuthenticateHeader.indexOf('Digest') !== -1) {
82
+ return authData.digest.getAuthHeader(options.user, options.pass, options.method ?? 'GET', options.path, authData.wwwAuthenticateHeader);
83
+ }
84
+ else {
85
+ return `Basic ${btoa(options.user + ':' + options.pass)}`;
86
+ }
87
+ }
88
+ }
89
+ exports.HttpRequestSender = HttpRequestSender;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpServer = void 0;
4
+ const http = require("http");
5
+ const url = require("url");
6
+ const fs = require("fs");
7
+ const path = require("path");
8
+ const EventEmitter = require("events");
9
+ class HttpServer extends EventEmitter {
10
+ host;
11
+ port;
12
+ registeredPaths;
13
+ server;
14
+ sockets;
15
+ constructor(options) {
16
+ super();
17
+ this.host = options?.host ?? process.env.HTTP_HOST ?? '0.0.0.0';
18
+ this.port = options?.port ?? parseInt(process.env.HTTP_PORT ?? '80');
19
+ this.registeredPaths = new Map();
20
+ this.server = http.createServer((req, res) => {
21
+ this.emit('access', req.method + ' ' + req.url);
22
+ const parsedUrl = url.parse(req.url ?? '');
23
+ parsedUrl.pathname ??= '';
24
+ const requestCallback = this.registeredPaths.get(parsedUrl.pathname);
25
+ if (requestCallback) {
26
+ requestCallback(req, res);
27
+ return;
28
+ }
29
+ let pathname = `./html${parsedUrl.pathname}`;
30
+ const ext = path.parse(pathname).ext;
31
+ const map = {
32
+ '.ico': 'image/x-icon',
33
+ '.html': 'text/html',
34
+ '.js': 'text/javascript',
35
+ '.json': 'application/json',
36
+ '.css': 'text/css',
37
+ '.png': 'image/png',
38
+ '.jpg': 'image/jpeg',
39
+ '.wav': 'audio/wav',
40
+ '.mp3': 'audio/mpeg',
41
+ '.svg': 'image/svg+xml',
42
+ '.pdf': 'application/pdf',
43
+ '.doc': 'application/msword',
44
+ };
45
+ fs.access(pathname, fs.constants.R_OK, (err) => {
46
+ if (err) {
47
+ res.statusCode = 404;
48
+ res.end(`File ${pathname} not found!`);
49
+ this.emit('error', `File ${pathname} not found!`);
50
+ return;
51
+ }
52
+ if (fs.statSync(pathname).isDirectory()) {
53
+ pathname += `/index${ext}`;
54
+ }
55
+ fs.readFile(pathname, (error, data) => {
56
+ if (error) {
57
+ res.statusCode = 500;
58
+ res.end(`Error getting the file: ${error}`);
59
+ this.emit('error', `Error getting the file: ${error}`);
60
+ }
61
+ else {
62
+ res.setHeader('Content-type', map[ext] ?? 'text/plain');
63
+ res.setHeader('Access-Control-Allow-Origin', '*');
64
+ res.end(data);
65
+ }
66
+ });
67
+ });
68
+ });
69
+ this.server.on('error', (err) => {
70
+ this.emit('error', err);
71
+ });
72
+ this.server.listen(this.port, this.host);
73
+ this.sockets = {};
74
+ let idTracker = 0;
75
+ this.server.on('connection', (socket) => {
76
+ const socketID = idTracker++;
77
+ this.sockets[socketID] = socket;
78
+ socket.on('close', () => {
79
+ delete this.sockets[socketID];
80
+ });
81
+ });
82
+ }
83
+ getServer() {
84
+ return this.server;
85
+ }
86
+ onRequest(pathName, callback) {
87
+ this.registeredPaths.set(pathName, callback);
88
+ }
89
+ close() {
90
+ this.server.close();
91
+ for (const key in this.sockets) {
92
+ this.sockets[key]?.destroy();
93
+ }
94
+ }
95
+ }
96
+ exports.HttpServer = HttpServer;
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WsClient = void 0;
4
+ const EventEmitter = require("events");
5
+ const WebSocket = require("ws");
6
+ const Digest_1 = require("../internal/Digest");
7
+ class WsClient extends EventEmitter {
8
+ user;
9
+ pass;
10
+ address;
11
+ protocol;
12
+ pingInterval;
13
+ wsOptions;
14
+ digestAddress;
15
+ isAlive = true;
16
+ pingTimer;
17
+ ws;
18
+ isClosed = false;
19
+ constructor(options) {
20
+ super();
21
+ const tls = options.tls ?? false;
22
+ const tlsInsecure = options.tlsInsecure ?? false;
23
+ const ip = options.ip ?? '127.0.0.1';
24
+ const port = options.port ?? (tls ? 443 : 80);
25
+ this.user = options.user ?? '';
26
+ this.pass = options.pass ?? '';
27
+ const protocol = tls ? 'wss' : 'ws';
28
+ this.address = `${protocol}://${ip}:${port}${options.address}`;
29
+ this.digestAddress = options.address;
30
+ this.pingInterval = options.pingInterval ?? 30000;
31
+ this.protocol = options.protocol;
32
+ this.wsOptions = {
33
+ auth: `${this.user}:${this.pass}`,
34
+ rejectUnauthorized: !tlsInsecure,
35
+ headers: options.headers ?? {},
36
+ };
37
+ }
38
+ open(wwwAuthenticateHeader) {
39
+ try {
40
+ if (this.ws !== undefined) {
41
+ return;
42
+ }
43
+ this.isClosed = false;
44
+ if (this.protocol === undefined) {
45
+ this.ws = new WebSocket(this.address, this.wsOptions);
46
+ }
47
+ else {
48
+ this.ws = new WebSocket(this.address, this.protocol, this.wsOptions);
49
+ }
50
+ this.ws.binaryType = 'arraybuffer';
51
+ this.isAlive = true;
52
+ this.pingTimer = setInterval(async () => {
53
+ if ((this.ws && this.ws.readyState !== WebSocket.OPEN) || this.isAlive === false) {
54
+ this.emit('error', new Error('Connection timeout'));
55
+ await this.closeWsConnection();
56
+ }
57
+ else {
58
+ this.isAlive = false;
59
+ this.ws?.ping();
60
+ }
61
+ }, this.pingInterval);
62
+ this.ws.on('pong', () => {
63
+ this.isAlive = true;
64
+ });
65
+ if (wwwAuthenticateHeader !== undefined) {
66
+ this.wsOptions.headers['Authorization'] = new Digest_1.Digest().getAuthHeader(this.user, this.pass, 'GET', this.digestAddress, wwwAuthenticateHeader);
67
+ }
68
+ this.ws.on('unexpected-response', (req, res) => {
69
+ if (res.statusCode === 401 && res.headers['www-authenticate'] !== undefined) {
70
+ if (this.pingTimer) {
71
+ clearInterval(this.pingTimer);
72
+ }
73
+ this.ws?.removeAllListeners();
74
+ this.ws = undefined;
75
+ this.open(res.headers['www-authenticate']);
76
+ }
77
+ else {
78
+ this.emit('error', new Error('Status code: ' + res.statusCode));
79
+ this.closeWsConnection();
80
+ }
81
+ });
82
+ this.ws.on('open', () => this.emit('open'));
83
+ this.ws.on('message', (data) => this.emit('message', data));
84
+ this.ws.on('error', (error) => {
85
+ this.emit('error', error);
86
+ this.closeWsConnection();
87
+ });
88
+ this.ws.on('close', () => this.closeWsConnection());
89
+ }
90
+ catch (error) {
91
+ this.emit('error', error instanceof Error ? error : new Error('Unknown error'));
92
+ this.closeWsConnection();
93
+ }
94
+ }
95
+ send(data) {
96
+ if (this.ws === undefined) {
97
+ throw new Error("This websocket hasn't been opened yet.");
98
+ }
99
+ if (this.ws.readyState === this.ws.OPEN) {
100
+ this.ws.send(data);
101
+ }
102
+ }
103
+ close() {
104
+ if (this.isClosed) {
105
+ return;
106
+ }
107
+ this.isClosed = true;
108
+ this.closeWsConnection();
109
+ }
110
+ reconnect() {
111
+ this.closeWsConnection();
112
+ }
113
+ closeWsConnection() {
114
+ if (this.ws === undefined) {
115
+ return;
116
+ }
117
+ const wsCopy = this.ws;
118
+ this.ws = undefined;
119
+ try {
120
+ if (this.pingTimer) {
121
+ clearInterval(this.pingTimer);
122
+ }
123
+ wsCopy.removeAllListeners();
124
+ wsCopy.on('error', () => { });
125
+ if (wsCopy.readyState !== WebSocket.CLOSING && wsCopy.readyState !== WebSocket.CLOSED) {
126
+ wsCopy.close();
127
+ }
128
+ setTimeout(() => {
129
+ if (wsCopy.readyState !== WebSocket.CLOSED) {
130
+ wsCopy.terminate();
131
+ }
132
+ }, 5000);
133
+ this.emit('close');
134
+ }
135
+ catch (err) {
136
+ console.error(err);
137
+ }
138
+ finally {
139
+ const shouldRestart = !this.isClosed;
140
+ setTimeout(() => {
141
+ wsCopy.removeAllListeners();
142
+ if (shouldRestart && !this.isClosed) {
143
+ this.open();
144
+ }
145
+ }, 10000);
146
+ }
147
+ }
148
+ }
149
+ exports.WsClient = WsClient;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WsEventClient = void 0;
4
+ const WsClient_1 = require("./WsClient");
5
+ class WsEventClient {
6
+ wsClient;
7
+ constructor(options) {
8
+ this.wsClient = new WsClient_1.WsClient(options);
9
+ this.wsClient.on('message', (data) => {
10
+ this.onmessage?.({ data: data.toString() });
11
+ });
12
+ }
13
+ send = (data) => {
14
+ this.wsClient.send(data);
15
+ };
16
+ destroy = () => {
17
+ this.wsClient.close();
18
+ this.onmessage = null;
19
+ };
20
+ onmessage = null;
21
+ }
22
+ exports.WsEventClient = WsEventClient;
@@ -0,0 +1,2 @@
1
+ export { DefaultClient } from './DefaultClient';
2
+ export { WsClient } from './WsClient';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WsClient = exports.DefaultClient = void 0;
4
+ var DefaultClient_1 = require("./DefaultClient");
5
+ Object.defineProperty(exports, "DefaultClient", { enumerable: true, get: function () { return DefaultClient_1.DefaultClient; } });
6
+ var WsClient_1 = require("./WsClient");
7
+ Object.defineProperty(exports, "WsClient", { enumerable: true, get: function () { return WsClient_1.WsClient; } });
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.storageSchema = exports.imageStorageSchema = exports.fontStorageSchema = exports.ImageType = exports.fileListSchema = exports.fileSchema = exports.fieldSchema = exports.serviceSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.serviceSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.any());
6
+ exports.fieldSchema = zod_1.z.object({
7
+ field_name: zod_1.z.string(),
8
+ text: zod_1.z.string(),
9
+ color: zod_1.z.string().optional(),
10
+ });
11
+ exports.fileSchema = zod_1.z.object({
12
+ name: zod_1.z.string(),
13
+ path: zod_1.z.string(),
14
+ storage: zod_1.z.string(),
15
+ });
16
+ exports.fileListSchema = zod_1.z.array(exports.fileSchema);
17
+ var ImageType;
18
+ (function (ImageType) {
19
+ ImageType[ImageType["PNG"] = 0] = "PNG";
20
+ ImageType[ImageType["JPEG"] = 1] = "JPEG";
21
+ })(ImageType || (exports.ImageType = ImageType = {}));
22
+ exports.fontStorageSchema = zod_1.z.tuple([
23
+ zod_1.z.object({
24
+ type: zod_1.z.literal('SD0'),
25
+ state: zod_1.z.literal('SD Card'),
26
+ }),
27
+ zod_1.z.object({
28
+ type: zod_1.z.literal('flash'),
29
+ state: zod_1.z.string(),
30
+ }),
31
+ ]);
32
+ exports.imageStorageSchema = zod_1.z.tuple([
33
+ ...exports.fontStorageSchema.items,
34
+ zod_1.z.object({
35
+ type: zod_1.z.literal('samba'),
36
+ state: zod_1.z.literal('Microsoft Network Share'),
37
+ }),
38
+ zod_1.z.object({
39
+ type: zod_1.z.literal('url'),
40
+ state: zod_1.z.literal('URL'),
41
+ }),
42
+ zod_1.z.object({
43
+ type: zod_1.z.literal('ftp'),
44
+ state: zod_1.z.literal('FTP'),
45
+ }),
46
+ ]);
47
+ exports.storageSchema = zod_1.z.union([exports.fontStorageSchema, exports.imageStorageSchema]);
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.storageSchema = exports.packageInfoListSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.packageInfoListSchema = zod_1.z.array(zod_1.z.object({
6
+ storage: zod_1.z.union([zod_1.z.literal('SD_CARD'), zod_1.z.literal('INTERNAL')]),
7
+ manifest: zod_1.z.object({
8
+ package_name: zod_1.z.string(),
9
+ package_menu_name: zod_1.z.string(),
10
+ package_version: zod_1.z.string(),
11
+ vendor: zod_1.z.string(),
12
+ required_camscripter_version: zod_1.z.string(),
13
+ required_camscripter_rbi_version: zod_1.z.string(),
14
+ ui_link: zod_1.z.string(),
15
+ }),
16
+ }));
17
+ exports.storageSchema = zod_1.z.array(zod_1.z.object({
18
+ type: zod_1.z.union([zod_1.z.literal('INTERNAL'), zod_1.z.literal('SD_CARD')]),
19
+ capacity_mb: zod_1.z.number(),
20
+ }));
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.streamListSchema = exports.streamAttributesSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.streamAttributesSchema = zod_1.z.object({
6
+ enabled: zod_1.z.string(),
7
+ active: zod_1.z.string(),
8
+ audioSource: zod_1.z.string(),
9
+ avSyncMsec: zod_1.z.string(),
10
+ internalVapixParameters: zod_1.z.string(),
11
+ userVapixParameters: zod_1.z.string(),
12
+ outputParameters: zod_1.z.string(),
13
+ outputType: zod_1.z.string(),
14
+ mediaServerUrl: zod_1.z.string(),
15
+ inputType: zod_1.z.string(),
16
+ inputUrl: zod_1.z.string(),
17
+ forceStereo: zod_1.z.string(),
18
+ streamDelay: zod_1.z.string(),
19
+ statusLed: zod_1.z.string(),
20
+ statusPort: zod_1.z.string(),
21
+ callApi: zod_1.z.string(),
22
+ trigger: zod_1.z.string(),
23
+ schedule: zod_1.z.string(),
24
+ prepareAhead: zod_1.z.string(),
25
+ startTime: zod_1.z.string(),
26
+ stopTime: zod_1.z.string(),
27
+ });
28
+ exports.streamListSchema = zod_1.z.record(zod_1.z.string(), exports.streamAttributesSchema);
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clipListSchema = exports.playlistQueueSchema = exports.trackerSaveLoadSchema = exports.trackerSaveSchema = exports.playlistSaveLoadSchema = exports.clipSaveLoadSchema = exports.clipSaveSchema = exports.streamSaveLoadSchema = exports.audioPushInfoSchema = exports.outputInfoSchema = exports.storageInfoListSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const transformers_1 = require("../internal/transformers");
6
+ const common_1 = require("./common");
7
+ const channelTypeSchema = zod_1.z.union([zod_1.z.literal('audio'), zod_1.z.literal('video'), zod_1.z.literal('av')]);
8
+ const playlistPlayTypeSchema = zod_1.z.union([
9
+ zod_1.z.literal('PLAY_ALL'),
10
+ zod_1.z.literal('PLAY_ALL_LOOP'),
11
+ zod_1.z.literal('PLAY_ALL_SHUFFLED'),
12
+ zod_1.z.literal('PLAY_ALL_LOOP_SHUFFLED'),
13
+ zod_1.z.literal('PLAY_ONE_RANDOM'),
14
+ ]);
15
+ exports.storageInfoListSchema = zod_1.z.array(zod_1.z.object({
16
+ storage: common_1.storageTypeSchema,
17
+ writable: zod_1.z.boolean(),
18
+ size: zod_1.z.number(),
19
+ available: zod_1.z.number(),
20
+ }));
21
+ exports.outputInfoSchema = zod_1.z
22
+ .object({
23
+ rtsp_url: zod_1.z.string(),
24
+ ws: zod_1.z.string(),
25
+ ws_initial_message: zod_1.z.string(),
26
+ })
27
+ .transform(transformers_1.toCamelCase);
28
+ exports.audioPushInfoSchema = zod_1.z
29
+ .object({
30
+ ws: zod_1.z.string(),
31
+ ws_initial_message: zod_1.z.string(),
32
+ })
33
+ .transform(transformers_1.toCamelCase);
34
+ const streamSaveSchema = zod_1.z.object({
35
+ niceName: zod_1.z.string(),
36
+ ip: zod_1.z.string(),
37
+ mdnsName: zod_1.z.string(),
38
+ port: zod_1.z.number(),
39
+ enabled: zod_1.z.boolean(),
40
+ auth: zod_1.z.string(),
41
+ query: zod_1.z.string(),
42
+ channel: channelTypeSchema,
43
+ keyboard: common_1.keyboardShortcutsSchema,
44
+ sortIndexOverview: zod_1.z.number().optional(),
45
+ viewNumber: zod_1.z.number(),
46
+ });
47
+ exports.streamSaveLoadSchema = zod_1.z.record(zod_1.z.string(), streamSaveSchema.partial());
48
+ exports.clipSaveSchema = zod_1.z.object({
49
+ niceName: zod_1.z.string(),
50
+ channel: channelTypeSchema,
51
+ keyboard: common_1.keyboardShortcutsSchema,
52
+ sortIndexOverview: zod_1.z.number(),
53
+ });
54
+ exports.clipSaveLoadSchema = zod_1.z.record(zod_1.z.string(), exports.clipSaveSchema.partial());
55
+ const playlistStreamSaveSchema = zod_1.z
56
+ .object({
57
+ stream_name: zod_1.z.string(),
58
+ clip_name: zod_1.z.string(),
59
+ tracker_name: zod_1.z.string(),
60
+ storage: common_1.storageTypeSchema,
61
+ })
62
+ .partial();
63
+ const playlistSaveSchema = zod_1.z.object({
64
+ channel: channelTypeSchema,
65
+ isFavourite: zod_1.z.boolean(),
66
+ keyboard: common_1.keyboardShortcutsSchema,
67
+ niceName: zod_1.z.string(),
68
+ sortIndexFavourite: zod_1.z.number().optional(),
69
+ sortIndexOverview: zod_1.z.number().optional(),
70
+ play_type: playlistPlayTypeSchema,
71
+ default: zod_1.z.boolean().optional(),
72
+ stream_list: zod_1.z.array(zod_1.z.object({
73
+ id: zod_1.z.string(),
74
+ isTimeoutCustom: zod_1.z.boolean(),
75
+ ptz_preset_pos_name: zod_1.z.string(),
76
+ repeat: zod_1.z.number(),
77
+ timeout: zod_1.z.number(),
78
+ video: playlistStreamSaveSchema,
79
+ audio: playlistStreamSaveSchema.optional(),
80
+ })),
81
+ });
82
+ exports.playlistSaveLoadSchema = zod_1.z.record(zod_1.z.string(), playlistSaveSchema.partial());
83
+ exports.trackerSaveSchema = zod_1.z.object({
84
+ id: zod_1.z.string(),
85
+ name: zod_1.z.string(),
86
+ previewId: zod_1.z.string(),
87
+ duration: zod_1.z.number(),
88
+ keyboard: common_1.keyboardShortcutsSchema,
89
+ channel: channelTypeSchema,
90
+ sortIndexOverview: zod_1.z.number(),
91
+ width: zod_1.z.number(),
92
+ height: zod_1.z.number(),
93
+ fps: zod_1.z.number(),
94
+ motion_history_frames: zod_1.z.number(),
95
+ include_zone: zod_1.z.array(zod_1.z.array(zod_1.z.number()).length(2)),
96
+ include_node_ids: zod_1.z.array(zod_1.z.string()),
97
+ camera_list: zod_1.z.array(zod_1.z.object({
98
+ id: zod_1.z.string(),
99
+ name: zod_1.z.string(),
100
+ overview: zod_1.z.boolean(),
101
+ zone: zod_1.z.array(zod_1.z.number()).length(4),
102
+ playlist_name: zod_1.z.string(),
103
+ ptz_preset_pos_no: zod_1.z.number(),
104
+ })),
105
+ viewNumber: zod_1.z.number(),
106
+ camera_view_number: zod_1.z.number(),
107
+ });
108
+ exports.trackerSaveLoadSchema = zod_1.z.record(zod_1.z.string(), exports.trackerSaveSchema.partial());
109
+ exports.playlistQueueSchema = zod_1.z
110
+ .object({
111
+ playlist_queue_list: zod_1.z.array(zod_1.z.string()),
112
+ })
113
+ .transform(transformers_1.toCamelCaseDeep);
114
+ exports.clipListSchema = zod_1.z.object({
115
+ clip_list: zod_1.z.record(zod_1.z.string(), zod_1.z.object({
116
+ storage: common_1.storageTypeSchema,
117
+ duration: zod_1.z.number(),
118
+ stream_list: zod_1.z.array(zod_1.z.union([
119
+ zod_1.z.object({
120
+ type: zod_1.z.literal('video'),
121
+ width: zod_1.z.number(),
122
+ height: zod_1.z.number(),
123
+ sample_rate: zod_1.z.number(),
124
+ h264_profile: common_1.h264ProfileSchema,
125
+ h264_level: zod_1.z.literal('4.1'),
126
+ gop: zod_1.z.number(),
127
+ fps: zod_1.z.number(),
128
+ bitrate: zod_1.z.number(),
129
+ }),
130
+ zod_1.z.object({
131
+ type: zod_1.z.literal('audio'),
132
+ sample_rate: zod_1.z.number(),
133
+ channel_count: common_1.audioChannelCountSchema,
134
+ }),
135
+ ])),
136
+ })),
137
+ });