@phystack/hub-client 4.4.29

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 (113) hide show
  1. package/.prettierignore +10 -0
  2. package/.prettierrc +10 -0
  3. package/CHANGELOG.md +1202 -0
  4. package/README-MEDIASTREAM.md +124 -0
  5. package/README.md +302 -0
  6. package/dist/constants/constants.d.ts +7 -0
  7. package/dist/constants/constants.d.ts.map +1 -0
  8. package/dist/constants/constants.js +10 -0
  9. package/dist/constants/constants.js.map +1 -0
  10. package/dist/helpers/browser.helper.d.ts +5 -0
  11. package/dist/helpers/browser.helper.d.ts.map +1 -0
  12. package/dist/helpers/browser.helper.js +19 -0
  13. package/dist/helpers/browser.helper.js.map +1 -0
  14. package/dist/helpers/cache.helper.d.ts +6 -0
  15. package/dist/helpers/cache.helper.d.ts.map +1 -0
  16. package/dist/helpers/cache.helper.js +46 -0
  17. package/dist/helpers/cache.helper.js.map +1 -0
  18. package/dist/helpers/date.helper.d.ts +4 -0
  19. package/dist/helpers/date.helper.d.ts.map +1 -0
  20. package/dist/helpers/date.helper.js +13 -0
  21. package/dist/helpers/date.helper.js.map +1 -0
  22. package/dist/helpers/session.helper.d.ts +13 -0
  23. package/dist/helpers/session.helper.d.ts.map +1 -0
  24. package/dist/helpers/session.helper.js +88 -0
  25. package/dist/helpers/session.helper.js.map +1 -0
  26. package/dist/helpers/shorten-look-ups.helper.d.ts +3 -0
  27. package/dist/helpers/shorten-look-ups.helper.d.ts.map +1 -0
  28. package/dist/helpers/shorten-look-ups.helper.js +80 -0
  29. package/dist/helpers/shorten-look-ups.helper.js.map +1 -0
  30. package/dist/helpers/signals-client.helper.d.ts +9 -0
  31. package/dist/helpers/signals-client.helper.d.ts.map +1 -0
  32. package/dist/helpers/signals-client.helper.js +44 -0
  33. package/dist/helpers/signals-client.helper.js.map +1 -0
  34. package/dist/helpers/signals.helper.d.ts +19 -0
  35. package/dist/helpers/signals.helper.d.ts.map +1 -0
  36. package/dist/helpers/signals.helper.js +48 -0
  37. package/dist/helpers/signals.helper.js.map +1 -0
  38. package/dist/helpers/wrtc/browser.d.ts +3 -0
  39. package/dist/helpers/wrtc/browser.d.ts.map +1 -0
  40. package/dist/helpers/wrtc/browser.js +11 -0
  41. package/dist/helpers/wrtc/browser.js.map +1 -0
  42. package/dist/helpers/wrtc/index.d.ts +5 -0
  43. package/dist/helpers/wrtc/index.d.ts.map +1 -0
  44. package/dist/helpers/wrtc/index.js +30 -0
  45. package/dist/helpers/wrtc/index.js.map +1 -0
  46. package/dist/helpers/wrtc/node.d.ts +3 -0
  47. package/dist/helpers/wrtc/node.d.ts.map +1 -0
  48. package/dist/helpers/wrtc/node.js +18 -0
  49. package/dist/helpers/wrtc/node.js.map +1 -0
  50. package/dist/index.d.ts +109 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +1013 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/services/online-status-subscription.service.d.ts +28 -0
  55. package/dist/services/online-status-subscription.service.d.ts.map +1 -0
  56. package/dist/services/online-status-subscription.service.js +96 -0
  57. package/dist/services/online-status-subscription.service.js.map +1 -0
  58. package/dist/services/phyhub-connection.service.d.ts +20 -0
  59. package/dist/services/phyhub-connection.service.d.ts.map +1 -0
  60. package/dist/services/phyhub-connection.service.js +176 -0
  61. package/dist/services/phyhub-connection.service.js.map +1 -0
  62. package/dist/services/signals.service.d.ts +97 -0
  63. package/dist/services/signals.service.d.ts.map +1 -0
  64. package/dist/services/signals.service.js +536 -0
  65. package/dist/services/signals.service.js.map +1 -0
  66. package/dist/services/webrtc/datachannel.d.ts +10 -0
  67. package/dist/services/webrtc/datachannel.d.ts.map +1 -0
  68. package/dist/services/webrtc/datachannel.js +290 -0
  69. package/dist/services/webrtc/datachannel.js.map +1 -0
  70. package/dist/services/webrtc/mediastream.d.ts +10 -0
  71. package/dist/services/webrtc/mediastream.d.ts.map +1 -0
  72. package/dist/services/webrtc/mediastream.js +396 -0
  73. package/dist/services/webrtc/mediastream.js.map +1 -0
  74. package/dist/services/webrtc/peer-connection-ice.d.ts +32 -0
  75. package/dist/services/webrtc/peer-connection-ice.d.ts.map +1 -0
  76. package/dist/services/webrtc/peer-connection-ice.js +483 -0
  77. package/dist/services/webrtc/peer-connection-ice.js.map +1 -0
  78. package/dist/types/signal.types.d.ts +354 -0
  79. package/dist/types/signal.types.d.ts.map +1 -0
  80. package/dist/types/signal.types.js +53 -0
  81. package/dist/types/signal.types.js.map +1 -0
  82. package/dist/types/twin.types.d.ts +705 -0
  83. package/dist/types/twin.types.d.ts.map +1 -0
  84. package/dist/types/twin.types.js +21 -0
  85. package/dist/types/twin.types.js.map +1 -0
  86. package/dist/types/webrtc.types.d.ts +41 -0
  87. package/dist/types/webrtc.types.d.ts.map +1 -0
  88. package/dist/types/webrtc.types.js +3 -0
  89. package/dist/types/webrtc.types.js.map +1 -0
  90. package/package.json +50 -0
  91. package/src/constants/constants.ts +12 -0
  92. package/src/helpers/browser.helper.ts +15 -0
  93. package/src/helpers/cache.helper.ts +52 -0
  94. package/src/helpers/date.helper.ts +8 -0
  95. package/src/helpers/session.helper.ts +96 -0
  96. package/src/helpers/shorten-look-ups.helper.ts +75 -0
  97. package/src/helpers/signals-client.helper.ts +54 -0
  98. package/src/helpers/signals.helper.ts +41 -0
  99. package/src/helpers/wrtc/browser.ts +9 -0
  100. package/src/helpers/wrtc/index.ts +32 -0
  101. package/src/helpers/wrtc/node.ts +16 -0
  102. package/src/index.ts +1429 -0
  103. package/src/services/online-status-subscription.service.ts +127 -0
  104. package/src/services/phyhub-connection.service.ts +213 -0
  105. package/src/services/signals.service.ts +783 -0
  106. package/src/services/webrtc/datachannel.ts +421 -0
  107. package/src/services/webrtc/mediastream.ts +602 -0
  108. package/src/services/webrtc/peer-connection-ice.ts +689 -0
  109. package/src/types/lodash.d.ts +3 -0
  110. package/src/types/signal.types.ts +382 -0
  111. package/src/types/twin.types.ts +803 -0
  112. package/src/types/webrtc.types.ts +48 -0
  113. package/tsconfig.json +45 -0
