@aloma.io/integration-sdk 3.3.64 → 3.3.65

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.
@@ -16,7 +16,7 @@ export default class RuntimeContext {
16
16
  let icon;
17
17
  try {
18
18
  if (data.icon) {
19
- icon = fs.readFileSync(data.icon).toString('base64');
19
+ icon = fs.readFileSync(data.icon).toString("base64");
20
20
  }
21
21
  }
22
22
  catch (e) {
@@ -26,7 +26,7 @@ export default class RuntimeContext {
26
26
  id: data.id,
27
27
  version: data.version,
28
28
  name: `${data.id}/${data.version}`,
29
- icon
29
+ icon,
30
30
  });
31
31
  const configuration = connector.configure().config(data.config || {});
32
32
  const resolvers = {};
@@ -29,11 +29,10 @@ const transform = (meta) => {
29
29
  let eg;
30
30
  if (example) {
31
31
  const parts = example.split(/```/);
32
- const backticks = '```';
33
- eg = `@example ${parts[0] || 'usage'}\n${backticks}${parts[1]}${backticks}`;
32
+ const backticks = "```";
33
+ eg = `@example ${parts[0] || "usage"}\n${backticks}${parts[1]}${backticks}`;
34
34
  }
35
- const paramDocs = docs
36
- .filter((what) => what.kind === "param");
35
+ const paramDocs = docs.filter((what) => what.kind === "param");
37
36
  const params = sig
38
37
  .getParameters()
39
38
  .filter((param) => param.isNamed())
@@ -46,12 +45,10 @@ const transform = (meta) => {
46
45
  return `${p.getName()}${defaultVal}`;
47
46
  })
48
47
  .join("; ");
49
- const suffix = serialized
50
- .type
51
- .properties
48
+ const suffix = serialized.type.properties
52
49
  .map((p) => {
53
50
  const comment = paramDocs.find((what) => what.value.name === p.name);
54
- const desc = (comment?.value.description || '').replace(/\\@/gi, '@');
51
+ const desc = (comment?.value.description || "").replace(/\\@/gi, "@");
55
52
  return `\n/**\n${desc}\n */\n ${p.name}: ${p.type.text}`;
56
53
  })
57
54
  .join("; ");
@@ -66,7 +63,7 @@ const transform = (meta) => {
66
63
  /**
67
64
  * ${desc || ""}
68
65
  *
69
- * ${eg || ''}
66
+ * ${eg || ""}
70
67
  **/
71
68
  declare function ${member.getName()}(${params}): ${retVal};
72
69
  `;
@@ -79,6 +76,6 @@ declare function ${member.getName()}(${params}): ${retVal};
79
76
  export default async (path) => {
80
77
  const parsed = await parseFromFiles([path]);
81
78
  if (parsed.errors?.length)
82
- throw new Error(path + ' ' + JSON.stringify(parsed.errors));
79
+ throw new Error(path + " " + JSON.stringify(parsed.errors));
83
80
  return transform(parsed.project?.getModules() || []);
84
81
  };
@@ -7,7 +7,7 @@ export declare abstract class AbstractController {
7
7
  protected fallback(arg: any): Promise<any>;
8
8
  protected endpoint(arg: any): Promise<any>;
9
9
  protected newTask(name: string, data: any): Promise<string>;
10
- protected getClient({ baseUrl, onResponse }: {
10
+ protected getClient({ baseUrl, onResponse, }: {
11
11
  baseUrl: string;
12
12
  onResponse?: (response: any) => void;
13
13
  }): Promise<any>;
@@ -15,7 +15,7 @@ export class AbstractController {
15
15
  async newTask(name, data) {
16
16
  throw new Error("not implemented");
17
17
  }
18
- getClient({ baseUrl, onResponse }) {
18
+ getClient({ baseUrl, onResponse, }) {
19
19
  throw new Error("not implemented");
20
20
  }
21
21
  async updateTask(name, data) {
@@ -44,7 +44,7 @@ class Dispatcher {
44
44
  placeholder: "e.g. 1234",
45
45
  type: "line",
46
46
  optional: !!arg.configurableClientOptional,
47
- plain: true
47
+ plain: true,
48
48
  },
49
49
  clientSecret: {
50
50
  name: "OAuth Client Secret",
@@ -67,8 +67,8 @@ class Dispatcher {
67
67
  ${arg.configurableClientScope}
68
68
  `,
69
69
  optional: true,
70
- plain: true
71
- }
70
+ plain: true,
71
+ },
72
72
  },
