@rtsdk/topia 0.0.10 → 0.0.12
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/README.md +19 -0
- package/dist/controllers/Asset.js +19 -8
- package/dist/controllers/DroppedAsset.js +217 -33
- package/dist/controllers/SDKController.js +36 -0
- package/dist/controllers/Topia.js +32 -0
- package/dist/controllers/User.js +56 -13
- package/dist/controllers/Visitor.js +36 -12
- package/dist/controllers/World.js +172 -30
- package/dist/controllers/__tests__/asset.test.js +24 -10
- package/dist/controllers/__tests__/droppedAsset.test.js +18 -13
- package/dist/controllers/__tests__/user.test.js +33 -6
- package/dist/controllers/__tests__/visitor.test.js +27 -10
- package/dist/controllers/__tests__/world.test.js +26 -24
- package/dist/controllers/index.js +2 -0
- package/dist/example.js +32 -0
- package/dist/factories/AssetFactory.js +11 -0
- package/dist/factories/DroppedAssetFactory.js +26 -0
- package/dist/factories/UserFactory.js +10 -0
- package/dist/factories/VisitorFactory.js +10 -0
- package/dist/factories/WorldFactory.js +10 -0
- package/dist/factories/index.js +5 -0
- package/dist/index.js +13 -18283
- package/dist/interfaces/SDKInterfaces.js +1 -0
- package/dist/interfaces/TopiaInterfaces.js +1 -0
- package/dist/interfaces/UserInterfaces.js +1 -0
- package/dist/interfaces/index.js +3 -0
- package/dist/src/__mocks__/assets.js +241 -0
- package/dist/src/__mocks__/index.js +4 -0
- package/dist/src/__mocks__/scenes.js +104 -0
- package/dist/src/__mocks__/visitors.js +83 -0
- package/dist/src/__mocks__/worlds.js +52 -0
- package/dist/src/controllers/Asset.js +39 -0
- package/dist/src/controllers/DroppedAsset.js +358 -0
- package/dist/src/controllers/SDKController.js +43 -0
- package/dist/src/controllers/Topia.js +35 -0
- package/dist/src/controllers/User.js +113 -0
- package/dist/src/controllers/Visitor.js +62 -0
- package/dist/src/controllers/World.js +319 -0
- package/dist/src/controllers/__tests__/asset.test.js +36 -0
- package/dist/src/controllers/__tests__/droppedAsset.test.js +97 -0
- package/dist/src/controllers/__tests__/user.test.js +49 -0
- package/dist/src/controllers/__tests__/visitor.test.js +40 -0
- package/dist/src/controllers/__tests__/world.test.js +80 -0
- package/dist/src/controllers/index.js +7 -0
- package/dist/src/factories/AssetFactory.js +11 -0
- package/dist/src/factories/DroppedAssetFactory.js +26 -0
- package/dist/src/factories/UserFactory.js +10 -0
- package/dist/src/factories/VisitorFactory.js +10 -0
- package/dist/src/factories/WorldFactory.js +10 -0
- package/dist/src/factories/index.js +5 -0
- package/dist/src/index.js +2 -0
- package/dist/src/interfaces/AssetInterfaces.js +1 -0
- package/dist/src/interfaces/DroppedAssetInterfaces.js +1 -0
- package/dist/src/interfaces/SDKInterfaces.js +1 -0
- package/dist/src/interfaces/TopiaInterfaces.js +1 -0
- package/dist/src/interfaces/UserInterfaces.js +1 -0
- package/dist/src/interfaces/VisitorInterfaces.js +1 -0
- package/dist/src/interfaces/WorldInterfaces.js +1 -0
- package/dist/src/interfaces/index.js +7 -0
- package/dist/src/types/DroppedAssetTypes.js +12 -0
- package/dist/src/types/InteractiveCredentialsTypes.js +1 -0
- package/dist/src/types/OptionsTypes.js +1 -0
- package/dist/src/types/ResponseTypes.js +1 -0
- package/dist/src/types/VisitorTypes.js +1 -0
- package/dist/src/types/index.js +4 -0
- package/dist/src/utils/__tests__/removeUndefined.test.js +10 -0
- package/dist/src/utils/__tests__/scatterVisitors.test.js +11 -0
- package/dist/src/utils/getBrowserWarning.js +5 -0
- package/dist/src/utils/getErrorMessage.js +5 -0
- package/dist/src/utils/getErrorResponse.js +20 -0
- package/dist/src/utils/getSuccessResponse.js +3 -0
- package/dist/src/utils/index.js +4 -0
- package/dist/src/utils/removeUndefined.js +11 -0
- package/dist/src/utils/scatterVisitors.js +8 -0
- package/dist/types/InteractiveCredentialsTypes.js +1 -0
- package/dist/types/OptionsTypes.js +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/getErrorMessage.js +3 -1
- package/dist/utils/publicAPI.js +3 -0
- package/dist/utils/removeUndefined.js +3 -0
- package/dist/utils/scatterVisitors.js +3 -0
- package/package.json +5 -1
- package/dist/utils/createDroppedAsset.js +0 -72
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
11
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
13
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
14
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
15
|
+
};
|
|
16
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
17
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
18
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
19
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
|
+
};
|
|
21
|
+
var _World_droppedAssetsMap, _World_visitorsMap;
|
|
22
|
+
// controllers
|
|
23
|
+
import { DroppedAsset } from "controllers/DroppedAsset";
|
|
24
|
+
import { SDKController } from "controllers/SDKController";
|
|
25
|
+
import { Visitor } from "controllers/Visitor";
|
|
26
|
+
// utils
|
|
27
|
+
import { getErrorResponse, removeUndefined, scatterVisitors } from "utils";
|
|
28
|
+
/**
|
|
29
|
+
* Create an instance of World class with a given url slug and optional attributes and session credentials.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* await new World(topia, "exampleWorld", { attributes: { name: "Example World" } });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export class World extends SDKController {
|
|
36
|
+
constructor(topia, urlSlug, options = { attributes: {}, credentials: {} }) {
|
|
37
|
+
super(topia, options.credentials);
|
|
38
|
+
_World_droppedAssetsMap.set(this, void 0);
|
|
39
|
+
_World_visitorsMap.set(this, void 0);
|
|
40
|
+
Object.assign(this, options.attributes);
|
|
41
|
+
__classPrivateFieldSet(this, _World_droppedAssetsMap, {}, "f");
|
|
42
|
+
__classPrivateFieldSet(this, _World_visitorsMap, {}, "f");
|
|
43
|
+
this.urlSlug = urlSlug;
|
|
44
|
+
}
|
|
45
|
+
get droppedAssets() {
|
|
46
|
+
return __classPrivateFieldGet(this, _World_droppedAssetsMap, "f");
|
|
47
|
+
}
|
|
48
|
+
get visitors() {
|
|
49
|
+
return __classPrivateFieldGet(this, _World_visitorsMap, "f");
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @summary
|
|
53
|
+
* Retrieves details of a world.
|
|
54
|
+
*
|
|
55
|
+
* @usage
|
|
56
|
+
* ```ts
|
|
57
|
+
* await world.fetchDetails();
|
|
58
|
+
* const { name } = world;
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
// world details
|
|
62
|
+
fetchDetails() {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
try {
|
|
65
|
+
const response = yield this.topia.axios.get(`/world/${this.urlSlug}/world-details`, this.requestOptions);
|
|
66
|
+
Object.assign(this, response.data);
|
|
67
|
+
console.log("🚀 ~ file: World.ts:64 ~ World ~ fetchDetails ~ response.data", response.data);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.log("🚀 ~ file: World.ts:65 ~ World ~ fetchDetails ~ error", error);
|
|
71
|
+
throw getErrorResponse({ error });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @summary
|
|
77
|
+
* Update details of a world.
|
|
78
|
+
*
|
|
79
|
+
* @usage
|
|
80
|
+
* ```ts
|
|
81
|
+
* await world.updateDetails({
|
|
82
|
+
* controls: {
|
|
83
|
+
* allowMuteAll: true,
|
|
84
|
+
* disableHideVideo: true,
|
|
85
|
+
* isMobileDisabled: false,
|
|
86
|
+
* isShowingCurrentGuests: false,
|
|
87
|
+
* },
|
|
88
|
+
* description: 'Welcome to my world.',
|
|
89
|
+
* forceAuthOnLogin: false,
|
|
90
|
+
* height: 2000,
|
|
91
|
+
* name: 'Example',
|
|
92
|
+
* spawnPosition: { x: 100, y: 100 },
|
|
93
|
+
* width: 2000
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
updateDetails({ controls, description, forceAuthOnLogin, height, name, spawnPosition, width, }) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const payload = {
|
|
100
|
+
controls,
|
|
101
|
+
description,
|
|
102
|
+
forceAuthOnLogin,
|
|
103
|
+
height,
|
|
104
|
+
name,
|
|
105
|
+
spawnPosition,
|
|
106
|
+
width,
|
|
107
|
+
};
|
|
108
|
+
try {
|
|
109
|
+
yield this.topia.axios.put(`/world/${this.urlSlug}/world-details`, payload, this.requestOptions);
|
|
110
|
+
const cleanPayload = removeUndefined(payload);
|
|
111
|
+
Object.assign(this, cleanPayload);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
throw getErrorResponse({ error });
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// visitors
|
|
119
|
+
fetchVisitors() {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
try {
|
|
122
|
+
const response = yield this.topia.axios.get(`/world/${this.urlSlug}/visitors`, this.requestOptions);
|
|
123
|
+
// create temp map and then update private property only once
|
|
124
|
+
const tempVisitorsMap = {};
|
|
125
|
+
for (const id in response.data) {
|
|
126
|
+
tempVisitorsMap[id] = new Visitor(this.topia, response.data[id].playerId, this.urlSlug, {
|
|
127
|
+
attributes: response.data[id],
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
__classPrivateFieldSet(this, _World_visitorsMap, tempVisitorsMap, "f");
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
throw getErrorResponse({ error });
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @summary
|
|
139
|
+
* Retrieve all visitors currently in a world.
|
|
140
|
+
*
|
|
141
|
+
* @usage
|
|
142
|
+
* ```ts
|
|
143
|
+
* const visitors = await world.currentVisitors();
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
currentVisitors() {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
try {
|
|
149
|
+
yield this.fetchVisitors();
|
|
150
|
+
return this.visitors;
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
return error;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* @summary
|
|
159
|
+
* Move all visitors currently in a world to a single set of coordinates.
|
|
160
|
+
* Optionally refetch visitors, teleport or walk visitors to new location,
|
|
161
|
+
* and scatter visitors by any number so that they don't all move to the exact same location.
|
|
162
|
+
*
|
|
163
|
+
* @usage
|
|
164
|
+
* ```ts
|
|
165
|
+
* await world.moveAllVisitors({
|
|
166
|
+
* shouldFetchVisitors: true,
|
|
167
|
+
* shouldTeleportVisitors: true,
|
|
168
|
+
* scatterVisitorsBy: 40,
|
|
169
|
+
* x: 100,
|
|
170
|
+
* y: 100,
|
|
171
|
+
* });
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* @result
|
|
175
|
+
* Updates each Visitor instance and world.visitors map.
|
|
176
|
+
*/
|
|
177
|
+
moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
if (shouldFetchVisitors)
|
|
180
|
+
yield this.fetchVisitors();
|
|
181
|
+
const allPromises = [];
|
|
182
|
+
if (!this.visitors)
|
|
183
|
+
return;
|
|
184
|
+
const objectKeys = Object.keys(this.visitors);
|
|
185
|
+
objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _World_visitorsMap, "f")[key].moveVisitor({
|
|
186
|
+
shouldTeleportVisitor: shouldTeleportVisitors,
|
|
187
|
+
x: scatterVisitors(x, scatterVisitorsBy),
|
|
188
|
+
y: scatterVisitors(y, scatterVisitorsBy),
|
|
189
|
+
})));
|
|
190
|
+
const outcomes = yield Promise.allSettled(allPromises);
|
|
191
|
+
return outcomes;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* @summary
|
|
196
|
+
* Teleport or walk a list of visitors currently in a world to various coordinates.
|
|
197
|
+
*
|
|
198
|
+
* @usage
|
|
199
|
+
* ```ts
|
|
200
|
+
* const visitorsToMove = [
|
|
201
|
+
* {
|
|
202
|
+
* visitorObj: world.visitors["1"],
|
|
203
|
+
* shouldTeleportVisitor: true,
|
|
204
|
+
* x: 100,
|
|
205
|
+
* y: 100
|
|
206
|
+
* }, {
|
|
207
|
+
* visitorObj: world.visitors["2"],
|
|
208
|
+
* shouldTeleportVisitor: false,
|
|
209
|
+
* x: 100,
|
|
210
|
+
* y: 100
|
|
211
|
+
* }
|
|
212
|
+
* ];
|
|
213
|
+
* await world.moveVisitors(visitorsToMove);
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* @result
|
|
217
|
+
* Updates each Visitor instance and world.visitors map.
|
|
218
|
+
*/
|
|
219
|
+
moveVisitors(visitorsToMove) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
const allPromises = [];
|
|
222
|
+
visitorsToMove.forEach((v) => {
|
|
223
|
+
allPromises.push(v.visitorObj.moveVisitor({ shouldTeleportVisitor: v.shouldTeleportVisitor, x: v.x, y: v.y }));
|
|
224
|
+
});
|
|
225
|
+
const outcomes = yield Promise.allSettled(allPromises);
|
|
226
|
+
return outcomes;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* @summary
|
|
231
|
+
* Retrieve all assets dropped in a world.
|
|
232
|
+
*
|
|
233
|
+
* @usage
|
|
234
|
+
* ```ts
|
|
235
|
+
* await world.fetchDroppedAssets();
|
|
236
|
+
* const assets = world.droppedAssets;
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
// dropped assets
|
|
240
|
+
fetchDroppedAssets() {
|
|
241
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
try {
|
|
243
|
+
const response = yield this.topia.axios.get(`/world/${this.urlSlug}/assets`, this.requestOptions);
|
|
244
|
+
// create temp map and then update private property only once
|
|
245
|
+
const tempDroppedAssetsMap = {};
|
|
246
|
+
for (const index in response.data) {
|
|
247
|
+
// tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
|
|
248
|
+
tempDroppedAssetsMap[index] = new DroppedAsset(this.topia, response.data[index].id, this.urlSlug, {
|
|
249
|
+
attributes: response.data[index],
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
__classPrivateFieldSet(this, _World_droppedAssetsMap, tempDroppedAssetsMap, "f");
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
throw getErrorResponse({ error });
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* @summary
|
|
261
|
+
* Update multiple custom text dropped assets with a single style while preserving text for specified dropped assets only.
|
|
262
|
+
*
|
|
263
|
+
* @usage
|
|
264
|
+
* ```ts
|
|
265
|
+
* const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]];
|
|
266
|
+
* const style = {
|
|
267
|
+
* "textColor": "#abc123",
|
|
268
|
+
* "textFontFamily": "Arial",
|
|
269
|
+
* "textSize": 40,
|
|
270
|
+
* "textWeight": "normal",
|
|
271
|
+
* "textWidth": 200
|
|
272
|
+
* };
|
|
273
|
+
* await world.updateCustomText(droppedAssetsToUpdate, style);
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* @result
|
|
277
|
+
* Updates each DroppedAsset instance and world.droppedAssets map.
|
|
278
|
+
*/
|
|
279
|
+
updateCustomTextDroppedAssets(droppedAssetsToUpdate, style) {
|
|
280
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
281
|
+
const allPromises = [];
|
|
282
|
+
droppedAssetsToUpdate.forEach((a) => {
|
|
283
|
+
allPromises.push(a.updateCustomTextAsset(style, a.text));
|
|
284
|
+
});
|
|
285
|
+
const outcomes = yield Promise.allSettled(allPromises);
|
|
286
|
+
return outcomes;
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* @summary
|
|
291
|
+
* Replace the current scene of a world.
|
|
292
|
+
*
|
|
293
|
+
* @usage
|
|
294
|
+
* ```ts
|
|
295
|
+
* const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]]
|
|
296
|
+
* const style = {
|
|
297
|
+
* "textColor": "#abc123",
|
|
298
|
+
* "textFontFamily": "Arial",
|
|
299
|
+
* "textSize": 40,
|
|
300
|
+
* "textWeight": "normal",
|
|
301
|
+
* "textWidth": 200
|
|
302
|
+
* }
|
|
303
|
+
* await world.replaceScene(SCENE_ID);
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
// scenes
|
|
307
|
+
replaceScene(sceneId) {
|
|
308
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
309
|
+
try {
|
|
310
|
+
yield this.topia.axios.put(`/world/${this.urlSlug}/change-scene`, { sceneId }, this.requestOptions);
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
throw getErrorResponse({ error });
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
_World_droppedAssetsMap = new WeakMap(), _World_visitorsMap = new WeakMap();
|
|
319
|
+
export default World;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import MockAdapter from "axios-mock-adapter";
|
|
11
|
+
import { AssetFactory } from "factories";
|
|
12
|
+
import { Topia } from "controllers/Topia";
|
|
13
|
+
const apiDomain = "api.topia.io";
|
|
14
|
+
describe("Asset Class", () => {
|
|
15
|
+
let Asset, mock, testAsset, topia;
|
|
16
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
topia = new Topia({
|
|
18
|
+
apiDomain: "api.topia.io",
|
|
19
|
+
apiKey: "exampleKey",
|
|
20
|
+
interactiveKey: "key",
|
|
21
|
+
interactiveSecret: "secret",
|
|
22
|
+
});
|
|
23
|
+
mock = new MockAdapter(topia.axios);
|
|
24
|
+
Asset = new AssetFactory(topia);
|
|
25
|
+
testAsset = Asset.create("test");
|
|
26
|
+
}));
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
mock.restore();
|
|
29
|
+
jest.resetAllMocks();
|
|
30
|
+
});
|
|
31
|
+
it("should return an array of assets owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
mock.onGet(`https://${apiDomain}/api/assets/topia-assets`).reply(200);
|
|
33
|
+
yield testAsset.fetchPlatformAssets();
|
|
34
|
+
expect(mock.history.get.length).toBe(1);
|
|
35
|
+
}));
|
|
36
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { droppedAssets } from "__mocks__";
|
|
11
|
+
import { Topia } from "controllers";
|
|
12
|
+
import { DroppedAssetClickType, DroppedAssetMediaType } from "types";
|
|
13
|
+
import MockAdapter from "axios-mock-adapter";
|
|
14
|
+
import { DroppedAssetFactory } from "factories";
|
|
15
|
+
const apiDomain = "api.topia.io";
|
|
16
|
+
const attributes = droppedAssets[0];
|
|
17
|
+
const BASE_URL = `https://api.topia.io/api/world/exampleWorld/assets/${droppedAssets[0].id}`;
|
|
18
|
+
const id = droppedAssets[0].id;
|
|
19
|
+
describe("DroppedAsset Class", () => {
|
|
20
|
+
let DroppedAsset, mock, testDroppedAsset, topia;
|
|
21
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
topia = new Topia({
|
|
23
|
+
apiDomain,
|
|
24
|
+
apiKey: "key",
|
|
25
|
+
});
|
|
26
|
+
mock = new MockAdapter(topia.axios);
|
|
27
|
+
DroppedAsset = new DroppedAssetFactory(topia);
|
|
28
|
+
testDroppedAsset = yield DroppedAsset.create(id, "exampleWorld");
|
|
29
|
+
}));
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
mock.restore();
|
|
32
|
+
jest.resetAllMocks();
|
|
33
|
+
});
|
|
34
|
+
it("should fetch dropped asset by id", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
mock.onGet(BASE_URL).reply(200, droppedAssets[0]);
|
|
36
|
+
yield testDroppedAsset.fetchDroppedAssetById();
|
|
37
|
+
expect(mock.history.get.length).toBe(1);
|
|
38
|
+
expect(testDroppedAsset.urlSlug).toBeDefined();
|
|
39
|
+
}));
|
|
40
|
+
it("should update dropped asset broadcast zone", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
mock.onPut(`${BASE_URL}/set-asset-broadcast`).reply(200);
|
|
42
|
+
const broadcastArgs = Object.assign(Object.assign({}, attributes), { assetBroadcast: true, assetBroadcastAll: false, broadcasterEmail: "test@test.com" });
|
|
43
|
+
yield testDroppedAsset.updateBroadcast(broadcastArgs);
|
|
44
|
+
expect(mock.history.put.length).toBe(1);
|
|
45
|
+
}));
|
|
46
|
+
it("should update dropped asset click type", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
mock.onPut(`${BASE_URL}/change-click-type`).reply(200);
|
|
48
|
+
const clickTypeArgs = Object.assign(Object.assign({}, attributes), { clickType: DroppedAssetClickType.LINK, clickableLink: "www.test.com", clickableLinkTitle: "Test", portalName: "Test", position: {
|
|
49
|
+
x: 0,
|
|
50
|
+
y: 0,
|
|
51
|
+
} });
|
|
52
|
+
yield testDroppedAsset.updateClickType(clickTypeArgs);
|
|
53
|
+
expect(mock.history.put.length).toBe(1);
|
|
54
|
+
}));
|
|
55
|
+
it("should update dropped asset custom text", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
mock.onPut(`${BASE_URL}/set-custom-text`).reply(200);
|
|
57
|
+
yield testDroppedAsset.updateCustomTextAsset({ textColor: "#abc123" }, "hello world");
|
|
58
|
+
expect(mock.history.put.length).toBe(1);
|
|
59
|
+
}));
|
|
60
|
+
it("should update dropped asset media type", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
mock.onPut(`${BASE_URL}/change-media-type`).reply(200);
|
|
62
|
+
const mediaTypeArgs = Object.assign(Object.assign({}, attributes), { audioRadius: 0, audioVolume: -1, isVideo: true, mediaLink: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", mediaName: "string", mediaType: DroppedAssetMediaType.LINK, portalName: "community", syncUserMedia: true });
|
|
63
|
+
yield testDroppedAsset.updateMediaType(mediaTypeArgs);
|
|
64
|
+
expect(mock.history.put.length).toBe(1);
|
|
65
|
+
}));
|
|
66
|
+
it("should update dropped asset mute zone", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
mock.onPut(`${BASE_URL}/set-mute-zone`).reply(200);
|
|
68
|
+
yield testDroppedAsset.updateMuteZone(true);
|
|
69
|
+
expect(mock.history.put.length).toBe(1);
|
|
70
|
+
}));
|
|
71
|
+
it("should update dropped asset position", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
mock.onPut(`${BASE_URL}/set-position`).reply(200);
|
|
73
|
+
yield testDroppedAsset.updatePosition(100, 100);
|
|
74
|
+
expect(mock.history.put.length).toBe(1);
|
|
75
|
+
}));
|
|
76
|
+
it("should update dropped asset private zone", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
+
mock.onPut(`${BASE_URL}/set-private-zone`).reply(200);
|
|
78
|
+
const privateZoneArgs = Object.assign(Object.assign({}, attributes), { isPrivateZone: true, isPrivateZoneChatDisabled: false, privateZoneUserCap: 10 });
|
|
79
|
+
yield testDroppedAsset.updatePrivateZone(privateZoneArgs);
|
|
80
|
+
expect(mock.history.put.length).toBe(1);
|
|
81
|
+
}));
|
|
82
|
+
it("should update dropped asset scale", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
mock.onPut(`${BASE_URL}/change-scale`).reply(200);
|
|
84
|
+
yield testDroppedAsset.updateScale(75);
|
|
85
|
+
expect(mock.history.put.length).toBe(1);
|
|
86
|
+
}));
|
|
87
|
+
it("should update dropped asset uploaded media selected", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
+
mock.onPut(`${BASE_URL}/change-uploaded-media-selected`).reply(200);
|
|
89
|
+
yield testDroppedAsset.updateUploadedMediaSelected("abc123");
|
|
90
|
+
expect(mock.history.put.length).toBe(1);
|
|
91
|
+
}));
|
|
92
|
+
it("should update dropped asset web image layers", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
93
|
+
mock.onPut(`${BASE_URL}/set-webimage-layers`).reply(200);
|
|
94
|
+
yield testDroppedAsset.updateWebImageLayers("test", "test");
|
|
95
|
+
expect(mock.history.put.length).toBe(1);
|
|
96
|
+
}));
|
|
97
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import MockAdapter from "axios-mock-adapter";
|
|
11
|
+
import { droppedAssets, scenes, worlds } from "__mocks__";
|
|
12
|
+
import { Topia } from "controllers";
|
|
13
|
+
import { UserFactory } from "factories";
|
|
14
|
+
const apiDomain = "api.topia.io";
|
|
15
|
+
const email = "test@email.com";
|
|
16
|
+
describe("User Class", () => {
|
|
17
|
+
let mock, testUser, topia, User;
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
topia = new Topia({
|
|
20
|
+
apiDomain,
|
|
21
|
+
apiKey: "key",
|
|
22
|
+
});
|
|
23
|
+
mock = new MockAdapter(topia.axios);
|
|
24
|
+
User = new UserFactory(topia);
|
|
25
|
+
testUser = User.create(email);
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
mock.restore();
|
|
29
|
+
jest.resetAllMocks();
|
|
30
|
+
});
|
|
31
|
+
it("should update user.worlds", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
mock.onGet(`https://${apiDomain}/api/user/worlds`).reply(200, worlds);
|
|
33
|
+
yield testUser.fetchWorldsByKey();
|
|
34
|
+
expect(mock.history.get.length).toBe(1);
|
|
35
|
+
expect(Object.keys(testUser.worlds).length).toBe(Object.keys(worlds).length);
|
|
36
|
+
}));
|
|
37
|
+
it("should return an array of scenes owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
testUser.fetchScenesByEmail = jest.fn().mockReturnValue(scenes);
|
|
39
|
+
const mockScenes = yield testUser.fetchScenesByEmail();
|
|
40
|
+
expect(testUser.fetchScenesByEmail).toHaveBeenCalled();
|
|
41
|
+
expect(mockScenes).toBeDefined();
|
|
42
|
+
}));
|
|
43
|
+
it("should return an array of assets owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
testUser.fetchAssetsByEmail = jest.fn().mockReturnValue(droppedAssets);
|
|
45
|
+
const mockAssets = yield testUser.fetchAssetsByEmail("lina@topia.io");
|
|
46
|
+
expect(testUser.fetchAssetsByEmail).toHaveBeenCalled();
|
|
47
|
+
expect(mockAssets).toBeDefined();
|
|
48
|
+
}));
|
|
49
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import MockAdapter from "axios-mock-adapter";
|
|
11
|
+
import { visitors } from "../../__mocks__";
|
|
12
|
+
import { Topia } from "controllers";
|
|
13
|
+
import { VisitorFactory } from "factories";
|
|
14
|
+
const apiDomain = "api.topia.io";
|
|
15
|
+
const id = visitors["1"].playerId;
|
|
16
|
+
describe("Visitor Class", () => {
|
|
17
|
+
let mock, testVisitor, topia, Visitor;
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
topia = new Topia({
|
|
20
|
+
apiDomain,
|
|
21
|
+
apiKey: "key",
|
|
22
|
+
});
|
|
23
|
+
mock = new MockAdapter(topia.axios);
|
|
24
|
+
Visitor = new VisitorFactory(topia);
|
|
25
|
+
testVisitor = Visitor.create(id, "exampleWorld");
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
mock.restore();
|
|
29
|
+
jest.resetAllMocks();
|
|
30
|
+
});
|
|
31
|
+
it("should move a list of visitors to uniquely specified coordinates", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
mock.onPut(`https://${apiDomain}/api/world/exampleWorld/visitors/${id}/move`).reply(200);
|
|
33
|
+
yield testVisitor.moveVisitor({
|
|
34
|
+
shouldTeleportVisitor: true,
|
|
35
|
+
x: 100,
|
|
36
|
+
y: 100,
|
|
37
|
+
});
|
|
38
|
+
expect(mock.history.put.length).toBe(1);
|
|
39
|
+
}));
|
|
40
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import MockAdapter from "axios-mock-adapter";
|
|
11
|
+
import { visitors, worlds } from "../../__mocks__";
|
|
12
|
+
import { Visitor, Topia } from "controllers";
|
|
13
|
+
import { WorldFactory } from "factories";
|
|
14
|
+
const BASE_URL = "https://api.topia.io/api/world/exampleWorld";
|
|
15
|
+
const urlSlug = worlds[1].urlSlug;
|
|
16
|
+
describe("World Class", () => {
|
|
17
|
+
let mock, testWorld, topia, World;
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
topia = new Topia({
|
|
20
|
+
apiDomain: "api.topia.io",
|
|
21
|
+
apiKey: "key",
|
|
22
|
+
});
|
|
23
|
+
mock = new MockAdapter(topia.axios);
|
|
24
|
+
World = new WorldFactory(topia);
|
|
25
|
+
testWorld = World.create(urlSlug);
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
mock.restore();
|
|
29
|
+
jest.resetAllMocks();
|
|
30
|
+
});
|
|
31
|
+
it("should return details of a world", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
expect(testWorld.urlSlug).toEqual("exampleWorld");
|
|
33
|
+
testWorld.fetchDetails = jest.fn().mockReturnValue(worlds[1]);
|
|
34
|
+
const mockDetails = yield testWorld.fetchDetails();
|
|
35
|
+
expect(testWorld.fetchDetails).toHaveBeenCalled();
|
|
36
|
+
expect(mockDetails).toBeDefined();
|
|
37
|
+
}));
|
|
38
|
+
// it("should update details of a world", async () => {
|
|
39
|
+
// mock.onPut(`${BASE_URL}/world-details`).reply(200);
|
|
40
|
+
// const worldArgs = {
|
|
41
|
+
// controls: {
|
|
42
|
+
// allowMuteAll: false,
|
|
43
|
+
// },
|
|
44
|
+
// description: "testing update details",
|
|
45
|
+
// name: "exampleWorld",
|
|
46
|
+
// };
|
|
47
|
+
// await testWorld.updateDetails(worldArgs);
|
|
48
|
+
// expect(mock.history.put.length).toBe(1);
|
|
49
|
+
// expect(testWorld.urlSlug).toEqual("exampleWorld");
|
|
50
|
+
// });
|
|
51
|
+
it("should move all visitors within a world to a single set of coordinates", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
mock.onGet(`${BASE_URL}/visitors`).reply(200, visitors);
|
|
53
|
+
mock.onPut(`${BASE_URL}/visitors/1/move`).reply(200);
|
|
54
|
+
const attributes = {
|
|
55
|
+
shouldFetchVisitors: true,
|
|
56
|
+
shouldTeleportVisitors: true,
|
|
57
|
+
scatterVisitorsBy: 100,
|
|
58
|
+
x: 20,
|
|
59
|
+
y: 40,
|
|
60
|
+
};
|
|
61
|
+
yield testWorld.moveAllVisitors(attributes);
|
|
62
|
+
expect(mock.history.put.length).toBe(Object.keys(visitors).length);
|
|
63
|
+
}));
|
|
64
|
+
it("should return success if world doesn't have visitors", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
const attributes = { shouldFetchVisitors: false, scatterVisitorsBy: 100, x: 20, y: 40 };
|
|
66
|
+
yield testWorld.moveAllVisitors(attributes);
|
|
67
|
+
expect(mock.history.put.length).toBe(0);
|
|
68
|
+
}));
|
|
69
|
+
it("should move a list of visitors to uniquely specified coordinates", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
mock.onPut(`${BASE_URL}/visitors/1/move`).reply(200);
|
|
71
|
+
const v1 = new Visitor(topia, visitors["1"].playerId, urlSlug, { attributes: visitors["1"] });
|
|
72
|
+
const v2 = new Visitor(topia, visitors["2"].playerId, urlSlug, { attributes: visitors["2"] });
|
|
73
|
+
const testVisitors = [
|
|
74
|
+
{ visitorObj: v1, shouldTeleportVisitor: true, x: 0, y: 0 },
|
|
75
|
+
{ visitorObj: v2, shouldTeleportVisitor: false, x: 100, y: 100 },
|
|
76
|
+
];
|
|
77
|
+
yield testWorld.moveVisitors(testVisitors);
|
|
78
|
+
expect(mock.history.put.length).toBe(2);
|
|
79
|
+
}));
|
|
80
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Asset } from "./Asset";
|
|
2
|
+
export { DroppedAsset } from "./DroppedAsset";
|
|
3
|
+
export { SDKController } from "./SDKController";
|
|
4
|
+
export { User } from "./User";
|
|
5
|
+
export { Visitor } from "./Visitor";
|
|
6
|
+
export { World } from "./World";
|
|
7
|
+
export { Topia } from "./Topia";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { DroppedAsset } from "controllers";
|
|
11
|
+
export class DroppedAssetFactory {
|
|
12
|
+
constructor(topia) {
|
|
13
|
+
this.topia = topia;
|
|
14
|
+
}
|
|
15
|
+
create(id, urlSlug, options) {
|
|
16
|
+
return new DroppedAsset(this.topia, id, urlSlug, options);
|
|
17
|
+
}
|
|
18
|
+
get(id, urlSlug, options) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const droppedAsset = new DroppedAsset(this.topia, id, urlSlug, options);
|
|
21
|
+
yield droppedAsset.fetchDroppedAssetById();
|
|
22
|
+
return droppedAsset;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export default DroppedAssetFactory;
|