@@ -0,0 +1,124 @@
1
+ # WebRTC MediaStream Improvements
2
+
3
+ This document outlines the improvements made to the WebRTC MediaStream implementation in the hub-client package. These changes address several key issues with frame detection, connection management, and track handling.
4
+
5
+ ## Key Improvements
6
+
7
+ ### 1. Frame-Level Detection
8
+
9
+ **Problem:** The original implementation only checked `track.readyState === 'live'` to determine if a track was actively receiving frames, which could result in false positives when a source disconnected but the WebRTC connection remained open.
10
+
11
+ **Solution:** Added frame-level detection that tracks the timestamps of actual frames received, allowing applications to detect when frames stop flowing even if the WebRTC connection remains active.
12
+
13
+ ```typescript
14
+ // Use the improved isReceivingFrames method
15
+ const isActive = stream.isReceivingFrames();
16
+ if (!isActive) {
17
+ console.log('No frames received in the last 5 seconds');
18
+ }
19
+ ```
20
+
21
+ ### 2. Enhanced Track Management
22
+
23
+ **Problem:** The track management in the custom `PhygridMediaStream` implementation could get out of sync with the actual MediaStream from WebRTC.
24
+
25
+ **Solution:** Improved track management with proper cleanup and synchronization between the custom PhygridMediaStream implementation and native WebRTC MediaStream.
26
+
27
+ ### 3. Automatic Reconnection
28
+
29
+ **Problem:** Connection restoration after source disconnection was unreliable and could result in "ghost" connections.
30
+
31
+ **Solution:** Added automatic reconnection logic based on frame activity, not just connection state:
32
+
33
+ - Tracks the timestamp of the last frame received for each track
34
+ - If no frames are received within a configurable timeout (default: 5 seconds), considers the connection inactive
35
+ - Automatically triggers reconnection when frames stop flowing but the connection appears active
36
+
37
+ ### 4. Memory Leak Prevention
38
+
39
+ **Problem:** Event listeners weren't always properly cleaned up, potentially causing memory leaks.
40
+
41
+ **Solution:** Added proper cleanup mechanisms for all event listeners:
42
+
43
+ - Centralized tracking of frame timestamps
44
+ - Interval-based checks with proper cleanup on stream close
45
+ - Safe removal of track handlers
46
+
47
+ ### 5. Developer-Friendly API
48
+
49
+ **Problem:** The API wasn't intuitive for frame-level operations.
50
+
51
+ **Solution:** Added new methods to the `PhygridMediaStream` interface:
52
+
53
+ ```typescript
54
+ interface PhygridMediaStream {
55
+ // Existing methods
56
+ getTracks(): MediaStreamTrack[];
57
+ onTrack(callback: (track: MediaStreamTrack) => void): void;
58
+ offTrack(callback: (track: MediaStreamTrack) => void): void;
59
+ onClose(callback: () => void): void;
60
+ offClose(callback: () => void): void;
61
+ close(): void;
62
+ addTrack(track: MediaStreamTrack): void;
63
+
64
+ // New methods
65
+ onFrame(callback: (frameData: any) => void): void;
66
+ offFrame(callback: (frameData: any) => void): void;
67
+ isReceivingFrames(): boolean;
68
+ }
69
+ ```
70
+
71
+ ## Integration with Applications
72
+
73
+ For applications using the hub-client package (like camera-viewer-edge), the integration is straightforward:
74
+
75
+ 1. Use the `onFrame` method to detect when frames are received
76
+ 2. Use the `isReceivingFrames` method to check if frames are actively flowing
77
+ 3. Set up periodic checks to monitor the health of the connection
78
+
79
+ Example:
80
+
81
+ ```typescript
82
+ const { stream } = await cameraInstance.getMediaStream();
83
+
84
+ // Listen for frames
85
+ stream.onFrame((frameData) => {
86
+ console.log('Received frame:', frameData);
87
+ });
88
+
89
+ // Check connection health periodically
90
+ setInterval(() => {
91
+ if (!stream.isReceivingFrames()) {
92
+ console.log('Connection is stale - no frames received recently');
93
+ }
94
+ }, 5000);
95
+ ```
96
+
97
+ ## Application-Specific Changes
98
+
99
+ For applications already using the hub-client package without the latest updates, a type definition bridge has been provided:
100
+
101
+ ```typescript
102
+ // types.ts
103
+ declare module '@phystack/hub-client' {
104
+ interface PhygridMediaStream {
105
+ onFrame(callback: (frameData: any) => void): void;
106
+ offFrame(callback: (frameData: any) => void): void;
107
+ isReceivingFrames(): boolean;
108
+ }
109
+ }
110
+ ```
111
+
112
+ Import this file in your application to use the enhanced API with the current hub-client version:
113
+
114
+ ```typescript
115
+ import './types';
116
+ ```
117
+
118
+ ## Testing
119
+
120
+ These changes have been tested with the camera-edge and camera-viewer-edge applications to ensure they properly handle connection failures, source disconnections, and reconnections.
121
+
122
+ ---
123
+
124
+ *Note: The WebRTC signaling is still handled through twin messages in the Phygrid Hub platform, maintaining compatibility with existing infrastructure.*
package/README.md ADDED
@@ -0,0 +1,302 @@
1
+ # PhyHub Client
2
+
3
+ The PhyHubClient is a Node.js class designed to facilitate communication with the PhyHub platform. It provides methods to connect to the PhyHub server, emit events, and handle responses.
4
+
5
+ ## Installation
6
+ To use the PhyHubClient in your project, you can install it via npm or yarn:
7
+
8
+ ```bash
9
+ npm install @phystack/hub-client
10
+ ```
11
+ ```bash
12
+ yarn add @phystack/hub-client
13
+ ```
14
+
15
+ ## Usage
16
+ ### Importing the Client
17
+ You can import the PhyHubClient class and the connectPhyClient function in your project as follows:
18
+
19
+ ```javascript
20
+ import { PhyHubClient, connectPhyClient } from '@phystack/hub-client';
21
+ ```
22
+
23
+ ### Connecting to PhyHub
24
+ To connect to the PhyHub server, use the connectPhyClient function:
25
+
26
+ ```javascript
27
+ const moduleName = 'your-module-name'; // Optional, defaults to Application Instace ID
28
+ const dataResidency = 'EU'; // Optional, defaults to 'EU'
29
+
30
+ const client: PhyHubClient = await connectPhyClient(moduleName, dataResidency);
31
+ ```
32
+
33
+ or
34
+ ```javascript
35
+ const client: PhyHubClient = await connectPhyClient();
36
+ ```
37
+
38
+ ### Methods
39
+ `isConnected()`
40
+ Check if PhyHub is connected:
41
+
42
+ ```javascript
43
+ const isConnected = client.isConnected();
44
+ console.log(`Is connected: ${isConnected}`);
45
+ ```
46
+
47
+ `getDeviceStatus()`
48
+ Retrieve the device status:
49
+
50
+ ```javascript
51
+ const deviceStatus = await client.getDeviceStatus();
52
+ console.log('Device Status:', deviceStatus);
53
+ ```
54
+
55
+ `getScreenInstance()`
56
+ Retrieve the screen instance settings:
57
+
58
+ ```javascript
59
+ const screenInstance = await client.getScreenInstance();
60
+ console.log('Screen Instance:', screenInstance);
61
+ ```
62
+
63
+ `getEdgeInstance()`
64
+ Retrieve the edge instance settings:
65
+
66
+ ```javascript
67
+ const edgeInstance = await client.getEdgeInstance();
68
+ console.log('Edge Instance:', edgeInstance);
69
+ ```
70
+
71
+
72
+ `getDeviceInstance()`
73
+ Retrieve the device instance:
74
+
75
+ ```javascript
76
+ const deviceInstance = await client.getDeviceInstance();
77
+ console.log('Device Instance:', deviceInstance);
78
+ ```
79
+
80
+
81
+ `getDeviceNetworks()`
82
+ Retrieve the device networks:
83
+
84
+ ```javascript
85
+ const deviceNetworks = await client.getDeviceNetworks();
86
+ console.log('Device Networks:', deviceNetworks);
87
+ ```
88
+
89
+
90
+ `setScreenInstanceReportedProperties(payload)`
91
+ Set the reported properties for the screen instance:
92
+
93
+ ```javascript
94
+ const payload = {
95
+ // Your payload here
96
+ };
97
+
98
+ const response = await client.setScreenInstanceReportedProperties(payload);
99
+ console.log('Response:', response);
100
+ ```
101
+
102
+
103
+ `emit(method, ...args)`
104
+ Emit a custom event:
105
+
106
+ ```javascript
107
+ client.emit('yourMethod', { yourData: 'data' }, (response) => {
108
+ console.log('Response:', response);
109
+ });
110
+ ```
111
+
112
+ `emitTo(targetInstance, method, ...args)`
113
+ Emit a custom event to a specific target instance:
114
+
115
+ ```javascript
116
+ client.emitTo('targetInstance', 'yourMethod', { yourData: 'data' }, (response) => {
117
+ console.log('Response:', response);
118
+ });
119
+ ```
120
+
121
+
122
+ ### Example
123
+ Here is a complete example demonstrating how to use the PhyHubClient:
124
+
125
+ ```javascript
126
+
127
+ import { connectPhyClient } from '@phystack/hub-client';
128
+
129
+ async function main() {
130
+ try {
131
+ const client = await connectPhyClient();
132
+
133
+ if (client.isConnected()) {
134
+ console.log('Connected to PhyHub');
135
+
136
+ const deviceStatus = await client.getDeviceStatus();
137
+ console.log('Device Status:', deviceStatus);
138
+
139
+ const edgeInstance = await client.getEdgeInstance();
140
+ console.log('Edge Instance:', edgeInstance);
141
+ }
142
+ } catch (error) {
143
+ console.error('Error:', error);
144
+ }
145
+ }
146
+
147
+ main();
148
+ ```
149
+
150
+ ---
151
+ # Signals
152
+
153
+ The `hub-client` can be used to initialize and utilize signals efficiently.
154
+
155
+ ### Initialization
156
+
157
+ To initialize and use signals, follow this pattern:
158
+ ```javascript
159
+ public initializeSignals = async (initParams?: InitSignalPayload) => Promise<SignalsService>
160
+ ```
161
+
162
+ ### Parameters
163
+
164
+ | Parameter | Type | Description |
165
+ |-------------|--------------------|-------------|
166
+ | `initParams` | `InitSignalPayload` (optional) | Optional payload containing initialization data. If not provided, the method fetches necessary data from the device and instance settings. |
167
+
168
+
169
+ ### Example
170
+
171
+ ```javascript
172
+ import { connectPhyClient } from '@phystack/hub-client';
173
+
174
+ const initParams = {
175
+ "deviceId": "device-12345",
176
+ "installationId": "install-67890",
177
+ "spaceId": "space-abcdef",
178
+ "tenantId": "tenant-xyz",
179
+ "appVersion": "1.0.0",
180
+ "appId": "com.example.app",
181
+ "environment": "production",
182
+ "dataResidency": "EU",
183
+ "country": "SE",
184
+ "installationVersion": "2.3.4",
185
+ "accessToken": "eyJhbGciOiJIUzI1NiIsInR...",
186
+ "clientUserAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
187
+ "ip": "192.168.1.100"
188
+ };
189
+
190
+ const client = await connectPhyClient();
191
+ const signals = await client.initializeSignals(initParams);
192
+ signals.sendEvent(...);
193
+ ```
194
+
195
+ or
196
+
197
+ ```javascript
198
+ import { connectPhyClient } from '@phystack/hub-client';
199
+
200
+ const client = await connectPhyClient();
201
+ const signals = await client.initializeSignals();
202
+ signals.sendEvent(...);
203
+ ```
204
+
205
+ ## Available Methods
206
+
207
+ ### Instance Management
208
+ - **`getInstanceProps()`** Returns instance props.
209
+
210
+ #### Session Management
211
+
212
+ - **`createSession()`** Creates a new session and initializes the instance with the required parameters.
213
+
214
+ - **`initialize(signalParams: InitSignalPayload)`** Initializes the `SignalsService` with the provided signal parameters.
215
+
216
+ - **`initializeEdgeApp(signalParams: InitSignalPayload | {} = {})`** Initializes the `SignalsService` for edge applications with the given parameters.
217
+
218
+ #### Application Tracking
219
+
220
+ - **`sendAppOnline(message?: string)`** Tracks when the application comes online.
221
+
222
+ - **`sendAppOffline(message?: string)`** Tracks when the application goes offline.
223
+
224
+ #### Event Handling
225
+
226
+ - **`sendEvent(event: Event, expectResponse?: boolean)`** Sends an event to the server.
227
+
228
+ - **`sendCustomEvent(event: TrackEvent)`** Sends a custom event.
229
+
230
+ #### Transaction Events
231
+
232
+ - **`sendCheckout(checkout: CheckoutEvent, expectResponse?: boolean)`** Sends a checkout event.
233
+
234
+ - **`sendPurchase(purchase: PurchaseEvent, expectResponse?: boolean)`** Sends a purchase event.
235
+
236
+ #### Session & Client Data
237
+
238
+ - **`sendSession(session: Session, expectResponse?: boolean)`** Sends session data to the server.
239
+
240
+ - **`sendClient(client: Client, expectResponse?: boolean)`** Sends client information to the server.
241
+
242
+ #### Order Processing
243
+
244
+ - **`sendProcessOrderStart()`** Tracks the start of an order process.
245
+
246
+ - **`sendProcessOrderEnd()`** Tracks the end of an order process.
247
+
248
+ - **`sendProcessOrderSuccess()`** Tracks a successful order process.
249
+
250
+ - **`sendProcessOrderFailed()`** Tracks a failed order process.
251
+
252
+ - **`sendOrderItem(params: object)`** Tracks an item in an order.
253
+
254
+ - **`sendProcessOrderItemDelivered(params: object)`** Tracks an item that was successfully delivered.
255
+
256
+ - **`sendProcessOrderItemFailed(params: object)`** Tracks an item that failed to be delivered.
257
+
258
+ #### Authentication Events
259
+
260
+ - **`sendAuthenticationSuccess()`** Tracks a successful authentication event.
261
+
262
+ - **`sendAuthenticationFailed()`** Tracks a failed authentication event.
263
+
264
+ #### Barcode & Media Events
265
+
266
+ - **`sendScanBarcode(params: object)`** Tracks a barcode scan event.
267
+
268
+ - **`sendMediaFinished(params: object)`** Tracks when media content has finished playing.
269
+
270
+ #### Product & Cart Events
271
+
272
+ - **`sendCategoryView(params: object)`** Tracks viewing a product category.
273
+
274
+ - **`sendProductView(params: object)`** Tracks viewing a specific product.
275
+
276
+ - **`sendCartAdd(params: object)`** Tracks adding a product to the cart.
277
+
278
+ - **`sendCartView()`** Tracks viewing the cart.
279
+
280
+ - **`sendCartRemove(params: object)`** Tracks removing a product from the cart.
281
+
282
+ - **`sendCartClear()`** Tracks clearing the cart.
283
+
284
+ #### Search & Feedback
285
+
286
+ - **`sendSearch(params: object)`** Tracks searching for a product or category.
287
+
288
+ - **`sendSearchClear()`** Tracks clearing the search.
289
+
290
+ - **`sendRating(params: object)`** Tracks user ratings of the experience.
291
+
292
+ - **`sendFeedback(params: object)`** Tracks user feedback.
293
+
294
+ - **`sendQrScan()`** Tracks a QR code scan.
295
+
296
+ #### State Management
297
+
298
+ - **`setState(params: object)`** Sets a state key, value, and expiry duration.
299
+
300
+ ---
301
+
302
+ This structured documentation makes it easier to understand the available signal methods and their usage.
@@ -0,0 +1,7 @@
1
+ export declare const MESSAGE_PREFIX = "@phystack/hub-client:";
2
+ export declare const EVENTS_CACHE_KEY = "_OMBORI_GRID_SIGNALS_EVENTS_CACHE";
3
+ export declare const CLIENT_CACHE_KEY = "_OMBORI_GRID_SIGNALS_CLIENT_CACHE";
4
+ export declare const SESSION_CACHE_KEY = "_OMBORI_GRID_SIGNALS_SESSION_CACHE";
5
+ export declare const LAST_ACTIVITY_CACHE_KEY = "_OMBORI_GRID_SIGNALS_LAST_ACTIVITY_CACHE";
6
+ export declare const DEFAULT_MAX_SESSION_LAST_ACTIVITY_MINS = 30;
7
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,0BAA0B,CAAC;AACtD,eAAO,MAAM,gBAAgB,sCAAsC,CAAC;AACpE,eAAO,MAAM,gBAAgB,sCAAsC,CAAC;AACpE,eAAO,MAAM,iBAAiB,uCAAuC,CAAC;AACtE,eAAO,MAAM,uBAAuB,6CAA6C,CAAC;AAClF,eAAO,MAAM,sCAAsC,KAAK,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_MAX_SESSION_LAST_ACTIVITY_MINS = exports.LAST_ACTIVITY_CACHE_KEY = exports.SESSION_CACHE_KEY = exports.CLIENT_CACHE_KEY = exports.EVENTS_CACHE_KEY = exports.MESSAGE_PREFIX = void 0;
4
+ exports.MESSAGE_PREFIX = '@phystack/hub-client:';
5
+ exports.EVENTS_CACHE_KEY = '_OMBORI_GRID_SIGNALS_EVENTS_CACHE';
6
+ exports.CLIENT_CACHE_KEY = '_OMBORI_GRID_SIGNALS_CLIENT_CACHE';
7
+ exports.SESSION_CACHE_KEY = '_OMBORI_GRID_SIGNALS_SESSION_CACHE';
8
+ exports.LAST_ACTIVITY_CACHE_KEY = '_OMBORI_GRID_SIGNALS_LAST_ACTIVITY_CACHE';
9
+ exports.DEFAULT_MAX_SESSION_LAST_ACTIVITY_MINS = 30;
10
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,uBAAuB,CAAC;AACzC,QAAA,gBAAgB,GAAG,mCAAmC,CAAC;AACvD,QAAA,gBAAgB,GAAG,mCAAmC,CAAC;AACvD,QAAA,iBAAiB,GAAG,oCAAoC,CAAC;AACzD,QAAA,uBAAuB,GAAG,0CAA0C,CAAC;AACrE,QAAA,sCAAsC,GAAG,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ import OnlineStatusSubscription from '../services/online-status-subscription.service';
2
+ export declare const isBrowser: boolean;
3
+ export declare const browserWindow: any;
4
+ export declare const getOnlineStatusSubscription: () => OnlineStatusSubscription;
5
+ //# sourceMappingURL=browser.helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/browser.helper.ts"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,MAAM,gDAAgD,CAAC;AAEtF,eAAO,MAAM,SAAS,SAAgC,CAAC;AAEvD,eAAO,MAAM,aAAa,KAAmC,CAAC;AAE9D,eAAO,MAAM,2BAA2B,QAOqB,wBAC5D,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getOnlineStatusSubscription = exports.browserWindow = exports.isBrowser = void 0;
7
+ const online_status_subscription_service_1 = __importDefault(require("../services/online-status-subscription.service"));
8
+ exports.isBrowser = typeof window !== 'undefined';
9
+ exports.browserWindow = exports.isBrowser ? window : {};
10
+ const getOnlineStatusSubscription = () => {
11
+ if (!exports.browserWindow.globalGridOnlineStatusSubscription) {
12
+ const onlineStatusSubscription = new online_status_subscription_service_1.default();
13
+ onlineStatusSubscription.start();
14
+ exports.browserWindow.globalGridOnlineStatusSubscription = onlineStatusSubscription;
15
+ }
16
+ return exports.browserWindow.globalGridOnlineStatusSubscription;
17
+ };
18
+ exports.getOnlineStatusSubscription = getOnlineStatusSubscription;
19
+ //# sourceMappingURL=browser.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.helper.js","sourceRoot":"","sources":["../../src/helpers/browser.helper.ts"],"names":[],"mappings":";;;;;;AAAA,wHAAsF;AAEzE,QAAA,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;AAE1C,QAAA,aAAa,GAAG,iBAAS,CAAC,CAAC,CAAE,MAAc,CAAC,CAAC,CAAC,EAAE,CAAC;AAEvD,MAAM,2BAA2B,GAAG,GAAG,EAAE;IAC9C,IAAI,CAAC,qBAAa,CAAC,kCAAkC,EAAE,CAAC;QACtD,MAAM,wBAAwB,GAAG,IAAI,4CAAwB,EAAE,CAAC;QAChE,wBAAwB,CAAC,KAAK,EAAE,CAAC;QACjC,qBAAa,CAAC,kCAAkC,GAAG,wBAAwB,CAAC;IAC9E,CAAC;IAED,OAAO,qBAAa,CAAC,kCAA8D,CAAC;AACtF,CAAC,CAAC;AARW,QAAA,2BAA2B,+BAQtC"}
@@ -0,0 +1,6 @@
1
+ import { DataRequestTypeEnum, RequestData } from '../types/signal.types';
2
+ export declare const supportsLocalStorage: any;
3
+ export declare const cache: any[];
4
+ export declare const cacheData: (type: DataRequestTypeEnum, data: RequestData) => void;
5
+ export declare let flushCacheOnce: any;
6
+ //# sourceMappingURL=cache.helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/cache.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAwB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAG/F,eAAO,MAAM,oBAAoB,KAU/B,CAAC;AAEH,eAAO,MAAM,KAAK,EAAE,GAAG,EAEjB,CAAC;AAEP,eAAO,MAAM,SAAS,GAAI,MAAM,mBAAmB,EAAE,MAAM,WAAW,SASrE,CAAC;AAsBF,eAAO,IAAI,cAAc,KAAmB,CAAC"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.flushCacheOnce = exports.cacheData = exports.cache = exports.supportsLocalStorage = void 0;
7
+ const lodash_once_1 = __importDefault(require("lodash.once"));
8
+ const constants_1 = require("../constants/constants");
9
+ exports.supportsLocalStorage = (0, lodash_once_1.default)(() => {
10
+ const value = '_OMBORI_GRID_SIGNALS_CACHE_TEST';
11
+ try {
12
+ localStorage.setItem(value, value);
13
+ localStorage.removeItem(value);
14
+ return true;
15
+ }
16
+ catch (e) {
17
+ return false;
18
+ }
19
+ });
20
+ exports.cache = (0, exports.supportsLocalStorage)()
21
+ ? JSON.parse(localStorage.getItem(constants_1.EVENTS_CACHE_KEY) || '[]')
22
+ : [];
23
+ const cacheData = (type, data) => {
24
+ if (exports.cache.length >= 10000) {
25
+ exports.cache.shift();
26
+ }
27
+ exports.cache.push({ type, data });
28
+ (0, exports.supportsLocalStorage)() && localStorage.setItem(constants_1.EVENTS_CACHE_KEY, JSON.stringify(exports.cache));
29
+ };
30
+ exports.cacheData = cacheData;
31
+ const delay = (ms) => new Promise(resolve => {
32
+ setTimeout(resolve, ms);
33
+ });
34
+ const flushCache = async (sendOrCacheData) => {
35
+ while (exports.cache.length) {
36
+ const event = exports.cache.shift();
37
+ if (event) {
38
+ sendOrCacheData(event.type, event.data);
39
+ await delay(100);
40
+ }
41
+ }
42
+ (0, exports.supportsLocalStorage)() && localStorage.removeItem(constants_1.EVENTS_CACHE_KEY);
43
+ exports.flushCacheOnce = (0, lodash_once_1.default)(flushCache);
44
+ };
45
+ exports.flushCacheOnce = (0, lodash_once_1.default)(flushCache);
46
+ //# sourceMappingURL=cache.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.helper.js","sourceRoot":"","sources":["../../src/helpers/cache.helper.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA+B;AAE/B,sDAA0D;AAE7C,QAAA,oBAAoB,GAAG,IAAA,qBAAI,EAAC,GAAG,EAAE;IAC5C,MAAM,KAAK,GAAG,iCAAiC,CAAC;IAEhD,IAAI,CAAC;QACH,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACnC,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC,CAAC;AAEU,QAAA,KAAK,GAAU,IAAA,4BAAoB,GAAE;IAChD,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,4BAAgB,CAAC,IAAI,IAAI,CAAC;IAC5D,CAAC,CAAC,EAAE,CAAC;AAEA,MAAM,SAAS,GAAG,CAAC,IAAyB,EAAE,IAAiB,EAAE,EAAE;IAExE,IAAI,aAAK,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC;QAC1B,aAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;IAED,aAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAE3B,IAAA,4BAAoB,GAAE,IAAI,YAAY,CAAC,OAAO,CAAC,4BAAgB,EAAE,IAAI,CAAC,SAAS,CAAC,aAAK,CAAC,CAAC,CAAC;AAC1F,CAAC,CAAC;AATW,QAAA,SAAS,aASpB;AAEF,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAC3B,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;IACpB,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC;AAEL,MAAM,UAAU,GAAG,KAAK,EAAE,eAAqC,EAAE,EAAE;IACjE,OAAO,aAAK,CAAC,MAAM,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,aAAK,CAAC,KAAK,EAAE,CAAC;QAC5B,IAAI,KAAK,EAAE,CAAC;YACV,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YAExC,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IAED,IAAA,4BAAoB,GAAE,IAAI,YAAY,CAAC,UAAU,CAAC,4BAAgB,CAAC,CAAC;IAEpE,sBAAc,GAAG,IAAA,qBAAI,EAAC,UAAU,CAAC,CAAC;AACpC,CAAC,CAAC;AAES,QAAA,cAAc,GAAG,IAAA,qBAAI,EAAC,UAAU,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const dateHelper: () => string;
2
+ export declare const getDateString: () => string;
3
+ export declare const getDifInMins: (date: string, dateToCompare: string) => number;
4
+ //# sourceMappingURL=date.helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/date.helper.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,cAAiC,CAAC;AAEzD,eAAO,MAAM,aAAa,cAAiC,CAAC;AAE5D,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,EAAE,eAAe,MAAM,WAG/D,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDifInMins = exports.getDateString = exports.dateHelper = void 0;
4
+ const dateHelper = () => new Date().toISOString();
5
+ exports.dateHelper = dateHelper;
6
+ const getDateString = () => new Date().toISOString();
7
+ exports.getDateString = getDateString;
8
+ const getDifInMins = (date, dateToCompare) => {
9
+ const dif = new Date(date).getTime() - new Date(dateToCompare).getTime();
10
+ return Math.round(dif / 60000);
11
+ };
12
+ exports.getDifInMins = getDifInMins;
13
+ //# sourceMappingURL=date.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.helper.js","sourceRoot":"","sources":["../../src/helpers/date.helper.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAA5C,QAAA,UAAU,cAAkC;AAElD,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAA/C,QAAA,aAAa,iBAAkC;AAErD,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,aAAqB,EAAE,EAAE;IAClE,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE,CAAC;IACzE,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC;AACjC,CAAC,CAAC;AAHW,QAAA,YAAY,gBAGvB"}
@@ -0,0 +1,13 @@
1
+ export declare const supportsSessionStorage: any;
2
+ export declare const cacheSession: (sessionId: string, sessionCreated: string) => void;
3
+ export declare const generateSession: ({ forceCreateNewSession, maxSessionLastActivityMins, }: {
4
+ forceCreateNewSession?: boolean;
5
+ maxSessionLastActivityMins: number;
6
+ }) => {
7
+ sessionId: string;
8
+ sessionCreated: string;
9
+ isFromCache: boolean;
10
+ };
11
+ export declare const getLastActivityCache: () => string | null;
12
+ export declare const setLastActivityCache: (dateString: string) => string | false;
13
+ //# sourceMappingURL=session.helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/session.helper.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,sBAAsB,KAUjC,CAAC;AAaH,eAAO,MAAM,YAAY,GAAI,WAAW,MAAM,EAAE,gBAAgB,MAAM,SAErE,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,wDAG7B;IACD,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,0BAA0B,EAAE,MAAM,CAAC;CACpC;;;;CA+BA,CAAC;AAEF,eAAO,MAAM,oBAAoB,qBAShC,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,YAAY,MAAM,mBAQtD,CAAC"}