73
73
  });
74
74
  }
@@ -38,7 +38,7 @@ const unwrap = async (ret, options) => {
38
38
  return JSON.parse(text);
39
39
  }
40
40
  catch (e) {
41
- throw (e + ' ' + text);
41
+ throw e + " " + text;
42
42
  }
43
43
  };
44
44
  class Fetcher {
@@ -192,7 +192,7 @@ class OAuth {
192
192
  }
193
193
  async periodicRefresh() {
194
194
  const clients = this.clients;
195
- console.log('refreshing oauth clients', clients.length);
195
+ console.log("refreshing oauth clients", clients.length);
196
196
  for (let i = 0; i < clients.length; ++i) {
197
197
  const client = clients[0];
198
198
  await client.periodicRefresh();
@@ -251,7 +251,7 @@ class Connector {
251
251
  publicKey: process.env.PUBLIC_KEY,
252
252
  introspect,
253
253
  configSchema,
254
- icon: this.icon
254
+ icon: this.icon,
255
255
  });
256
256
  if (Object.keys(configSchema().fields).length) {
257
257
  try {
@@ -293,7 +293,7 @@ ${text}
293
293
  const value = secrets[key];
294
294
  if (!value)
295
295
  continue;
296
- if (fields[key]?.plain || ['endpointUrl'].includes(key)) {
296
+ if (fields[key]?.plain || ["endpointUrl"].includes(key)) {
297
297
  decrypted[key] = value;
298
298
  }
299
299
  else {
@@ -338,7 +338,6 @@ ${text}
338
338
  const clientId = process.env.OAUTH_CLIENT_ID ||
339
339
  decrypted.clientId ||
340
340
  that._oauth.clientId;
341
- ;
342
341
  if (!clientId)
343
342
  throw new Error("clientId not configured");
344
343
  const clientSecret = process.env.OAUTH_CLIENT_SECRET ||
@@ -473,7 +472,7 @@ ${text}
473
472
  await theOAuth.periodicRefresh();
474
473
  }
475
474
  catch (e) {
476
- console.log('periodic refresh', e);
475
+ console.log("periodic refresh", e);
477
476
  }
478
477
  }, 4 * 60 * 60 * 15000);
479
478
  }
@@ -1,5 +1,5 @@
1
1
  export class Config {
2
- constructor({ registrationToken, version, name, id, endpoint, wsEndpoint, privateKey, publicKey, introspect, configSchema, icon }: {
2
+ constructor({ registrationToken, version, name, id, endpoint, wsEndpoint, privateKey, publicKey, introspect, configSchema, icon, }: {
3
3
  registrationToken: any;
4
4
  version: any;
5
5
  name: any;
@@ -1,7 +1,7 @@
1
1
  import C from "./connection/constants.mjs";
2
2
  import JWE from "../util/jwe/index.mjs";
3
3
  class Config {
4
- constructor({ registrationToken, version, name, id, endpoint, wsEndpoint, privateKey, publicKey, introspect, configSchema, icon }) {
4
+ constructor({ registrationToken, version, name, id, endpoint, wsEndpoint, privateKey, publicKey, introspect, configSchema, icon, }) {
5
5
  this._token = null;
6
6
  this._registrationToken = registrationToken;
7
7
  this._version = version;
@@ -19,7 +19,7 @@ class Registration {
19
19
  id: config.id(),
20
20
  publicKey: config.publicKey(),
21
21
  schema: { configSchema, introspect: intro },
22
- icon
22
+ icon,
23
23
  }),
24
24
  headers: { "Content-Type": "application/json" },
25
25
  }, config));
@@ -47,15 +47,25 @@ class Transport {
47
47
  local.close();
48
48
  this.running = true;
49
49
  const ws = (local.ws = new WebSocket(config.wsUrl(), ["connector"], C.augmentRequest({ headers: {} }, config)));
50
+ ws.onPing = function () {
51
+ clearTimeout(this.pingTimeout);
52
+ this.pingTimeout = setTimeout(() => {
53
+ console.log("terminating ws");
54
+ if (local.running)
55
+ this.terminate();
56
+ }, 30000 + 15000);
57
+ };
50
58
  ws.on("open", () => {
51
59
  console.log("websocket connected");
52
60
  local.connected = true;
61
+ ws.onPing();
53
62
  local.pinger = setInterval(() => ws.ping(() => null), pingInterval);
54
63
  local.onConnect(local);
55
64
  });
56
65
  ws.on("message", (message) => {
57
66
  setTimeout(() => local.onMessages(JSON.parse(message)), 0);
58
67
  });
68
+ ws.on("ping", () => ws.onPing());
59
69
  ws.on("error", (message) => {
60
70
  console.log("error:", message);
61
71
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aloma.io/integration-sdk",
3
- "version": "3.3.64",
3
+ "version": "3.3.65",
4
4
  "description": "",
5
5
  "author": "aloma.io",
6
6
  "license": "Apache-2.0",
@@ -38,7 +38,7 @@ export class Builder {
38
38
  await this.parsePackageJson();
39
39
  await this.discoverTypes();
40
40
  await this.checkIcon();
41
-
41
+
42
42
  // @ts-ignore
43
43
  const Controller = (
44
44
  await import(__dirname + "/../../../../../build/controller/index.mjs")
@@ -46,11 +46,11 @@ export class Builder {
46
46
 
47
47
  return new RuntimeContext(new Controller(), this.data);
48
48
  }
49
-
49
+
50
50
  private async checkIcon() {
51
51
  const data = this.data;
52
- const root = __dirname + "/../../../../../"
53
-
52
+ const root = __dirname + "/../../../../../";
53
+
54
54
  data.icon = `${root}/logo.png`;
55
55
  }
56
56
 
@@ -1,7 +1,7 @@
1
1
  import { AbstractController } from "../controller/index.mjs";
2
2
  import { Connector } from "../internal/index.mjs";
3
3
  import fs from "node:fs";
4
-
4
+
5
5
  export default class RuntimeContext {
6
6
  constructor(
7
7
  private controller: AbstractController,
@@ -14,25 +14,22 @@ export default class RuntimeContext {
14
14
  if (!(controller instanceof AbstractController))
15
15
  throw new Error("the controller needs to extend AbstractController");
16
16
  const data: any = this.data;
17
-
17
+
18
18
  let icon;
19
-
20
- try
21
- {
22
- if (data.icon)
23
- {
24
- icon = fs.readFileSync(data.icon).toString('base64');
19
+
20
+ try {
21
+ if (data.icon) {
22
+ icon = fs.readFileSync(data.icon).toString("base64");
25
23
  }
26
- } catch(e) {
24
+ } catch (e) {
27
25
  // blank
28
26
  }
29
-
30
27
 
31
28
  const connector = new Connector({
32
29
  id: data.id,
33
30
  version: data.version,
34
31
  name: `${data.id}/${data.version}`,
35
- icon
32
+ icon,
36
33
  });
37
34
 
38
35
  const configuration = connector.configure().config(data.config || {});
@@ -56,7 +53,10 @@ export default class RuntimeContext {
56
53
  configuration.types(data.types).resolvers(resolvers);
57
54
 
58
55
  if (data.options?.endpoint?.enabled) {
59
- configuration.endpoint((arg) => controller.__endpoint(arg), data.options?.endpoint?.required);
56
+ configuration.endpoint(
57
+ (arg) => controller.__endpoint(arg),
58
+ data.options?.endpoint?.required,
59
+ );
60
60
  }
61
61
 
62
62
  if (data.auth?.oauth) {
@@ -81,7 +81,7 @@ export default class RuntimeContext {
81
81
  );
82
82
 
83
83
  connector.run();
84
-
84
+
85
85
  const term = async () => {
86
86
  await controller._doStop(true);
87
87
 
@@ -31,21 +31,20 @@ const transform = (meta: any) => {
31
31
  const docs = sig.getJSDoc().serialize() || [];
32
32
  const desc = docs.find((what: any) => what.kind === "description")
33
33
  ?.value;
34
-
34
+
35
35
  const example = docs.find((what: any) => what.kind === "example")
36
36
  ?.value;
37
37
 
38
38
  let eg;
39
- if (example)
40
- {
39
+ if (example) {
41
40
  const parts = example.split(/```/);
42
- const backticks = '```';
43
- eg = `@example ${parts[0] || 'usage'}\n${backticks}${parts[1]}${backticks}`;
41
+ const backticks = "```";
42
+ eg = `@example ${parts[0] || "usage"}\n${backticks}${
43
+ parts[1]
44
+ }${backticks}`;
44
45
  }
45
-
46
- const paramDocs =
47
- docs
48
- .filter((what: any) => what.kind === "param")
46
+
47
+ const paramDocs = docs.filter((what: any) => what.kind === "param");
49
48
 
50
49
  const params = sig
51
50
  .getParameters()
@@ -62,22 +61,25 @@ const transform = (meta: any) => {
62
61
  return `${p.getName()}${defaultVal}`;
63
62
  })
64
63
  .join("; ");
65
-
66
- const suffix = serialized
67
- .type
68
- .properties
64
+
65
+ const suffix = serialized.type.properties
69
66
  .map((p) => {
70
- const comment = paramDocs.find((what) => what.value.name === p.name);
71
- const desc = (comment?.value.description || '').replace(/\\@/gi, '@');
72
-
67
+ const comment = paramDocs.find(
68
+ (what) => what.value.name === p.name,
69
+ );
70
+ const desc = (comment?.value.description || "").replace(
71
+ /\\@/gi,
72
+ "@",
73
+ );
74
+
73
75
  return `\n/**\n${desc}\n */\n ${p.name}: ${p.type.text}`;
74
76
  })
75
77
  .join("; ");
76
-
78
+
77
79
  return `{${prefix}}: {${suffix}}`;
78
80
  })
79
81
  .join(", ");
80
-
82
+
81
83
  const retVal = sig
82
84
  .serialize()
83
85
  .return.type.text.replace(/^Promise</, "")
@@ -87,7 +89,7 @@ const transform = (meta: any) => {
87
89
  /**
88
90
  * ${desc || ""}
89
91
  *
90
- * ${eg || ''}
92
+ * ${eg || ""}
91
93
  **/
92
94
  declare function ${member.getName()}(${params}): ${retVal};
93
95
  `;
@@ -101,6 +103,7 @@ declare function ${member.getName()}(${params}): ${retVal};
101
103
 
102
104
  export default async (path: string) => {
103
105
  const parsed = await parseFromFiles([path]);
104
- if (parsed.errors?.length) throw new Error(path + ' ' + JSON.stringify(parsed.errors));
106
+ if (parsed.errors?.length)
107
+ throw new Error(path + " " + JSON.stringify(parsed.errors));
105
108
  return transform(parsed.project?.getModules() || []);
106
109
  };
@@ -22,7 +22,13 @@ export abstract class AbstractController {
22
22
  throw new Error("not implemented");
23
23
  }
24
24
 
25
- protected getClient({ baseUrl, onResponse }: { baseUrl: string, onResponse?: (response: any) => void }): Promise<any> {
25
+ protected getClient({
26
+ baseUrl,
27
+ onResponse,
28
+ }: {
29
+ baseUrl: string;
30
+ onResponse?: (response: any) => void;
31
+ }): Promise<any> {
26
32
  throw new Error("not implemented");
27
33
  }
28
34
 
@@ -51,7 +51,7 @@ class Dispatcher {
51
51
  placeholder: "e.g. 1234",
52
52
  type: "line",
53
53
  optional: !!arg.configurableClientOptional,
54
- plain: true
54
+ plain: true,
55
55
  },
56
56
  clientSecret: {
57
57
  name: "OAuth Client Secret",
@@ -62,7 +62,7 @@ class Dispatcher {
62
62
  },
63
63
  });
64
64
  }
65
-
65
+
66
66
  if (arg.configurableClientScope) {
67
67
  this.config({
68
68
  fields: {
@@ -75,8 +75,8 @@ class Dispatcher {
75
75
  ${arg.configurableClientScope}
76
76
  `,
77
77
  optional: true,
78
- plain: true
79
- }
78
+ plain: true,
79
+ },
80
80
  },
81
81
  });
82
82
  }
@@ -111,7 +111,7 @@ ${arg.configurableClientScope}
111
111
  _endpointToken: {
112
112
  name: "Endpoint Token",
113
113
  placeholder: "e.g. 1234",
114
- type: !!notOptional?"managed":"line",
114
+ type: !!notOptional ? "managed" : "line",
115
115
  plain: true,
116
116
  optional: !notOptional,
117
117
  },
@@ -40,14 +40,13 @@ const reply = (arg, packet, transport) => {
40
40
  const unwrap = async (ret, options) => {
41
41
  if (options?.text) return await ret.text();
42
42
  if (options?.base64) return (await ret.buffer()).toString("base64");
43
-
43
+
44
44
  const text = await ret.text();
45
-
46
- try
47
- {
45
+
46
+ try {
48
47
  return JSON.parse(text);
49
- } catch(e) {
50
- throw (e + ' ' + text)
48
+ } catch (e) {
49
+ throw e + " " + text;
51
50
  }
52
51
  };
53
52
 
@@ -120,9 +119,8 @@ class Fetcher {
120
119
  e.status = status;
121
120
  throw e;
122
121
  }
123
-
124
- if (local.onResponse)
125
- {
122
+
123
+ if (local.onResponse) {
126
124
  await local.onResponse(ret);
127
125
  }
128
126
 
@@ -130,9 +128,9 @@ class Fetcher {
130
128
  } catch (e) {
131
129
  // too many requests
132
130
  if (e.status === 429) {
133
- return local.onError(e, url, options, retries, args, true);
131
+ return local.onError(e, url, options, retries, args, true);
134
132
  }
135
-
133
+
136
134
  --retries;
137
135
 
138
136
  console.log(theURL, e);
@@ -179,24 +177,28 @@ class OAuthFetcher extends Fetcher {
179
177
  var local = this;
180
178
 
181
179
  return new Promise((resolve, reject) => {
182
- setTimeout(async () => {
183
- try {
184
- resolve(
185
- await local.fetch(url, options, retries, {
186
- forceTokenRefresh: e.status === 401,
187
- }),
188
- );
189
- } catch (e) {
190
- reject(e);
191
- }
192
- }, rateLimit?10000:500);
180
+ setTimeout(
181
+ async () => {
182
+ try {
183
+ resolve(
184
+ await local.fetch(url, options, retries, {
185
+ forceTokenRefresh: e.status === 401,
186
+ }),
187
+ );
188
+ } catch (e) {
189
+ reject(e);
190
+ }
191
+ },
192
+ rateLimit ? 10000 : 500,
193
+ );
193
194
  });
194
195
  }
195
196
 
196
197
  async periodicRefresh() {
197
- const local = this, oauth = local.oauth;
198
+ const local = this,
199
+ oauth = local.oauth;
198
200
  if (!oauth.refreshToken()) return;
199
-
201
+
200
202
  await local.getToken(true);
201
203
  }
202
204
 
@@ -244,12 +246,12 @@ class OAuth {
244
246
 
245
247
  async periodicRefresh() {
246
248
  const clients = this.clients;
247
-
248
- console.log('refreshing oauth clients', clients.length)
249
-
249
+
250
+ console.log("refreshing oauth clients", clients.length);
251
+
250
252
  for (let i = 0; i < clients.length; ++i) {
251
253
  const client = clients[0];
252
-
254
+
253
255
  await client.periodicRefresh();
254
256
  }
255
257
  }
@@ -321,7 +323,7 @@ class Connector {
321
323
  publicKey: process.env.PUBLIC_KEY,
322
324
  introspect,
323
325
  configSchema,
324
- icon: this.icon
326
+ icon: this.icon,
325
327
  });
326
328
 
327
329
  if (Object.keys(configSchema().fields).length) {
@@ -369,7 +371,7 @@ ${text}
369
371
  const value = secrets[key];
370
372
  if (!value) continue;
371
373
 
372
- if (fields[key]?.plain || ['endpointUrl'].includes(key)) {
374
+ if (fields[key]?.plain || ["endpointUrl"].includes(key)) {
373
375
  decrypted[key] = value;
374
376
  } else {
375
377
  try {
@@ -383,16 +385,17 @@ ${text}
383
385
  this.startOAuth = async function (args) {
384
386
  if (!this._oauth) throw new Error("oauth not configured");
385
387
 
386
- const clientId = process.env.OAUTH_CLIENT_ID ||
388
+ const clientId =
389
+ process.env.OAUTH_CLIENT_ID ||
387
390
  decrypted.clientId ||
388
- this._oauth.clientId;
389
-
391
+ this._oauth.clientId;
392
+
390
393
  if (!clientId) throw new Error("clientId not configured");
391
394
 
392
395
  const scopes =
393
396
  process.env.OAUTH_SCOPE ||
394
397
  decrypted.scope ||
395
- this._oauth.scope ||
398
+ this._oauth.scope ||
396
399
  "";
397
400
  const useCodeChallenge = !!that._oauth.useCodeChallenge;
398
401
 
@@ -417,18 +420,17 @@ ${text}
417
420
  if (!arg.code || !arg.redirectURI)
418
421
  throw new Error("need code and redirectUri");
419
422
 
420
- const clientId = process.env.OAUTH_CLIENT_ID ||
421
- decrypted.clientId ||
423
+ const clientId =
424
+ process.env.OAUTH_CLIENT_ID ||
425
+ decrypted.clientId ||
426
+ that._oauth.clientId;
422
427
 
423
- that._oauth.clientId;
424
-
425
- ;
426
428
  if (!clientId) throw new Error("clientId not configured");
427
429
 
428
430
  const clientSecret =
429
431
  process.env.OAUTH_CLIENT_SECRET ||
430
432
  decrypted.clientSecret ||
431
- that._oauth.clientSecret;
433
+ that._oauth.clientSecret;
432
434
  if (!clientSecret) throw new Error("clientSecret not configured");
433
435
 
434
436
  const additionalTokenArgs = that._oauth.additionalTokenArgs || {};
@@ -522,17 +524,15 @@ ${text}
522
524
 
523
525
  const getRefreshToken = async (refreshToken) => {
524
526
  const clientId =
525
-
526
527
  process.env.OAUTH_CLIENT_ID ||
527
- decrypted.clientId ||
528
- that._oauth.clientId;
528
+ decrypted.clientId ||
529
+ that._oauth.clientId;
529
530
  if (!clientId) throw new Error("clientId not configured");
530
531
 
531
532
  const clientSecret =
532
-
533
533
  process.env.OAUTH_CLIENT_SECRET ||
534
534
  decrypted.clientSecret ||
535
- that._oauth.clientSecret;
535
+ that._oauth.clientSecret;
536
536
  if (!clientSecret) throw new Error("clientSecret not configured");
537
537
 
538
538
  const useAuthHeader = !!that._oauth.useAuthHeader;
@@ -580,21 +580,21 @@ ${text}
580
580
 
581
581
  if (theOAuth) {
582
582
  clearInterval(this._refreshOAuthToken);
583
-
583
+
584
584
  if (!(this._oauth.noPeriodicTokenRefresh === false)) {
585
- this._refreshOAuthToken = setInterval(async () => {
586
-
587
- try
588
- {
589
- await theOAuth.periodicRefresh();
590
- } catch(e) {
591
- console.log('periodic refresh', e);
592
- }
593
- }, 4 * 60 * 60 * 15000);
585
+ this._refreshOAuthToken = setInterval(
586
+ async () => {
587
+ try {
588
+ await theOAuth.periodicRefresh();
589
+ } catch (e) {
590
+ console.log("periodic refresh", e);
591
+ }
592
+ },
593
+ 4 * 60 * 60 * 15000,
594
+ );
594
595
  }
595
-
596
596
  }
597
-
597
+
598
598
  start({
599
599
  config: decrypted,
600
600
  oauth: theOAuth,
@@ -13,7 +13,7 @@ class Config {
13
13
  publicKey,
14
14
  introspect,
15
15
  configSchema,
16
- icon
16
+ icon,
17
17
  }) {
18
18
  this._token = null;
19
19
  this._registrationToken = registrationToken;
@@ -100,7 +100,7 @@ class Config {
100
100
  token() {
101
101
  return this._token;
102
102
  }
103
-
103
+
104
104
  icon() {
105
105
  return this._icon;
106
106
  }
@@ -12,7 +12,7 @@ class Registration {
12
12
  const configSchema = config.configSchema();
13
13
  const intro = await config.introspect();
14
14
  const icon = config.icon();
15
-
15
+
16
16
  const response = await fetch(
17
17
  config.url() + "register",
18
18
  C.augmentRegistration(
@@ -25,7 +25,7 @@ class Registration {
25
25
  id: config.id(),
26
26
  publicKey: config.publicKey(),
27
27
  schema: { configSchema, introspect: intro },
28
- icon
28
+ icon,
29
29
  }),
30
30
  headers: { "Content-Type": "application/json" },
31
31
  },
@@ -68,9 +68,18 @@ class Transport {
68
68
  C.augmentRequest({ headers: {} }, config),
69
69
  ));
70
70
 
71
+ ws.onPing = function () {
72
+ clearTimeout(this.pingTimeout);
73
+ this.pingTimeout = setTimeout(() => {
74
+ console.log("terminating ws");
75
+ if (local.running) this.terminate();
76
+ }, 30000 + 15000);
77
+ };
78
+
71
79
  ws.on("open", () => {
72
80
  console.log("websocket connected");
73
81
  local.connected = true;
82
+ ws.onPing();
74
83
  local.pinger = setInterval(() => ws.ping(() => null), pingInterval);
75
84
 
76
85
  local.onConnect(local);
@@ -80,6 +89,8 @@ class Transport {
80
89
  setTimeout(() => local.onMessages(JSON.parse(message)), 0);
81
90
  });
82
91
 
92
+ ws.on("ping", () => ws.onPing());
93
+
83
94
  ws.on("error", (message) => {
84
95
  console.log("error:", message);
85
96
  });