@multiplayer-app/session-recorder-react-native 1.2.37 → 1.3.2

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 (54) hide show
  1. package/lib/module/config/constants.js +3 -0
  2. package/lib/module/config/constants.js.map +1 -1
  3. package/lib/module/config/defaults.js +2 -1
  4. package/lib/module/config/defaults.js.map +1 -1
  5. package/lib/module/config/session-recorder.js +2 -1
  6. package/lib/module/config/session-recorder.js.map +1 -1
  7. package/lib/module/recorder/index.js +7 -18
  8. package/lib/module/recorder/index.js.map +1 -1
  9. package/lib/module/services/api.service.js +2 -2
  10. package/lib/module/services/api.service.js.map +1 -1
  11. package/lib/module/services/socket.service.js +176 -0
  12. package/lib/module/services/socket.service.js.map +1 -0
  13. package/lib/module/session-recorder.js +67 -11
  14. package/lib/module/session-recorder.js.map +1 -1
  15. package/lib/module/types/session-recorder.js.map +1 -1
  16. package/lib/module/types/session.js.map +1 -1
  17. package/lib/module/utils/logger.js +1 -1
  18. package/lib/typescript/src/config/constants.d.ts +3 -0
  19. package/lib/typescript/src/config/constants.d.ts.map +1 -1
  20. package/lib/typescript/src/config/defaults.d.ts.map +1 -1
  21. package/lib/typescript/src/config/session-recorder.d.ts.map +1 -1
  22. package/lib/typescript/src/recorder/index.d.ts +3 -4
  23. package/lib/typescript/src/recorder/index.d.ts.map +1 -1
  24. package/lib/typescript/src/services/api.service.d.ts +10 -4
  25. package/lib/typescript/src/services/api.service.d.ts.map +1 -1
  26. package/lib/typescript/src/services/socket.service.d.ts +39 -0
  27. package/lib/typescript/src/services/socket.service.d.ts.map +1 -0
  28. package/lib/typescript/src/session-recorder.d.ts +17 -1
  29. package/lib/typescript/src/session-recorder.d.ts.map +1 -1
  30. package/lib/typescript/src/types/session-recorder.d.ts +12 -1
  31. package/lib/typescript/src/types/session-recorder.d.ts.map +1 -1
  32. package/lib/typescript/src/types/session.d.ts +1 -2
  33. package/lib/typescript/src/types/session.d.ts.map +1 -1
  34. package/package.json +2 -2
  35. package/src/config/constants.ts +6 -0
  36. package/src/config/defaults.ts +29 -27
  37. package/src/config/session-recorder.ts +2 -0
  38. package/src/recorder/index.ts +8 -21
  39. package/src/services/api.service.ts +15 -6
  40. package/src/services/socket.service.ts +225 -0
  41. package/src/session-recorder.ts +71 -11
  42. package/src/types/session-recorder.ts +14 -1
  43. package/src/types/session.ts +3 -2
  44. package/src/utils/logger.ts +1 -1
  45. package/lib/module/recorder/eventExporter.js +0 -130
  46. package/lib/module/recorder/eventExporter.js.map +0 -1
  47. package/lib/module/types/client-type.enum.js +0 -9
  48. package/lib/module/types/client-type.enum.js.map +0 -1
  49. package/lib/typescript/src/recorder/eventExporter.d.ts +0 -25
  50. package/lib/typescript/src/recorder/eventExporter.d.ts.map +0 -1
  51. package/lib/typescript/src/types/client-type.enum.d.ts +0 -6
  52. package/lib/typescript/src/types/client-type.enum.d.ts.map +0 -1
  53. package/src/recorder/eventExporter.ts +0 -150
  54. package/src/types/client-type.enum.ts +0 -5
