@amityco/ts-sdk-react-native 6.31.1-7ca0115.0 → 6.31.1
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/.env +26 -26
- package/dist/@types/domains/client.d.ts +1 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/stream.d.ts +4 -0
- package/dist/@types/domains/stream.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts +2 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/core/device.d.ts.map +1 -1
- package/dist/index.cjs.js +30 -6
- package/dist/index.esm.js +30 -6
- package/dist/index.umd.js +3 -3
- package/dist/utils/linkedObject/streamLinkedObject.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/domains/client.ts +2 -0
- package/src/@types/domains/stream.ts +12 -0
- package/src/client/api/createClient.ts +8 -0
- package/src/core/device.ts +6 -2
- package/src/utils/linkedObject/streamLinkedObject.ts +11 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/streamLinkedObject.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,WAAY,MAAM,cAAc,KAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"streamLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/streamLinkedObject.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,WAAY,MAAM,cAAc,KAAG,MAAM,MAmBvE,CAAC"}
|
package/package.json
CHANGED
|
@@ -61,6 +61,18 @@ declare global {
|
|
|
61
61
|
streamerUrl: StreamEndpoint;
|
|
62
62
|
watcherUrl: MultiFormat<StreamEndpoint>;
|
|
63
63
|
recordings: MultiFormat<StreamRecording>[];
|
|
64
|
+
|
|
65
|
+
/*
|
|
66
|
+
* If the stream is create and use to create a post,
|
|
67
|
+
* the referenceType should be 'post' and referenceId should be the postId.
|
|
68
|
+
*/
|
|
69
|
+
referenceId?: string; // 'post', etc..
|
|
70
|
+
referenceType?: string;
|
|
71
|
+
/*
|
|
72
|
+
* Target is the livestream post's target when create a post.
|
|
73
|
+
*/
|
|
74
|
+
targetId?: string; // communityId, userId, etc..
|
|
75
|
+
targetType?: string; // 'community', 'user', etc..
|
|
64
76
|
} & Amity.Metadata &
|
|
65
77
|
Amity.Timestamps &
|
|
66
78
|
Amity.SoftDelete;
|
|
@@ -46,9 +46,11 @@ export const createClient = (
|
|
|
46
46
|
{
|
|
47
47
|
debugSession = DEFAULT_DEBUG_SESSION,
|
|
48
48
|
apiEndpoint,
|
|
49
|
+
prefixDeviceIdKey,
|
|
49
50
|
}: {
|
|
50
51
|
debugSession?: string;
|
|
51
52
|
apiEndpoint?: { http?: string; mqtt?: string };
|
|
53
|
+
prefixDeviceIdKey?: string;
|
|
52
54
|
} = {},
|
|
53
55
|
): Amity.Client => {
|
|
54
56
|
const log = createLogger(debugSession);
|
|
@@ -117,6 +119,12 @@ export const createClient = (
|
|
|
117
119
|
|
|
118
120
|
getMarkerSyncConsistentMode,
|
|
119
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Prefix for the deviceId key in the local storage or async storage.
|
|
124
|
+
* This is allow user to have multiple SDK client and Mqtt client within the same app.
|
|
125
|
+
*/
|
|
126
|
+
prefixDeviceIdKey,
|
|
127
|
+
|
|
120
128
|
/*
|
|
121
129
|
* The objectSyncMap is used to keep the map between local referenceId and server id in two ways mapping.
|
|
122
130
|
*
|
package/src/core/device.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { safeProcess } from '~/utils/env';
|
|
|
4
4
|
import { VERSION } from '~/version';
|
|
5
5
|
import * as localStorage from '../client/utils/localStorage';
|
|
6
6
|
import { uuid } from './uuid';
|
|
7
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
7
8
|
|
|
8
9
|
type CrossTabResponse = {
|
|
9
10
|
tabId: string;
|
|
@@ -60,11 +61,14 @@ export const getDeviceId = async () => {
|
|
|
60
61
|
// https://www.npmjs.com/package/react-native-device-info#getuniqueid
|
|
61
62
|
// how to make sure that the React native package will not be included when build is for web
|
|
62
63
|
|
|
63
|
-
const
|
|
64
|
+
const client = getActiveClient();
|
|
65
|
+
const key = `${client.prefixDeviceIdKey ?? ''}#deviceId`;
|
|
66
|
+
|
|
67
|
+
const savedDeviceId = await localStorage.getItem(key);
|
|
64
68
|
if (savedDeviceId) return savedDeviceId;
|
|
65
69
|
|
|
66
70
|
const deviceId = `ascWebSdk#${uuid()}`;
|
|
67
|
-
await localStorage.setItem(
|
|
71
|
+
await localStorage.setItem(key, deviceId);
|
|
68
72
|
return deviceId;
|
|
69
73
|
};
|
|
70
74
|
|
|
@@ -7,5 +7,16 @@ export const streamLinkedObject = (stream: Amity.InternalStream): Amity.Stream =
|
|
|
7
7
|
return pullFromCache<Amity.StreamModeration>(['streamModeration', 'get', stream.streamId])
|
|
8
8
|
?.data;
|
|
9
9
|
},
|
|
10
|
+
get post() {
|
|
11
|
+
if (stream.referenceType !== 'post') return;
|
|
12
|
+
return pullFromCache<Amity.Post>(['post', 'get', stream.referenceId])?.data;
|
|
13
|
+
},
|
|
14
|
+
get community() {
|
|
15
|
+
if (stream.targetType !== 'community') return;
|
|
16
|
+
return pullFromCache<Amity.Community>(['community', 'get', stream.targetId])?.data;
|
|
17
|
+
},
|
|
18
|
+
get user() {
|
|
19
|
+
return pullFromCache<Amity.User>(['user', 'get', stream.userId])?.data;
|
|
20
|
+
},
|
|
10
21
|
};
|
|
11
22
|
};
|