jsgar 4.6.0 → 4.6.3

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 (3) hide show
  1. package/dist/gar.umd.js +17 -4
  2. package/gar.js +17 -4
  3. package/package.json +1 -1
package/dist/gar.umd.js CHANGED
@@ -92,6 +92,10 @@
92
92
  // (or jsgar's connect path) handles fallback if it's unreachable.
93
93
  async function optimalEndpoint(inetEndpoint) {
94
94
  if (_garAfUnixDisabled()) return inetEndpoint;
95
+ // Skip AF_UNIX for SSL — OpenSSL's non-blocking handshake over AF_UNIX
96
+ // produces sporadic failures.
97
+ const lower = inetEndpoint.toLowerCase();
98
+ if (lower.startsWith('wss://') || lower.startsWith('https://')) return inetEndpoint;
95
99
  if (!(await _garLoadNodeModules())) return inetEndpoint;
96
100
  let parsed;
97
101
  try { parsed = new URL(inetEndpoint); } catch { return inetEndpoint; }
@@ -189,8 +193,9 @@
189
193
  * @param {string} [logLevel='INFO'] - Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
190
194
  * @param {boolean} [uniqueKeyAndRecordUpdates=false] - Only one update per key/record
191
195
  * @param {string} [token=null] - Token for authenticated connections (appended as ?token= query param)
196
+ * @param {boolean} [logEveryMessage=false] - If true, log every message sent and received at INFO level.
192
197
  */
193
- constructor(wsEndpoint, user, working_namespace = null, heartbeatTimeoutInterval = 60000, allowSelfSignedCertificate = false, logLevel = 'INFO', uniqueKeyAndRecordUpdates = false, token = null) {
198
+ constructor(wsEndpoint, user, working_namespace = null, heartbeatTimeoutInterval = 60000, allowSelfSignedCertificate = false, logLevel = 'INFO', uniqueKeyAndRecordUpdates = false, token = null, logEveryMessage = false) {
194
199
  this.wsEndpoint = token ? `${wsEndpoint}${wsEndpoint.includes('?') ? '&' : '?'}token=${token}` : wsEndpoint;
195
200
  this.websocket = null;
196
201
  this.messageQueue = [];
@@ -204,6 +209,7 @@
204
209
  this.scaledHeartbeatTimeoutInterval *= this.timeoutScale;
205
210
  }
206
211
  this.unique_key_and_record_updates = uniqueKeyAndRecordUpdates;
212
+ this.logEveryMessage = logEveryMessage;
207
213
  this.version = 650709;
208
214
  this.uuid = GARClient._generateUUID();
209
215
 
@@ -321,9 +327,12 @@
321
327
  // Prefer AF_UNIX abstract-namespace transport for local destinations.
322
328
  // Falls back to TCP automatically (next reconnect iteration) if the
323
329
  // listener disappears between probe and real connect.
330
+ // Skip AF_UNIX for SSL — OpenSSL's non-blocking handshake over
331
+ // AF_UNIX produces sporadic failures.
332
+ const useSSL = this.wsEndpoint.toLowerCase().startsWith('wss://');
324
333
  let unixAbstractPath = null;
325
334
  let sniHost = null;
326
- if (isNode) {
335
+ if (isNode && !useSSL) {
327
336
  unixAbstractPath = await _garUnixAbstractPathForEndpoint(this.wsEndpoint);
328
337
  if (unixAbstractPath) {
329
338
  try { sniHost = new URL(this.wsEndpoint).hostname; } catch { /* ignore */ }
@@ -334,7 +343,6 @@
334
343
 
335
344
  const connectionPromise = new Promise((resolve, reject) => {
336
345
  let websocket;
337
- const useSSL = this.wsEndpoint.toLowerCase().startsWith('wss://');
338
346
  const wsOpts = {};
339
347
  if (this.allowSelfSignedCertificate && isNode && useSSL) {
340
348
  // Node.js 'ws' supports options for TLS; browsers do not.
@@ -434,7 +442,9 @@
434
442
  if (message === null) break;
435
443
  if (this._isSocketOpen()) {
436
444
  this.websocket.send(JSON.stringify(message));
437
- this.log('DEBUG', `Sent: ${JSON.stringify(message)}`);
445
+ if (this.logEveryMessage) {
446
+ this.log('INFO', `Sent: ${JSON.stringify(message)}`);
447
+ }
438
448
  }
439
449
  } catch (e) {
440
450
  this.log('WARNING', `Error sending message: ${e.message}`);
@@ -909,6 +919,9 @@
909
919
  * @param {Object} message - Incoming message
910
920
  */
911
921
  _processMessage(message) {
922
+ if (this.logEveryMessage) {
923
+ this.log('INFO', `Received: ${JSON.stringify(message)}`);
924
+ }
912
925
  const msgType = message.message_type;
913
926
  let subscriptionGroup = 0;
914
927
  if (msgType === 'TopicIntroduction') {
package/gar.js CHANGED
@@ -86,6 +86,10 @@ function _garLocalIPv4Set() {
86
86
  // (or jsgar's connect path) handles fallback if it's unreachable.
87
87
  async function optimalEndpoint(inetEndpoint) {
88
88
  if (_garAfUnixDisabled()) return inetEndpoint;
89
+ // Skip AF_UNIX for SSL — OpenSSL's non-blocking handshake over AF_UNIX
90
+ // produces sporadic failures.
91
+ const lower = inetEndpoint.toLowerCase();
92
+ if (lower.startsWith('wss://') || lower.startsWith('https://')) return inetEndpoint;
89
93
  if (!(await _garLoadNodeModules())) return inetEndpoint;
90
94
  let parsed;
91
95
  try { parsed = new URL(inetEndpoint); } catch { return inetEndpoint; }
@@ -183,8 +187,9 @@ class GARClient {
183
187
  * @param {string} [logLevel='INFO'] - Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
184
188
  * @param {boolean} [uniqueKeyAndRecordUpdates=false] - Only one update per key/record
185
189
  * @param {string} [token=null] - Token for authenticated connections (appended as ?token= query param)
190
+ * @param {boolean} [logEveryMessage=false] - If true, log every message sent and received at INFO level.
186
191
  */
187
- constructor(wsEndpoint, user, working_namespace = null, heartbeatTimeoutInterval = 60000, allowSelfSignedCertificate = false, logLevel = 'INFO', uniqueKeyAndRecordUpdates = false, token = null) {
192
+ constructor(wsEndpoint, user, working_namespace = null, heartbeatTimeoutInterval = 60000, allowSelfSignedCertificate = false, logLevel = 'INFO', uniqueKeyAndRecordUpdates = false, token = null, logEveryMessage = false) {
188
193
  this.wsEndpoint = token ? `${wsEndpoint}${wsEndpoint.includes('?') ? '&' : '?'}token=${token}` : wsEndpoint;
189
194
  this.websocket = null;
190
195
  this.messageQueue = [];
@@ -198,6 +203,7 @@ class GARClient {
198
203
  this.scaledHeartbeatTimeoutInterval *= this.timeoutScale;
199
204
  }
200
205
  this.unique_key_and_record_updates = uniqueKeyAndRecordUpdates;
206
+ this.logEveryMessage = logEveryMessage;
201
207
  this.version = 650709;
202
208
  this.uuid = GARClient._generateUUID();
203
209
 
@@ -315,9 +321,12 @@ class GARClient {
315
321
  // Prefer AF_UNIX abstract-namespace transport for local destinations.
316
322
  // Falls back to TCP automatically (next reconnect iteration) if the
317
323
  // listener disappears between probe and real connect.
324
+ // Skip AF_UNIX for SSL — OpenSSL's non-blocking handshake over
325
+ // AF_UNIX produces sporadic failures.
326
+ const useSSL = this.wsEndpoint.toLowerCase().startsWith('wss://');
318
327
  let unixAbstractPath = null;
319
328
  let sniHost = null;
320
- if (isNode) {
329
+ if (isNode && !useSSL) {
321
330
  unixAbstractPath = await _garUnixAbstractPathForEndpoint(this.wsEndpoint);
322
331
  if (unixAbstractPath) {
323
332
  try { sniHost = new URL(this.wsEndpoint).hostname; } catch { /* ignore */ }
@@ -328,7 +337,6 @@ class GARClient {
328
337
 
329
338
  const connectionPromise = new Promise((resolve, reject) => {
330
339
  let websocket;
331
- const useSSL = this.wsEndpoint.toLowerCase().startsWith('wss://');
332
340
  const wsOpts = {};
333
341
  if (this.allowSelfSignedCertificate && isNode && useSSL) {
334
342
  // Node.js 'ws' supports options for TLS; browsers do not.
@@ -428,7 +436,9 @@ class GARClient {
428
436
  if (message === null) break;
429
437
  if (this._isSocketOpen()) {
430
438
  this.websocket.send(JSON.stringify(message));
431
- this.log('DEBUG', `Sent: ${JSON.stringify(message)}`);
439
+ if (this.logEveryMessage) {
440
+ this.log('INFO', `Sent: ${JSON.stringify(message)}`);
441
+ }
432
442
  }
433
443
  } catch (e) {
434
444
  this.log('WARNING', `Error sending message: ${e.message}`);
@@ -903,6 +913,9 @@ class GARClient {
903
913
  * @param {Object} message - Incoming message
904
914
  */
905
915
  _processMessage(message) {
916
+ if (this.logEveryMessage) {
917
+ this.log('INFO', `Received: ${JSON.stringify(message)}`);
918
+ }
906
919
  const msgType = message.message_type;
907
920
  let subscriptionGroup = 0;
908
921
  if (msgType === 'TopicIntroduction') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsgar",
3
- "version": "4.6.0",
3
+ "version": "4.6.3",
4
4
  "description": "A Javascript client for the GAR protocol",
5
5
  "type": "module",
6
6
  "main": "dist/gar.umd.js",