@rtsdk/topia 0.0.9 → 0.0.10
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/__mocks__/worlds.js +1 -0
- package/dist/controllers/Asset.js +2 -44
- package/dist/controllers/DroppedAsset.js +36 -35
- package/dist/controllers/User.js +63 -0
- package/dist/controllers/Visitor.js +4 -43
- package/dist/controllers/World.js +112 -63
- package/dist/controllers/__tests__/asset.test.js +13 -4
- package/dist/controllers/__tests__/droppedAsset.test.js +55 -71
- package/dist/controllers/__tests__/user.test.js +23 -0
- package/dist/controllers/__tests__/visitor.test.js +17 -5
- package/dist/controllers/__tests__/world.test.js +49 -24
- package/dist/controllers/index.js +1 -1
- package/dist/index.js +229 -214
- package/dist/{types/DroppedAssetType.js → interfaces/AssetInterfaces.js} +0 -0
- package/dist/{types/VisitorType.js → interfaces/VisitorInterfaces.js} +0 -0
- package/dist/interfaces/index.js +2 -0
- package/dist/utils/__tests__/removeUndefined.test.js +10 -0
- package/dist/utils/__tests__/scatterVisitors.test.js +4 -4
- package/dist/utils/getErrorMessage.js +2 -2
- package/dist/utils/index.js +1 -1
- package/dist/utils/publicAPI.js +0 -1
- package/dist/utils/removeUndefined.js +8 -0
- package/package.json +1 -1
- package/dist/controllers/Scene.js +0 -22
- package/dist/controllers/__tests__/scene.test.js +0 -14
- package/dist/types/Visitors.js +0 -1
- package/dist/utils/createVisitor.js +0 -3
package/dist/__mocks__/worlds.js
CHANGED
|
@@ -1,50 +1,8 @@
|
|
|
1
1
|
import { getErrorMessage, publicAPI } from "utils";
|
|
2
2
|
export class Asset {
|
|
3
|
-
|
|
4
|
-
apiKey;
|
|
5
|
-
assetName;
|
|
6
|
-
creatorTags;
|
|
7
|
-
id;
|
|
8
|
-
isPublic;
|
|
9
|
-
kitId;
|
|
10
|
-
layer0;
|
|
11
|
-
layer1;
|
|
12
|
-
library;
|
|
13
|
-
originalAssetId;
|
|
14
|
-
originalKit;
|
|
15
|
-
ownerId;
|
|
16
|
-
ownerName;
|
|
17
|
-
platformAsset;
|
|
18
|
-
purchased;
|
|
19
|
-
purchaseDate;
|
|
20
|
-
purchasedFrom;
|
|
21
|
-
specialType;
|
|
22
|
-
transactionId;
|
|
23
|
-
type;
|
|
24
|
-
urlSlug;
|
|
25
|
-
constructor(addedOn = "", apiKey, assetName = "", creatorTags = {}, id = "", isPublic = false, kitId = "", layer0 = "", layer1 = "", library = "", originalAssetId = "", originalKit = "", ownerId = "", ownerName = "", platformAsset = false, purchased = false, purchaseDate = "", purchasedFrom = "", specialType = "", transactionId = "", type = "", urlSlug = "") {
|
|
26
|
-
this.addedOn = addedOn;
|
|
3
|
+
constructor({ apiKey, args }) {
|
|
27
4
|
this.apiKey = apiKey;
|
|
28
|
-
this
|
|
29
|
-
this.creatorTags = creatorTags;
|
|
30
|
-
this.id = id;
|
|
31
|
-
this.isPublic = isPublic;
|
|
32
|
-
this.kitId = kitId;
|
|
33
|
-
this.layer0 = layer0;
|
|
34
|
-
this.layer1 = layer1;
|
|
35
|
-
this.library = library;
|
|
36
|
-
this.originalAssetId = originalAssetId;
|
|
37
|
-
this.originalKit = originalKit;
|
|
38
|
-
this.ownerId = ownerId;
|
|
39
|
-
this.ownerName = ownerName;
|
|
40
|
-
this.platformAsset = platformAsset;
|
|
41
|
-
this.purchased = purchased;
|
|
42
|
-
this.purchaseDate = purchaseDate;
|
|
43
|
-
this.purchasedFrom = purchasedFrom;
|
|
44
|
-
this.specialType = specialType;
|
|
45
|
-
this.transactionId = transactionId;
|
|
46
|
-
this.type = type;
|
|
47
|
-
this.urlSlug = urlSlug;
|
|
5
|
+
Object.assign(this, args);
|
|
48
6
|
}
|
|
49
7
|
fetchAssetsByEmail(ownerEmail) {
|
|
50
8
|
return new Promise((resolve, reject) => {
|
|
@@ -1,16 +1,32 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
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");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _DroppedAsset_updateDroppedAsset;
|
|
1
7
|
import { getErrorMessage, publicAPI } from "utils";
|
|
2
8
|
import Asset from "./Asset";
|
|
3
9
|
export class DroppedAsset extends Asset {
|
|
4
|
-
apiKey
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
constructor({ apiKey, id, args, urlSlug, }) {
|
|
11
|
+
super({ apiKey, args });
|
|
12
|
+
// update dropped assets
|
|
13
|
+
_DroppedAsset_updateDroppedAsset.set(this, (payload, updateType) => {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
publicAPI(this.apiKey)
|
|
16
|
+
.put(`/world/${this.urlSlug}/assets/${this.id}/${updateType}`, Object.assign({}, payload))
|
|
17
|
+
.then(() => {
|
|
18
|
+
resolve("Success!");
|
|
19
|
+
})
|
|
20
|
+
.catch((error) => {
|
|
21
|
+
reject(new Error(getErrorMessage(error)));
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
Object.assign(this, args);
|
|
10
26
|
this.apiKey = apiKey;
|
|
11
|
-
this.
|
|
27
|
+
this.id = id;
|
|
28
|
+
this.text = args.text;
|
|
12
29
|
this.urlSlug = urlSlug;
|
|
13
|
-
Object.assign(this, args);
|
|
14
30
|
this.updateCustomText;
|
|
15
31
|
}
|
|
16
32
|
// get dropped asset
|
|
@@ -40,25 +56,9 @@ export class DroppedAsset extends Asset {
|
|
|
40
56
|
});
|
|
41
57
|
});
|
|
42
58
|
}
|
|
43
|
-
// update dropped assets
|
|
44
|
-
#updateDroppedAsset = (payload, updateType) => {
|
|
45
|
-
console.log("apiKey", this.apiKey);
|
|
46
|
-
return new Promise((resolve, reject) => {
|
|
47
|
-
publicAPI(this.apiKey)
|
|
48
|
-
.put(`/world/${this.urlSlug}/assets/${this.id}/${updateType}`, {
|
|
49
|
-
...payload,
|
|
50
|
-
})
|
|
51
|
-
.then(() => {
|
|
52
|
-
resolve("Success!");
|
|
53
|
-
})
|
|
54
|
-
.catch((error) => {
|
|
55
|
-
reject(new Error(getErrorMessage(error)));
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
59
|
updateBroadcast({ assetBroadcast, assetBroadcastAll, broadcasterEmail }) {
|
|
60
60
|
return new Promise((resolve, reject) => {
|
|
61
|
-
return this
|
|
61
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { assetBroadcast, assetBroadcastAll, broadcasterEmail }, "set-asset-broadcast")
|
|
62
62
|
.then(resolve)
|
|
63
63
|
.catch((error) => {
|
|
64
64
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -67,7 +67,7 @@ export class DroppedAsset extends Asset {
|
|
|
67
67
|
}
|
|
68
68
|
updateClickType({ clickType, clickableLink, clickableLinkTitle, portalName, position, }) {
|
|
69
69
|
return new Promise((resolve, reject) => {
|
|
70
|
-
return this
|
|
70
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { clickType, clickableLink, clickableLinkTitle, portalName, position }, "change-click-type")
|
|
71
71
|
.then(resolve)
|
|
72
72
|
.catch((error) => {
|
|
73
73
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -76,7 +76,7 @@ export class DroppedAsset extends Asset {
|
|
|
76
76
|
}
|
|
77
77
|
updateCustomText(style, text) {
|
|
78
78
|
return new Promise((resolve, reject) => {
|
|
79
|
-
return this
|
|
79
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { style, text }, "set-custom-text")
|
|
80
80
|
.then(resolve)
|
|
81
81
|
.catch((error) => {
|
|
82
82
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -85,7 +85,7 @@ export class DroppedAsset extends Asset {
|
|
|
85
85
|
}
|
|
86
86
|
updateMediaType({ audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia, }) {
|
|
87
87
|
return new Promise((resolve, reject) => {
|
|
88
|
-
return this
|
|
88
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia }, "change-media-type")
|
|
89
89
|
.then(resolve)
|
|
90
90
|
.catch((error) => {
|
|
91
91
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -94,7 +94,7 @@ export class DroppedAsset extends Asset {
|
|
|
94
94
|
}
|
|
95
95
|
updateMuteZone(isMutezone) {
|
|
96
96
|
return new Promise((resolve, reject) => {
|
|
97
|
-
return this
|
|
97
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { isMutezone }, "set-mute-zone")
|
|
98
98
|
.then(resolve)
|
|
99
99
|
.catch((error) => {
|
|
100
100
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -103,7 +103,7 @@ export class DroppedAsset extends Asset {
|
|
|
103
103
|
}
|
|
104
104
|
updatePosition(x, y) {
|
|
105
105
|
return new Promise((resolve, reject) => {
|
|
106
|
-
return this
|
|
106
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { x, y }, "set-position")
|
|
107
107
|
.then(resolve)
|
|
108
108
|
.catch((error) => {
|
|
109
109
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -112,7 +112,7 @@ export class DroppedAsset extends Asset {
|
|
|
112
112
|
}
|
|
113
113
|
updatePrivateZone({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap, }) {
|
|
114
114
|
return new Promise((resolve, reject) => {
|
|
115
|
-
return this
|
|
115
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap }, "set-private-zone")
|
|
116
116
|
.then(resolve)
|
|
117
117
|
.catch((error) => {
|
|
118
118
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -121,7 +121,7 @@ export class DroppedAsset extends Asset {
|
|
|
121
121
|
}
|
|
122
122
|
updateScale(assetScale) {
|
|
123
123
|
return new Promise((resolve, reject) => {
|
|
124
|
-
return this
|
|
124
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { assetScale }, "change-scale")
|
|
125
125
|
.then(resolve)
|
|
126
126
|
.catch((error) => {
|
|
127
127
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -130,7 +130,7 @@ export class DroppedAsset extends Asset {
|
|
|
130
130
|
}
|
|
131
131
|
updateUploadedMediaSelected(mediaId) {
|
|
132
132
|
return new Promise((resolve, reject) => {
|
|
133
|
-
return this
|
|
133
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { mediaId }, "change-uploaded-media-selected")
|
|
134
134
|
.then(resolve)
|
|
135
135
|
.catch((error) => {
|
|
136
136
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -139,7 +139,7 @@ export class DroppedAsset extends Asset {
|
|
|
139
139
|
}
|
|
140
140
|
updateWebImageLayers(bottom, top) {
|
|
141
141
|
return new Promise((resolve, reject) => {
|
|
142
|
-
return this
|
|
142
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { bottom, top }, "set-webimage-layers")
|
|
143
143
|
.then(resolve)
|
|
144
144
|
.catch((error) => {
|
|
145
145
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -147,4 +147,5 @@ export class DroppedAsset extends Asset {
|
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
_DroppedAsset_updateDroppedAsset = new WeakMap();
|
|
151
|
+
export default DroppedAsset;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
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");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
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");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _User_worldsMap;
|
|
13
|
+
import { World } from "controllers/World";
|
|
14
|
+
import { getErrorMessage, publicAPI } from "utils";
|
|
15
|
+
export class User {
|
|
16
|
+
constructor({ apiKey, email }) {
|
|
17
|
+
_User_worldsMap.set(this, void 0);
|
|
18
|
+
__classPrivateFieldSet(this, _User_worldsMap, {}, "f");
|
|
19
|
+
this.apiKey = apiKey;
|
|
20
|
+
this.email = email;
|
|
21
|
+
}
|
|
22
|
+
get worlds() {
|
|
23
|
+
return __classPrivateFieldGet(this, _User_worldsMap, "f");
|
|
24
|
+
}
|
|
25
|
+
fetchScenesByEmail() {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
if (!this.email)
|
|
28
|
+
reject("There is no email associated with this user.");
|
|
29
|
+
publicAPI(this.apiKey)
|
|
30
|
+
.get(`/scenes/my-scenes?email=${this.email}`)
|
|
31
|
+
.then((response) => {
|
|
32
|
+
resolve(response.data);
|
|
33
|
+
})
|
|
34
|
+
.catch((error) => {
|
|
35
|
+
reject(new Error(getErrorMessage(error)));
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
fetchWorldsByKey() {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
publicAPI(this.apiKey)
|
|
42
|
+
.get("/user/worlds")
|
|
43
|
+
.then((response) => {
|
|
44
|
+
const tempWorldsMap = {};
|
|
45
|
+
for (const i in response.data) {
|
|
46
|
+
const worldDetails = response.data[i];
|
|
47
|
+
tempWorldsMap[worldDetails.urlSlug] = new World({
|
|
48
|
+
apiKey: this.apiKey,
|
|
49
|
+
args: worldDetails,
|
|
50
|
+
urlSlug: worldDetails.urlSlug,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
__classPrivateFieldSet(this, _User_worldsMap, tempWorldsMap, "f");
|
|
54
|
+
resolve("Success!");
|
|
55
|
+
})
|
|
56
|
+
.catch((error) => {
|
|
57
|
+
reject(new Error(getErrorMessage(error)));
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
_User_worldsMap = new WeakMap();
|
|
63
|
+
export default User;
|
|
@@ -1,50 +1,11 @@
|
|
|
1
1
|
import { getErrorMessage, publicAPI } from "utils";
|
|
2
2
|
export class Visitor {
|
|
3
|
-
apiKey
|
|
4
|
-
|
|
5
|
-
displayName;
|
|
6
|
-
gestureType;
|
|
7
|
-
hidden;
|
|
8
|
-
isAdmin;
|
|
9
|
-
isBackground;
|
|
10
|
-
isMobile;
|
|
11
|
-
isRecording;
|
|
12
|
-
isRecordingBot;
|
|
13
|
-
lastUpdate;
|
|
14
|
-
moveFrom;
|
|
15
|
-
movedOn;
|
|
16
|
-
moveTo;
|
|
17
|
-
muted;
|
|
18
|
-
performer;
|
|
19
|
-
performerNear;
|
|
20
|
-
playerId;
|
|
21
|
-
shareScreen;
|
|
22
|
-
sitting;
|
|
23
|
-
urlSlug;
|
|
24
|
-
username;
|
|
25
|
-
constructor(apiKey, color = "", displayName, gestureType = 0, hidden = false, isAdmin = false, isBackground = false, isMobile = false, isRecording = false, isRecordingBot = false, lastUpdate = undefined, moveFrom = {}, movedOn = undefined, moveTo = { x: 0, y: 0 }, muted = false, performer = false, performerNear = false, playerId = undefined, shareScreen = false, sitting = false, urlSlug, username = undefined) {
|
|
3
|
+
constructor({ apiKey, args, urlSlug }) {
|
|
4
|
+
Object.assign(this, args);
|
|
26
5
|
this.apiKey = apiKey;
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
29
|
-
this.gestureType = gestureType;
|
|
30
|
-
this.hidden = hidden;
|
|
31
|
-
this.isAdmin = isAdmin;
|
|
32
|
-
this.isBackground = isBackground;
|
|
33
|
-
this.isMobile = isMobile;
|
|
34
|
-
this.isRecording = isRecording;
|
|
35
|
-
this.isRecordingBot = isRecordingBot;
|
|
36
|
-
this.lastUpdate = lastUpdate;
|
|
37
|
-
this.moveFrom = moveFrom;
|
|
38
|
-
this.movedOn = movedOn;
|
|
39
|
-
this.moveTo = moveTo;
|
|
40
|
-
this.muted = muted;
|
|
41
|
-
this.performer = performer;
|
|
42
|
-
this.performerNear = performerNear;
|
|
43
|
-
this.playerId = playerId;
|
|
44
|
-
this.shareScreen = shareScreen;
|
|
45
|
-
this.sitting = sitting;
|
|
6
|
+
this.moveTo = args.moveTo;
|
|
7
|
+
this.playerId = args.playerId;
|
|
46
8
|
this.urlSlug = urlSlug;
|
|
47
|
-
this.username = username;
|
|
48
9
|
this.moveVisitor;
|
|
49
10
|
}
|
|
50
11
|
moveVisitor(shouldTeleportVisitor, x, y) {
|
|
@@ -1,35 +1,42 @@
|
|
|
1
|
-
|
|
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
|
+
import { getErrorMessage, publicAPI, removeUndefined, scatterVisitors } from "utils";
|
|
2
23
|
import { DroppedAsset } from "controllers/DroppedAsset";
|
|
3
24
|
import { Visitor } from "controllers/Visitor";
|
|
4
25
|
export class World {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
height;
|
|
15
|
-
heroImage;
|
|
16
|
-
mapExists;
|
|
17
|
-
name;
|
|
18
|
-
redirectTo;
|
|
19
|
-
spawnPosition;
|
|
20
|
-
tileBackgroundEverywhere;
|
|
21
|
-
urlSlug;
|
|
22
|
-
useTopiaPassword;
|
|
23
|
-
width;
|
|
26
|
+
constructor({ apiKey, args, urlSlug }) {
|
|
27
|
+
_World_droppedAssetsMap.set(this, void 0);
|
|
28
|
+
_World_visitorsMap.set(this, void 0);
|
|
29
|
+
Object.assign(this, args);
|
|
30
|
+
__classPrivateFieldSet(this, _World_droppedAssetsMap, {}, "f");
|
|
31
|
+
__classPrivateFieldSet(this, _World_visitorsMap, {}, "f");
|
|
32
|
+
this.apiKey = apiKey;
|
|
33
|
+
this.urlSlug = urlSlug;
|
|
34
|
+
}
|
|
24
35
|
get droppedAssets() {
|
|
25
|
-
return this
|
|
36
|
+
return __classPrivateFieldGet(this, _World_droppedAssetsMap, "f");
|
|
26
37
|
}
|
|
27
38
|
get visitors() {
|
|
28
|
-
return this
|
|
29
|
-
}
|
|
30
|
-
constructor(apiKey, urlSlug) {
|
|
31
|
-
this.apiKey = apiKey;
|
|
32
|
-
this.urlSlug = urlSlug;
|
|
39
|
+
return __classPrivateFieldGet(this, _World_visitorsMap, "f");
|
|
33
40
|
}
|
|
34
41
|
// world details
|
|
35
42
|
fetchDetails() {
|
|
@@ -45,11 +52,22 @@ export class World {
|
|
|
45
52
|
});
|
|
46
53
|
});
|
|
47
54
|
}
|
|
48
|
-
updateDetails() {
|
|
55
|
+
updateDetails({ controls, description, forceAuthOnLogin, height, name, spawnPosition, width, }) {
|
|
56
|
+
const payload = {
|
|
57
|
+
controls,
|
|
58
|
+
description,
|
|
59
|
+
forceAuthOnLogin,
|
|
60
|
+
height,
|
|
61
|
+
name,
|
|
62
|
+
spawnPosition,
|
|
63
|
+
width,
|
|
64
|
+
};
|
|
49
65
|
return new Promise((resolve, reject) => {
|
|
50
66
|
publicAPI(this.apiKey)
|
|
51
|
-
.
|
|
67
|
+
.put(`/world/${this.urlSlug}/world-details`, payload)
|
|
52
68
|
.then(() => {
|
|
69
|
+
const cleanPayload = removeUndefined(payload);
|
|
70
|
+
Object.assign(this, cleanPayload);
|
|
53
71
|
resolve("Success!");
|
|
54
72
|
})
|
|
55
73
|
.catch((error) => {
|
|
@@ -66,9 +84,13 @@ export class World {
|
|
|
66
84
|
// create temp map and then update private property only once
|
|
67
85
|
const tempVisitorsMap = {};
|
|
68
86
|
for (const playerId in response.data) {
|
|
69
|
-
tempVisitorsMap[playerId] =
|
|
87
|
+
tempVisitorsMap[playerId] = new Visitor({
|
|
88
|
+
apiKey: this.apiKey,
|
|
89
|
+
args: response.data[playerId],
|
|
90
|
+
urlSlug: this.urlSlug,
|
|
91
|
+
});
|
|
70
92
|
}
|
|
71
|
-
this
|
|
93
|
+
__classPrivateFieldSet(this, _World_visitorsMap, tempVisitorsMap, "f");
|
|
72
94
|
resolve("Success!");
|
|
73
95
|
})
|
|
74
96
|
.catch((error) => {
|
|
@@ -76,33 +98,39 @@ export class World {
|
|
|
76
98
|
});
|
|
77
99
|
});
|
|
78
100
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
101
|
+
currentVisitors() {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
try {
|
|
104
|
+
yield this.fetchVisitors();
|
|
105
|
+
return this.visitors;
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
return error;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
87
111
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
if (shouldFetchVisitors)
|
|
115
|
+
yield this.fetchVisitors();
|
|
116
|
+
const allPromises = [];
|
|
117
|
+
if (!this.visitors)
|
|
118
|
+
return;
|
|
119
|
+
const objectKeys = Object.keys(this.visitors);
|
|
120
|
+
objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _World_visitorsMap, "f")[key].moveVisitor(shouldTeleportVisitors, scatterVisitors(x, scatterVisitorsBy), scatterVisitors(y, scatterVisitorsBy))));
|
|
121
|
+
const outcomes = yield Promise.allSettled(allPromises);
|
|
122
|
+
return outcomes;
|
|
123
|
+
});
|
|
98
124
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
125
|
+
moveVisitors(visitorsToMove) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const allPromises = [];
|
|
128
|
+
visitorsToMove.forEach((v) => {
|
|
129
|
+
allPromises.push(v.visitorObj.moveVisitor(v.shouldTeleportVisitor, v.x, v.y));
|
|
130
|
+
});
|
|
131
|
+
const outcomes = yield Promise.allSettled(allPromises);
|
|
132
|
+
return outcomes;
|
|
103
133
|
});
|
|
104
|
-
const outcomes = await Promise.allSettled(allPromises);
|
|
105
|
-
return outcomes;
|
|
106
134
|
}
|
|
107
135
|
// dropped assets
|
|
108
136
|
fetchDroppedAssets() {
|
|
@@ -114,9 +142,14 @@ export class World {
|
|
|
114
142
|
const tempDroppedAssetsMap = {};
|
|
115
143
|
for (const id in response.data) {
|
|
116
144
|
// tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
|
|
117
|
-
tempDroppedAssetsMap[id] = new DroppedAsset(
|
|
145
|
+
tempDroppedAssetsMap[id] = new DroppedAsset({
|
|
146
|
+
apiKey: this.apiKey,
|
|
147
|
+
id,
|
|
148
|
+
args: response.data[id],
|
|
149
|
+
urlSlug: this.urlSlug,
|
|
150
|
+
});
|
|
118
151
|
}
|
|
119
|
-
this
|
|
152
|
+
__classPrivateFieldSet(this, _World_droppedAssetsMap, tempDroppedAssetsMap, "f");
|
|
120
153
|
resolve("Success!");
|
|
121
154
|
})
|
|
122
155
|
.catch((error) => {
|
|
@@ -124,14 +157,30 @@ export class World {
|
|
|
124
157
|
});
|
|
125
158
|
});
|
|
126
159
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
160
|
+
updateCustomTextDroppedAssets(droppedAssetsToUpdate, style) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
// adds ability to update any styles for specified dropped assets only while preserving text
|
|
163
|
+
const allPromises = [];
|
|
164
|
+
droppedAssetsToUpdate.forEach((a) => {
|
|
165
|
+
allPromises.push(a.updateCustomText(style, a.text));
|
|
166
|
+
});
|
|
167
|
+
const outcomes = yield Promise.allSettled(allPromises);
|
|
168
|
+
return outcomes;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
// scenes
|
|
172
|
+
replaceScene(sceneId) {
|
|
173
|
+
return new Promise((resolve, reject) => {
|
|
174
|
+
publicAPI(this.apiKey)
|
|
175
|
+
.put(`/world/${this.urlSlug}/change-scene`, { sceneId })
|
|
176
|
+
.then(() => {
|
|
177
|
+
resolve("Success!");
|
|
178
|
+
})
|
|
179
|
+
.catch((error) => {
|
|
180
|
+
reject(new Error(getErrorMessage(error)));
|
|
181
|
+
});
|
|
132
182
|
});
|
|
133
|
-
const outcomes = await Promise.allSettled(allPromises);
|
|
134
|
-
return outcomes;
|
|
135
183
|
}
|
|
136
184
|
}
|
|
185
|
+
_World_droppedAssetsMap = new WeakMap(), _World_visitorsMap = new WeakMap();
|
|
137
186
|
export default World;
|
|
@@ -1,14 +1,23 @@
|
|
|
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
|
+
};
|
|
1
10
|
import { assets } from "../../__mocks__";
|
|
2
11
|
import { Asset } from "..";
|
|
3
12
|
afterEach(() => {
|
|
4
13
|
jest.resetAllMocks();
|
|
5
14
|
});
|
|
6
15
|
describe("Asset Class", () => {
|
|
7
|
-
it("should return an array of assets owned by specific email address",
|
|
8
|
-
const testAsset = new Asset("", "
|
|
16
|
+
it("should return an array of assets owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const testAsset = new Asset({ apiKey: "key", args: { id: "abc123" } });
|
|
9
18
|
testAsset.fetchAssetsByEmail = jest.fn().mockReturnValue(assets);
|
|
10
|
-
const mockAssets =
|
|
19
|
+
const mockAssets = yield testAsset.fetchAssetsByEmail("lina@topia.io");
|
|
11
20
|
expect(testAsset.fetchAssetsByEmail).toHaveBeenCalled();
|
|
12
21
|
expect(mockAssets).toBeDefined();
|
|
13
|
-
});
|
|
22
|
+
}));
|
|
14
23
|
});
|