@@ -1 +0,0 @@
1
- {"version":3,"file":"eventExporter.d.ts","sourceRoot":"","sources":["../../../../src/recorder/eventExporter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAazC,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,SAAS,CAAuB;IAExC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAS;gBAEX,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAK1D,OAAO,CAAC,IAAI;IA+CZ,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAIrC,OAAO,CAAC,yBAAyB;IAMjC,OAAO,CAAC,UAAU;IAWlB,OAAO,CAAC,sBAAsB;IASvB,IAAI,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAStB,kBAAkB,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI;IAgB3C,KAAK,IAAI,IAAI;CAYrB"}
@@ -1,6 +0,0 @@
1
- export declare enum UserType {
2
- USER = "USER",
3
- VISITOR = "VISITOR",
4
- API_CLIENT = "API_CLIENT"
5
- }
6
- //# sourceMappingURL=client-type.enum.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-type.enum.d.ts","sourceRoot":"","sources":["../../../../src/types/client-type.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAClB,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,UAAU,eAAe;CAC1B"}
@@ -1,150 +0,0 @@
1
- import io, { Socket } from 'socket.io-client';
2
-
3
- import { type ISession } from '../types';
4
- import { logger } from '../utils';
5
-
6
- import {
7
- SESSION_ADD_EVENT,
8
- SESSION_AUTO_CREATED,
9
- SESSION_STOPPED_EVENT,
10
- SESSION_SUBSCRIBE_EVENT,
11
- SESSION_UNSUBSCRIBE_EVENT,
12
- } from '../config';
13
-
14
- const MAX_RECONNECTION_ATTEMPTS = 2;
15
-
16
- export class EventExporter {
17
- private socket: Socket | null = null;
18
- private queue: any[] = [];
19
- private isConnecting: boolean = false;
20
- private isConnected: boolean = false;
21
- private attempts: number = 0;
22
- private sessionId: string | null = null;
23
-
24
- private socketUrl: string;
25
- private apiKey: string;
26
-
27
- constructor(options: { socketUrl: string; apiKey: string }) {
28
- this.socketUrl = options.socketUrl;
29
- this.apiKey = options.apiKey;
30
- }
31
-
32
- private init(): void {
33
- if (this.isConnecting || this.isConnected) return;
34
- this.attempts++;
35
- this.isConnecting = true;
36
- this.socket = io(this.socketUrl, {
37
- path: '/v0/radar/ws',
38
- auth: {
39
- 'x-api-key': this.apiKey,
40
- },
41
- reconnectionAttempts: 2,
42
- transports: ['websocket'],
43
- });
44
-
45
- // this.socket.on('connect', () => {
46
- // this.isConnecting = false
47
- // this.isConnected = true
48
- // this.usePostMessage = false
49
- // this.flushQueue()
50
- // })
51
-
52
- this.socket.on('ready', () => {
53
- this.isConnecting = false;
54
- this.isConnected = true;
55
- logger.info('EventExporter', 'Connected to server');
56
- this.flushQueue();
57
- });
58
-
59
- this.socket.on('disconnect', (_err: any) => {
60
- this.isConnecting = false;
61
- this.isConnected = false;
62
- logger.info('EventExporter', 'Disconnected from server');
63
- });
64
-
65
- this.socket.on('connect_error', (err: any) => {
66
- this.isConnecting = false;
67
- this.isConnected = false;
68
- this.checkReconnectionAttempts();
69
- logger.error('EventExporter', 'Error connecting to server', err);
70
- });
71
-
72
- this.socket.on(SESSION_STOPPED_EVENT, (_: any) => {
73
- this.unsubscribeFromSession();
74
- });
75
-
76
- this.socket.on(SESSION_AUTO_CREATED, (_: any) => {});
77
- }
78
-
79
- setApiKey(apiKey: string): void {
80
- this.apiKey = apiKey;
81
- }
82
-
83
- setSocketUrl(socketUrl: string): void {
84
- this.socketUrl = socketUrl;
85
- }
86
-
87
- private checkReconnectionAttempts(): void {
88
- if (this.attempts >= MAX_RECONNECTION_ATTEMPTS) {
89
- this.flushQueue();
90
- }
91
- }
92
-
93
- private flushQueue(): void {
94
- while (this.queue.length > 0 && this.socket?.connected) {
95
- const event = this.queue.shift();
96
- if (!event) continue;
97
-
98
- if (this.socket?.connected) {
99
- this.socket.emit(event.name, event.data);
100
- }
101
- }
102
- }
103
-
104
- private unsubscribeFromSession() {
105
- const payload = {
106
- debugSessionId: this.sessionId,
107
- };
108
- if (this.socket?.connected) {
109
- this.socket.emit(SESSION_UNSUBSCRIBE_EVENT, payload);
110
- }
111
- }
112
-
113
- public send(event: any): void {
114
- if (this.socket?.connected) {
115
- this.socket.emit(SESSION_ADD_EVENT, event);
116
- } else {
117
- this.queue.push({ data: event, name: SESSION_ADD_EVENT });
118
- this.init();
119
- }
120
- }
121
-
122
- public subscribeToSession(session: ISession): void {
123
- this.sessionId = session.shortId || session._id;
124
- const payload = {
125
- projectId: session.project,
126
- workspaceId: session.workspace,
127
- debugSessionId: this.sessionId,
128
- sessionType: session.creationType,
129
- };
130
- if (this.socket?.connected) {
131
- this.socket.emit(SESSION_SUBSCRIBE_EVENT, payload);
132
- } else {
133
- this.queue.push({ data: payload, name: SESSION_SUBSCRIBE_EVENT });
134
- this.init();
135
- }
136
- }
137
-
138
- public close(): void {
139
- if (this.socket?.connected) {
140
- setTimeout(() => {
141
- this.unsubscribeFromSession();
142
- this.attempts = 0;
143
- this.isConnected = false;
144
- this.isConnecting = false;
145
- this.socket?.disconnect();
146
- this.socket = null;
147
- }, 500);
148
- }
149
- }
150
- }
@@ -1,5 +0,0 @@
1
- export enum UserType {
2
- USER = 'USER',
3
- VISITOR = 'VISITOR',
4
- API_CLIENT = 'API_CLIENT',
5
- }