@reactoo/watchtogether-sdk-js 2.7.7 → 2.7.8
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/watchtogether-sdk.js +5 -5
- package/dist/watchtogether-sdk.min.js +2 -2
- package/package.json +1 -1
- package/src/models/asset.js +24 -12
- package/src/models/user.js +21 -9
- package/src/modules/wt-utils.js +9 -1
package/package.json
CHANGED
package/src/models/asset.js
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
import {generateUUID} from "../modules/wt-utils";
|
|
3
|
+
import {generateUUID, chunkArray} from "../modules/wt-utils";
|
|
4
4
|
|
|
5
5
|
let asset = function() {
|
|
6
6
|
return {
|
|
7
7
|
getAssetList: ({type = 'instanceType', instanceType, assetType, size = 20, startKey = null, roomId, ids}) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
return chunkArray(ids, 50)
|
|
9
|
+
.reduce((promiseChain, idsChunk) => {
|
|
10
|
+
return promiseChain.then(chainResponse => {
|
|
11
|
+
let apiParams = {
|
|
12
|
+
type,
|
|
13
|
+
...(instanceType && {instanceType: instanceType === true ? this.__instanceType : instanceType }),
|
|
14
|
+
...(assetType && {assetType}),
|
|
15
|
+
...(size && !ids && {size}),
|
|
16
|
+
...(idsChunk?.length && {ids: idsChunk.join(',')}),
|
|
17
|
+
...(roomId && {roomId}),
|
|
18
|
+
...(startKey && {startKey})
|
|
19
|
+
};
|
|
20
|
+
return this.__privates.auth.__client
|
|
21
|
+
.then(client => client.apis.asset.getAssetList(apiParams))
|
|
22
|
+
.then(response => type === 'ids' ? {
|
|
23
|
+
data: {
|
|
24
|
+
items: [...chainResponse.data.items, ...response.data.items],
|
|
25
|
+
size: chainResponse.data.size + response.data.size,
|
|
26
|
+
startKey: null,
|
|
27
|
+
},
|
|
28
|
+
} : response);
|
|
29
|
+
});
|
|
30
|
+
}, Promise.resolve({data: {items: [], size: 0, startKey: null}}));
|
|
19
31
|
},
|
|
20
32
|
getAssetById: (id) => {
|
|
21
33
|
return this.__privates.auth.__client
|
package/src/models/user.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
import {generateUUID} from "../modules/wt-utils";
|
|
3
|
+
import {generateUUID, chunkArray} from "../modules/wt-utils";
|
|
4
4
|
import {serializeError} from "serialize-error";
|
|
5
5
|
|
|
6
6
|
let user = function () {
|
|
@@ -95,14 +95,26 @@ let user = function () {
|
|
|
95
95
|
.then(client => client.apis.user.getUserById({id}))
|
|
96
96
|
},
|
|
97
97
|
getUsersByIds: ({ids = [], size = null, startKey = null } = {}) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
98
|
+
return chunkArray(ids, 50)
|
|
99
|
+
.reduce((promiseChain, idsChunk) => {
|
|
100
|
+
return promiseChain.then(chainResponse => {
|
|
101
|
+
let apiParams = {
|
|
102
|
+
type : 'ids',
|
|
103
|
+
...(size && {size}),
|
|
104
|
+
...(idsChunk?.length && {ids: idsChunk.join(',')}),
|
|
105
|
+
...(startKey && {startKey})
|
|
106
|
+
};
|
|
107
|
+
return this.__privates.auth.__client
|
|
108
|
+
.then(client => client.apis.user.getUsers(apiParams))
|
|
109
|
+
.then(response => ({
|
|
110
|
+
data: {
|
|
111
|
+
items: [...chainResponse.data.items, ...response.data.items],
|
|
112
|
+
size: chainResponse.data.size + response.data.size,
|
|
113
|
+
startKey: null,
|
|
114
|
+
},
|
|
115
|
+
}));
|
|
116
|
+
});
|
|
117
|
+
}, Promise.resolve({data: {items: [], size: 0, startKey: null}}));
|
|
106
118
|
},
|
|
107
119
|
getUsers: ({type, userId, roomId, size = 20, startKey = null} = {}) => {
|
|
108
120
|
let apiParams = {
|
package/src/modules/wt-utils.js
CHANGED
|
@@ -128,6 +128,14 @@ const maxJitter = (x) => {
|
|
|
128
128
|
return a / (1 + Math.exp(-b * (x - c))) + d; // Fixed the typo here
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
const chunkArray = (array, chunkSize) => {
|
|
132
|
+
if (!array?.length) return [[]];
|
|
131
133
|
|
|
134
|
+
let results = [];
|
|
135
|
+
while (array.length) {
|
|
136
|
+
results.push(array.splice(0, chunkSize));
|
|
137
|
+
}
|
|
138
|
+
return results;
|
|
139
|
+
}
|
|
132
140
|
|
|
133
|
-
export {wait, getBrowserFingerprint, generateUUID, decodeJanusDisplay, setExactTimeout, clearExactTimeout, median, maxJitter}
|
|
141
|
+
export {wait, getBrowserFingerprint, generateUUID, decodeJanusDisplay, setExactTimeout, clearExactTimeout, median, maxJitter, chunkArray}
|