@amityco/ts-sdk-react-native 6.35.3-ab24b11.0 → 6.35.3-e008e09.0
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.
- package/dist/@types/core/transport.d.ts +0 -2
- package/dist/@types/core/transport.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +0 -9
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +0 -1
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/core/transports/mqtt.d.ts.map +1 -1
- package/dist/index.cjs.js +0 -57
- package/dist/index.esm.js +0 -57
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
- package/src/@types/core/transport.ts +0 -2
- package/src/@types/domains/client.ts +0 -14
- package/src/client/api/createClient.ts +0 -3
- package/src/client/api/index.ts +0 -2
- package/src/core/transports/mqtt.ts +1 -40
- package/dist/client/api/onRTEConnectionStateChange.d.ts +0 -13
- package/dist/client/api/onRTEConnectionStateChange.d.ts.map +0 -1
- package/src/client/api/onRTEConnectionStateChange.ts +0 -24
package/package.json
CHANGED
|
@@ -34,8 +34,6 @@ declare global {
|
|
|
34
34
|
type MqttClient = {
|
|
35
35
|
connect: (params: { accessToken: string; userId: string }) => Promise<void>;
|
|
36
36
|
disconnect: () => Promise<void>;
|
|
37
|
-
reconnect: () => void;
|
|
38
|
-
listen(callback: (state: Amity.RTEConnectionState) => void): () => void;
|
|
39
37
|
get connected(): boolean;
|
|
40
38
|
on: <T extends keyof Amity.MqttEvents>(
|
|
41
39
|
event: T,
|
|
@@ -31,16 +31,6 @@ declare global {
|
|
|
31
31
|
TERMINATED = 'terminated',
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
enum RTEConnectionStateEnum {
|
|
35
|
-
CONNECTING = 'connecting', // actively establishing a connection (initial or reconnection)
|
|
36
|
-
CONNECTED = 'connected', // connected to broker
|
|
37
|
-
RECONNECTING = 'reconnecting', // lost connection and attempting to reconnect
|
|
38
|
-
DISCONNECTED = 'disconnected', // disconnected (not currently connected, and not automatically reconnecting)
|
|
39
|
-
DISCONNECTING = 'disconnecting', // disconnected (not currently connected, and not automatically reconnecting)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
type RTEConnectionState = `${Amity.RTEConnectionStateEnum}`;
|
|
43
|
-
|
|
44
34
|
type Client = {
|
|
45
35
|
version: string;
|
|
46
36
|
|
|
@@ -70,10 +60,6 @@ declare global {
|
|
|
70
60
|
|
|
71
61
|
accessTokenExpiryWatcher: (sessionHandler: Amity.SessionHandler) => Amity.Unsubscriber;
|
|
72
62
|
|
|
73
|
-
onRTEConnectionStateChange: (
|
|
74
|
-
callback: (state: Amity.RTEConnectionState) => void,
|
|
75
|
-
) => (() => void) | undefined;
|
|
76
|
-
|
|
77
63
|
getFeedSettings: () => Promise<Amity.FeedSettings>;
|
|
78
64
|
getSocialSettings: () => Promise<Amity.SocialSettings>;
|
|
79
65
|
getMessagePreviewSetting: (refresh?: boolean) => Promise<Amity.MessagePreviewSetting>;
|
|
@@ -21,7 +21,6 @@ import { getFeedSettings } from './getFeedSettings';
|
|
|
21
21
|
|
|
22
22
|
import { accessTokenExpiryWatcher } from './accessTokenExpiryWatcher';
|
|
23
23
|
import { getMarkerSyncConsistentMode } from '../utils/markerSyncEngine';
|
|
24
|
-
import { onRTEConnectionStateChange } from './onRTEConnectionStateChange';
|
|
25
24
|
|
|
26
25
|
const DEFAULT_DEBUG_SESSION = 'amity';
|
|
27
26
|
|
|
@@ -122,8 +121,6 @@ export const createClient = (
|
|
|
122
121
|
getSocialSettings,
|
|
123
122
|
getMessagePreviewSetting,
|
|
124
123
|
|
|
125
|
-
onRTEConnectionStateChange,
|
|
126
|
-
|
|
127
124
|
use: () => setActiveClient(client),
|
|
128
125
|
|
|
129
126
|
isUnreadCountEnabled,
|
package/src/client/api/index.ts
CHANGED
|
@@ -50,25 +50,11 @@ export function getMqttOptions(params: {
|
|
|
50
50
|
*/
|
|
51
51
|
export const createMqttTransport = (endpoint: string): Amity.MqttClient => {
|
|
52
52
|
let mqttClient: MqttClient;
|
|
53
|
-
let currentState: Amity.RTEConnectionState = 'disconnected';
|
|
54
|
-
const connectionStateListeners: Set<(state: Amity.RTEConnectionState) => void> = new Set();
|
|
55
|
-
|
|
56
|
-
const updateConnectionState = (state: Amity.RTEConnectionState) => {
|
|
57
|
-
if (currentState === state) return;
|
|
58
|
-
|
|
59
|
-
currentState = state;
|
|
60
|
-
|
|
61
|
-
connectionStateListeners.forEach(listener => {
|
|
62
|
-
listener(state);
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
53
|
|
|
66
54
|
async function connect(params: { accessToken: string; userId: string }): Promise<void> {
|
|
67
55
|
const clientId = await getMQTTClientId(params.userId);
|
|
68
|
-
updateConnectionState('connecting');
|
|
69
56
|
|
|
70
57
|
if (mqttClient) {
|
|
71
|
-
updateConnectionState('disconnecting');
|
|
72
58
|
mqttClient.removeAllListeners();
|
|
73
59
|
mqttClient.end(true);
|
|
74
60
|
}
|
|
@@ -84,7 +70,7 @@ export const createMqttTransport = (endpoint: string): Amity.MqttClient => {
|
|
|
84
70
|
|
|
85
71
|
mqttClient.on('connect', () => {
|
|
86
72
|
mqttClient.options.reconnectPeriod = RETRY_BASE_TIMEOUT;
|
|
87
|
-
|
|
73
|
+
|
|
88
74
|
subscribeGlobalTopic();
|
|
89
75
|
});
|
|
90
76
|
|
|
@@ -95,12 +81,10 @@ export const createMqttTransport = (endpoint: string): Amity.MqttClient => {
|
|
|
95
81
|
case MqttError.BAD_USERNAME_OR_PASSWORD:
|
|
96
82
|
case MqttError.NOT_AUTHORIZED:
|
|
97
83
|
mqttClient.end();
|
|
98
|
-
updateConnectionState('disconnected');
|
|
99
84
|
}
|
|
100
85
|
});
|
|
101
86
|
|
|
102
87
|
mqttClient.on('reconnect', () => {
|
|
103
|
-
updateConnectionState('reconnecting');
|
|
104
88
|
// Double the reconnect period for each attempt
|
|
105
89
|
mqttClient.options.reconnectPeriod = Math.min(
|
|
106
90
|
(mqttClient.options.reconnectPeriod || RETRY_BASE_TIMEOUT) * 2,
|
|
@@ -108,14 +92,6 @@ export const createMqttTransport = (endpoint: string): Amity.MqttClient => {
|
|
|
108
92
|
);
|
|
109
93
|
});
|
|
110
94
|
|
|
111
|
-
mqttClient.on('close', () => {
|
|
112
|
-
updateConnectionState('disconnected');
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
mqttClient.on('disconnect', () => {
|
|
116
|
-
updateConnectionState('disconnected');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
95
|
return new Promise(resolve => mqttClient!.once('connect', () => resolve()));
|
|
120
96
|
}
|
|
121
97
|
|
|
@@ -126,21 +102,6 @@ export const createMqttTransport = (endpoint: string): Amity.MqttClient => {
|
|
|
126
102
|
return new Promise(resolve => mqttClient?.end(true, undefined, () => resolve()));
|
|
127
103
|
}
|
|
128
104
|
},
|
|
129
|
-
async reconnect(): Promise<void> {
|
|
130
|
-
return new Promise(resolve => {
|
|
131
|
-
mqttClient?.reconnect();
|
|
132
|
-
resolve();
|
|
133
|
-
});
|
|
134
|
-
},
|
|
135
|
-
listen(callback: (state: Amity.RTEConnectionState) => void): () => void {
|
|
136
|
-
connectionStateListeners.add(callback);
|
|
137
|
-
|
|
138
|
-
if (currentState) callback(currentState);
|
|
139
|
-
|
|
140
|
-
return () => {
|
|
141
|
-
connectionStateListeners.delete(callback);
|
|
142
|
-
};
|
|
143
|
-
},
|
|
144
105
|
get connected() {
|
|
145
106
|
return !!mqttClient?.connected;
|
|
146
107
|
},
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ```js
|
|
3
|
-
* import { Client } from '@amityco/ts-sdk'
|
|
4
|
-
* const unsubscribe = Client.onRTEConnectionStateChange((state) => console.log(state))
|
|
5
|
-
* unsubscribe()
|
|
6
|
-
* ```
|
|
7
|
-
* @param callback The function to call when the event was fired
|
|
8
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
9
|
-
*
|
|
10
|
-
* @category Client API
|
|
11
|
-
*/
|
|
12
|
-
export declare const onRTEConnectionStateChange: (callback: (state: Amity.RTEConnectionState) => void) => (() => void) | undefined;
|
|
13
|
-
//# sourceMappingURL=onRTEConnectionStateChange.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onRTEConnectionStateChange.d.ts","sourceRoot":"","sources":["../../../src/client/api/onRTEConnectionStateChange.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,qBACnB,MAAM,kBAAkB,KAAK,IAAI,KAClD,CAAC,MAAM,IAAI,CAAC,GAAG,SAQjB,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { getActiveClient } from './activeClient';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ```js
|
|
5
|
-
* import { Client } from '@amityco/ts-sdk'
|
|
6
|
-
* const unsubscribe = Client.onRTEConnectionStateChange((state) => console.log(state))
|
|
7
|
-
* unsubscribe()
|
|
8
|
-
* ```
|
|
9
|
-
* @param callback The function to call when the event was fired
|
|
10
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11
|
-
*
|
|
12
|
-
* @category Client API
|
|
13
|
-
*/
|
|
14
|
-
export const onRTEConnectionStateChange = (
|
|
15
|
-
callback: (state: Amity.RTEConnectionState) => void,
|
|
16
|
-
): (() => void) | undefined => {
|
|
17
|
-
const client = getActiveClient();
|
|
18
|
-
|
|
19
|
-
if (client.mqtt) {
|
|
20
|
-
return client.mqtt?.listen(callback);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return undefined;
|
|
24
|
-
};
|