@rtsdk/topia 0.1.0 → 0.1.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/dist/index.cjs +0 -13
- package/dist/index.js +1 -14
- package/dist/types/example.d.ts +6 -0
- package/dist/types/src/__mocks__/assets.d.ts +99 -0
- package/dist/{src/__mocks__/index.js → types/src/__mocks__/index.d.ts} +4 -4
- package/dist/types/src/__mocks__/scenes.d.ts +79 -0
- package/dist/types/src/__mocks__/visitors.d.ts +83 -0
- package/dist/types/src/__mocks__/worlds.d.ts +73 -0
- package/dist/types/src/controllers/Asset.d.ts +20 -0
- package/dist/types/src/controllers/DroppedAsset.d.ts +285 -0
- package/dist/types/src/controllers/SDKController.d.ts +48 -0
- package/dist/types/src/controllers/Scene.d.ts +19 -0
- package/dist/types/src/controllers/Topia.d.ts +33 -0
- package/dist/types/src/controllers/User.d.ts +58 -0
- package/dist/types/src/controllers/Visitor.d.ts +50 -0
- package/dist/types/src/controllers/World.d.ts +143 -0
- package/dist/types/src/controllers/WorldActivity.d.ts +83 -0
- package/dist/{src/interfaces/AssetInterfaces.js → types/src/controllers/__tests__/asset.test.d.ts} +1 -1
- package/dist/{src/interfaces/DroppedAssetInterfaces.js → types/src/controllers/__tests__/droppedAsset.test.d.ts} +1 -1
- package/dist/{src/interfaces/SDKInterfaces.js → types/src/controllers/__tests__/scene.test.d.ts} +1 -1
- package/dist/{src/interfaces/SceneInterfaces.js → types/src/controllers/__tests__/user.test.d.ts} +1 -1
- package/dist/types/src/controllers/__tests__/visitor.test.d.ts +1 -0
- package/dist/types/src/controllers/__tests__/world.test.d.ts +1 -0
- package/dist/types/src/controllers/__tests__/worldActivity.test.d.ts +1 -0
- package/dist/{src/controllers/index.js → types/src/controllers/index.d.ts} +9 -9
- package/dist/types/src/factories/AssetFactory.d.ts +8 -0
- package/dist/types/src/factories/DroppedAssetFactory.d.ts +16 -0
- package/dist/types/src/factories/SceneFactory.d.ts +9 -0
- package/dist/types/src/factories/UserFactory.d.ts +8 -0
- package/dist/types/src/factories/VisitorFactory.d.ts +9 -0
- package/dist/types/src/factories/WorldActivityFactory.d.ts +8 -0
- package/dist/types/src/factories/WorldFactory.d.ts +8 -0
- package/dist/{src/factories/index.js → types/src/factories/index.d.ts} +7 -7
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/interfaces/AssetInterfaces.d.ts +26 -0
- package/dist/types/src/interfaces/DroppedAssetInterfaces.d.ts +102 -0
- package/dist/types/src/interfaces/SDKInterfaces.d.ts +8 -0
- package/dist/types/src/interfaces/SceneInterfaces.d.ts +27 -0
- package/dist/types/src/interfaces/TopiaInterfaces.d.ts +10 -0
- package/dist/types/src/interfaces/UserInterfaces.d.ts +6 -0
- package/dist/types/src/interfaces/VisitorInterfaces.d.ts +37 -0
- package/dist/types/src/interfaces/WorldActivityInterfaces.d.ts +11 -0
- package/dist/types/src/interfaces/WorldInterfaces.d.ts +32 -0
- package/dist/{src/interfaces/index.js → types/src/interfaces/index.d.ts} +9 -9
- package/dist/types/src/types/DroppedAssetTypes.d.ts +10 -0
- package/dist/types/src/types/InteractiveCredentialsTypes.d.ts +8 -0
- package/dist/types/src/types/OptionsTypes.d.ts +21 -0
- package/dist/types/src/types/ResponseTypes.d.ts +4 -0
- package/dist/types/src/types/VisitorTypes.d.ts +33 -0
- package/dist/{src/types/index.js → types/src/types/index.d.ts} +5 -4
- package/dist/types/src/utils/__tests__/removeUndefined.test.d.ts +1 -0
- package/dist/types/src/utils/__tests__/scatterVisitors.test.d.ts +1 -0
- package/dist/types/src/utils/getBrowserWarning.d.ts +1 -0
- package/dist/{src/utils/index.js → types/src/utils/index.d.ts} +3 -3
- package/dist/types/src/utils/removeUndefined.d.ts +8 -0
- package/dist/types/src/utils/scatterVisitors.d.ts +4 -0
- package/package.json +3 -2
- package/dist/example.js +0 -32
- package/dist/src/__mocks__/assets.js +0 -249
- package/dist/src/__mocks__/scenes.js +0 -104
- package/dist/src/__mocks__/visitors.js +0 -83
- package/dist/src/__mocks__/worlds.js +0 -52
- package/dist/src/controllers/Asset.js +0 -39
- package/dist/src/controllers/DroppedAsset.js +0 -461
- package/dist/src/controllers/SDKController.js +0 -85
- package/dist/src/controllers/Scene.js +0 -39
- package/dist/src/controllers/Topia.js +0 -39
- package/dist/src/controllers/User.js +0 -139
- package/dist/src/controllers/Visitor.js +0 -92
- package/dist/src/controllers/World.js +0 -256
- package/dist/src/controllers/WorldActivity.js +0 -162
- package/dist/src/controllers/__tests__/asset.test.js +0 -37
- package/dist/src/controllers/__tests__/droppedAsset.test.js +0 -98
- package/dist/src/controllers/__tests__/scene.test.js +0 -38
- package/dist/src/controllers/__tests__/user.test.js +0 -49
- package/dist/src/controllers/__tests__/visitor.test.js +0 -47
- package/dist/src/controllers/__tests__/world.test.js +0 -51
- package/dist/src/controllers/__tests__/worldActivity.test.js +0 -63
- package/dist/src/factories/AssetFactory.js +0 -11
- package/dist/src/factories/DroppedAssetFactory.js +0 -42
- package/dist/src/factories/SceneFactory.js +0 -27
- package/dist/src/factories/UserFactory.js +0 -10
- package/dist/src/factories/VisitorFactory.js +0 -26
- package/dist/src/factories/WorldActivityFactory.js +0 -10
- package/dist/src/factories/WorldFactory.js +0 -10
- package/dist/src/index.js +0 -28
- package/dist/src/interfaces/TopiaInterfaces.js +0 -1
- package/dist/src/interfaces/UserInterfaces.js +0 -1
- package/dist/src/interfaces/VisitorInterfaces.js +0 -1
- package/dist/src/interfaces/WorldActivityInterfaces.js +0 -1
- package/dist/src/interfaces/WorldInterfaces.js +0 -1
- package/dist/src/types/DroppedAssetTypes.js +0 -12
- package/dist/src/types/InteractiveCredentialsTypes.js +0 -1
- package/dist/src/types/OptionsTypes.js +0 -1
- package/dist/src/types/ResponseTypes.js +0 -1
- package/dist/src/types/VisitorTypes.js +0 -1
- package/dist/src/utils/__tests__/removeUndefined.test.js +0 -10
- package/dist/src/utils/__tests__/scatterVisitors.test.js +0 -11
- package/dist/src/utils/getBrowserWarning.js +0 -5
- package/dist/src/utils/removeUndefined.js +0 -11
- package/dist/src/utils/scatterVisitors.js +0 -8
|
@@ -1,139 +0,0 @@
|
|
|
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 _User_assetsMap, _User_scenesMap, _User_worldsMap;
|
|
22
|
-
// controllers
|
|
23
|
-
import { Asset } from "controllers/Asset";
|
|
24
|
-
import { Scene } from "controllers/Scene";
|
|
25
|
-
import { SDKController } from "controllers/SDKController";
|
|
26
|
-
import { World } from "controllers/World";
|
|
27
|
-
/**
|
|
28
|
-
* @summary
|
|
29
|
-
* Create an instance of User class with optional session credentials.
|
|
30
|
-
*
|
|
31
|
-
* @usage
|
|
32
|
-
* ```ts
|
|
33
|
-
* await new User(topia, { interactiveNonce: "exampleNonce", interactivePublicKey: "examplePublicKey", visitorId: 1 });
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export class User extends SDKController {
|
|
37
|
-
constructor(topia, options = { credentials: {} }) {
|
|
38
|
-
super(topia, options.credentials);
|
|
39
|
-
_User_assetsMap.set(this, void 0);
|
|
40
|
-
_User_scenesMap.set(this, void 0);
|
|
41
|
-
_User_worldsMap.set(this, void 0);
|
|
42
|
-
__classPrivateFieldSet(this, _User_assetsMap, {}, "f");
|
|
43
|
-
__classPrivateFieldSet(this, _User_scenesMap, {}, "f");
|
|
44
|
-
__classPrivateFieldSet(this, _User_worldsMap, {}, "f");
|
|
45
|
-
}
|
|
46
|
-
get assets() {
|
|
47
|
-
return __classPrivateFieldGet(this, _User_assetsMap, "f");
|
|
48
|
-
}
|
|
49
|
-
get scenes() {
|
|
50
|
-
return __classPrivateFieldGet(this, _User_scenesMap, "f");
|
|
51
|
-
}
|
|
52
|
-
get worlds() {
|
|
53
|
-
return __classPrivateFieldGet(this, _User_worldsMap, "f");
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* @summary
|
|
57
|
-
* Returns all assets owned by User when an email address is provided.
|
|
58
|
-
*/
|
|
59
|
-
fetchAssets() {
|
|
60
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
try {
|
|
62
|
-
const response = yield this.topiaPublicApi().get(`/assets/my-assets`, this.requestOptions);
|
|
63
|
-
const tempAssetsMap = {};
|
|
64
|
-
for (const i in response.data) {
|
|
65
|
-
const assetDetails = response.data[i];
|
|
66
|
-
tempAssetsMap[assetDetails.id] = new Asset(this.topia, assetDetails.id, {
|
|
67
|
-
attributes: assetDetails,
|
|
68
|
-
credentials: this.credentials,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
__classPrivateFieldSet(this, _User_assetsMap, tempAssetsMap, "f");
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
throw this.errorHandler({ error });
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* @summary
|
|
80
|
-
* Returns all scenes owned by User
|
|
81
|
-
*/
|
|
82
|
-
fetchScenes() {
|
|
83
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
try {
|
|
85
|
-
const response = yield this.topiaPublicApi().get("/scenes/my-scenes", this.requestOptions);
|
|
86
|
-
const tempScenesMap = {};
|
|
87
|
-
for (const i in response.data) {
|
|
88
|
-
const sceneDetails = response.data[i];
|
|
89
|
-
tempScenesMap[sceneDetails.id] = new Scene(this.topia, sceneDetails.urlSlug, {
|
|
90
|
-
attributes: sceneDetails,
|
|
91
|
-
credentials: this.credentials,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
__classPrivateFieldSet(this, _User_scenesMap, tempScenesMap, "f");
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
throw this.errorHandler({ error });
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* @summary
|
|
103
|
-
* Retrieves all worlds owned by user with matching API Key,
|
|
104
|
-
* creates a new World object for each,
|
|
105
|
-
* and creates new map of Worlds accessible via user.worlds.
|
|
106
|
-
*
|
|
107
|
-
* @usage
|
|
108
|
-
* ```ts
|
|
109
|
-
* await user.fetchWorldsByKey();
|
|
110
|
-
* const userWorlds = user.worlds;
|
|
111
|
-
* ```
|
|
112
|
-
*
|
|
113
|
-
* @result
|
|
114
|
-
* ```ts
|
|
115
|
-
* { urlSlug: new World({ apiKey, worldArgs, urlSlug }) }
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
fetchWorldsByKey() {
|
|
119
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
try {
|
|
121
|
-
const response = yield this.topiaPublicApi().get("/user/worlds", this.requestOptions);
|
|
122
|
-
const tempWorldsMap = {};
|
|
123
|
-
for (const i in response.data) {
|
|
124
|
-
const worldDetails = response.data[i];
|
|
125
|
-
tempWorldsMap[worldDetails.urlSlug] = new World(this.topia, worldDetails.urlSlug, {
|
|
126
|
-
attributes: worldDetails,
|
|
127
|
-
credentials: this.credentials,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
__classPrivateFieldSet(this, _User_worldsMap, tempWorldsMap, "f");
|
|
131
|
-
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
throw this.errorHandler({ error });
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
_User_assetsMap = new WeakMap(), _User_scenesMap = new WeakMap(), _User_worldsMap = new WeakMap();
|
|
139
|
-
export default User;
|
|
@@ -1,92 +0,0 @@
|
|
|
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 { User } from "controllers/User";
|
|
11
|
-
/**
|
|
12
|
-
* @summary
|
|
13
|
-
* Create an instance of Visitor class with a given id and optional attributes and session credentials.
|
|
14
|
-
*
|
|
15
|
-
* @usage
|
|
16
|
-
* ```ts
|
|
17
|
-
* await new Visitor(topia, id, urlSlug, { attributes: { moveTo: { x: 0, y: 0 } } });
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export class Visitor extends User {
|
|
21
|
-
constructor(topia, id, urlSlug, options = { attributes: {}, credentials: {} }) {
|
|
22
|
-
super(topia, { credentials: options.credentials });
|
|
23
|
-
Object.assign(this, options.attributes);
|
|
24
|
-
this.id = id;
|
|
25
|
-
this.urlSlug = urlSlug;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @summary
|
|
29
|
-
* Get a single visitor from a world
|
|
30
|
-
*
|
|
31
|
-
* @usage
|
|
32
|
-
* ```ts
|
|
33
|
-
* await visitor.fetchVisitor();
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @result
|
|
37
|
-
* Returns details for a visitor in a world by id and urlSlug
|
|
38
|
-
*/
|
|
39
|
-
fetchVisitor() {
|
|
40
|
-
var _a;
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
try {
|
|
43
|
-
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors/${this.id}`, this.requestOptions);
|
|
44
|
-
if (((_a = response.data) === null || _a === void 0 ? void 0 : _a.visitorId) === this.id) {
|
|
45
|
-
Object.assign(this, response.data);
|
|
46
|
-
}
|
|
47
|
-
else if (response.data[this.id]) {
|
|
48
|
-
Object.assign(this, response.data[this.id]);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
throw "This visitor is not active";
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
throw this.errorHandler({ error });
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* @summary
|
|
61
|
-
* Teleport or walk a visitor currently in a world to a single set of coordinates.
|
|
62
|
-
*
|
|
63
|
-
* @usage
|
|
64
|
-
* ```ts
|
|
65
|
-
* await visitor.moveVisitor({
|
|
66
|
-
* shouldTeleportVisitor: true,
|
|
67
|
-
* x: 100,
|
|
68
|
-
* y: 100,
|
|
69
|
-
* });
|
|
70
|
-
* ```
|
|
71
|
-
*
|
|
72
|
-
* @result
|
|
73
|
-
* Updates each Visitor instance and world.visitors map.
|
|
74
|
-
*/
|
|
75
|
-
moveVisitor({ shouldTeleportVisitor, x, y }) {
|
|
76
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
try {
|
|
78
|
-
yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/move`, {
|
|
79
|
-
moveTo: {
|
|
80
|
-
x,
|
|
81
|
-
y,
|
|
82
|
-
},
|
|
83
|
-
teleport: shouldTeleportVisitor,
|
|
84
|
-
}, this.requestOptions);
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
throw this.errorHandler({ error });
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
export default Visitor;
|
|
@@ -1,256 +0,0 @@
|
|
|
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;
|
|
22
|
-
// controllers
|
|
23
|
-
import { DroppedAsset } from "controllers/DroppedAsset";
|
|
24
|
-
import { SDKController } from "controllers/SDKController";
|
|
25
|
-
// utils
|
|
26
|
-
import { removeUndefined } from "utils";
|
|
27
|
-
/**
|
|
28
|
-
* @summary
|
|
29
|
-
* Create an instance of World class with a given url slug and optional attributes and session credentials.
|
|
30
|
-
*
|
|
31
|
-
* @usage
|
|
32
|
-
* ```ts
|
|
33
|
-
* await new World(topia, "exampleWorld", { attributes: { name: "Example World" } });
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export class World extends SDKController {
|
|
37
|
-
constructor(topia, urlSlug, options = { attributes: {}, credentials: {} }) {
|
|
38
|
-
super(topia, options.credentials);
|
|
39
|
-
_World_droppedAssetsMap.set(this, void 0);
|
|
40
|
-
Object.assign(this, options.attributes);
|
|
41
|
-
__classPrivateFieldSet(this, _World_droppedAssetsMap, {}, "f");
|
|
42
|
-
this.urlSlug = urlSlug;
|
|
43
|
-
}
|
|
44
|
-
get droppedAssets() {
|
|
45
|
-
return __classPrivateFieldGet(this, _World_droppedAssetsMap, "f");
|
|
46
|
-
}
|
|
47
|
-
//////// world details
|
|
48
|
-
/**
|
|
49
|
-
* @summary
|
|
50
|
-
* Retrieves details of a world.
|
|
51
|
-
*
|
|
52
|
-
* @usage
|
|
53
|
-
* ```ts
|
|
54
|
-
* await world.fetchDetails();
|
|
55
|
-
* const { name } = world;
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
fetchDetails() {
|
|
59
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
try {
|
|
61
|
-
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/world-details`, this.requestOptions);
|
|
62
|
-
Object.assign(this, response.data);
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
throw this.errorHandler({ error });
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* @summary
|
|
71
|
-
* Update details of a world.
|
|
72
|
-
*
|
|
73
|
-
* @usage
|
|
74
|
-
* ```ts
|
|
75
|
-
* await world.updateDetails({
|
|
76
|
-
* controls: {
|
|
77
|
-
* allowMuteAll: true,
|
|
78
|
-
* disableHideVideo: true,
|
|
79
|
-
* isMobileDisabled: false,
|
|
80
|
-
* isShowingCurrentGuests: false,
|
|
81
|
-
* },
|
|
82
|
-
* description: 'Welcome to my world.',
|
|
83
|
-
* forceAuthOnLogin: false,
|
|
84
|
-
* height: 2000,
|
|
85
|
-
* name: 'Example',
|
|
86
|
-
* spawnPosition: { x: 100, y: 100 },
|
|
87
|
-
* width: 2000
|
|
88
|
-
* });
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
updateDetails({ controls, description, forceAuthOnLogin, height, name, spawnPosition, width, }) {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const payload = {
|
|
94
|
-
controls,
|
|
95
|
-
description,
|
|
96
|
-
forceAuthOnLogin,
|
|
97
|
-
height,
|
|
98
|
-
name,
|
|
99
|
-
spawnPosition,
|
|
100
|
-
width,
|
|
101
|
-
};
|
|
102
|
-
try {
|
|
103
|
-
yield this.topiaPublicApi().put(`/world/${this.urlSlug}/world-details`, payload, this.requestOptions);
|
|
104
|
-
const cleanPayload = removeUndefined(payload);
|
|
105
|
-
Object.assign(this, cleanPayload);
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
throw this.errorHandler({ error });
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
////////// dropped assets
|
|
113
|
-
/**
|
|
114
|
-
* @summary
|
|
115
|
-
* Retrieve all assets dropped in a world.
|
|
116
|
-
*
|
|
117
|
-
* @usage
|
|
118
|
-
* ```ts
|
|
119
|
-
* await world.fetchDroppedAssets();
|
|
120
|
-
* const assets = world.droppedAssets;
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
fetchDroppedAssets() {
|
|
124
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
try {
|
|
126
|
-
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets`, this.requestOptions);
|
|
127
|
-
// create temp map and then update private property only once
|
|
128
|
-
const tempDroppedAssetsMap = {};
|
|
129
|
-
for (const index in response.data) {
|
|
130
|
-
tempDroppedAssetsMap[index] = new DroppedAsset(this.topia, response.data[index].id, this.urlSlug, {
|
|
131
|
-
attributes: response.data[index],
|
|
132
|
-
credentials: this.credentials,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
__classPrivateFieldSet(this, _World_droppedAssetsMap, tempDroppedAssetsMap, "f");
|
|
136
|
-
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
throw this.errorHandler({ error });
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* @summary
|
|
144
|
-
* Retrieve all assets dropped in a world matching uniqueName.
|
|
145
|
-
*
|
|
146
|
-
* @usage
|
|
147
|
-
* ```ts
|
|
148
|
-
* await world.fetchDroppedAssets();
|
|
149
|
-
* const assets = world.droppedAssets;
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
152
|
-
fetchDroppedAssetsWithUniqueName({ uniqueName, isPartial = false, isReversed = false, }) {
|
|
153
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
-
try {
|
|
155
|
-
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets-with-unique-name/${uniqueName}?${isPartial ? `partial=${isPartial}&` : ""}${isReversed ? `reversed=${isReversed}` : ""}`, this.requestOptions);
|
|
156
|
-
// create temp map and then update private property only once
|
|
157
|
-
const droppedAssets = [];
|
|
158
|
-
for (const asset of response.data.assets) {
|
|
159
|
-
droppedAssets.push(new DroppedAsset(this.topia, asset.id, this.urlSlug, {
|
|
160
|
-
attributes: asset,
|
|
161
|
-
credentials: this.credentials,
|
|
162
|
-
}));
|
|
163
|
-
}
|
|
164
|
-
return droppedAssets;
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
throw this.errorHandler({ error });
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* @summary
|
|
173
|
-
* Update multiple custom text dropped assets with a single style while preserving text for specified dropped assets only.
|
|
174
|
-
*
|
|
175
|
-
* @usage
|
|
176
|
-
* ```ts
|
|
177
|
-
* const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]];
|
|
178
|
-
* const style = {
|
|
179
|
-
* "textColor": "#abc123",
|
|
180
|
-
* "textFontFamily": "Arial",
|
|
181
|
-
* "textSize": 40,
|
|
182
|
-
* "textWeight": "normal",
|
|
183
|
-
* "textWidth": 200
|
|
184
|
-
* };
|
|
185
|
-
* await world.updateCustomText(droppedAssetsToUpdate, style);
|
|
186
|
-
* ```
|
|
187
|
-
*
|
|
188
|
-
* @result
|
|
189
|
-
* Updates each DroppedAsset instance and world.droppedAssets map.
|
|
190
|
-
*/
|
|
191
|
-
updateCustomTextDroppedAssets(droppedAssetsToUpdate, style) {
|
|
192
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
-
const allPromises = [];
|
|
194
|
-
droppedAssetsToUpdate.forEach((a) => {
|
|
195
|
-
allPromises.push(a.updateCustomTextAsset(style, a.text));
|
|
196
|
-
});
|
|
197
|
-
const outcomes = yield Promise.all(allPromises);
|
|
198
|
-
return outcomes;
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* @summary
|
|
203
|
-
* Drop a scene in a world.
|
|
204
|
-
*
|
|
205
|
-
* @usage
|
|
206
|
-
* ```ts
|
|
207
|
-
* await world.dropScene({
|
|
208
|
-
* "sceneId": "string",
|
|
209
|
-
* "position": {
|
|
210
|
-
* "x": 0,
|
|
211
|
-
* "y": 0
|
|
212
|
-
* },
|
|
213
|
-
* "assetSuffix": "string"
|
|
214
|
-
* });
|
|
215
|
-
* ```
|
|
216
|
-
*/
|
|
217
|
-
dropScene({ assetSuffix, position, sceneId, }) {
|
|
218
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
-
try {
|
|
220
|
-
yield this.topiaPublicApi().post(`/world/${this.urlSlug}/drop-scene`, { assetSuffix, position, sceneId }, this.requestOptions);
|
|
221
|
-
}
|
|
222
|
-
catch (error) {
|
|
223
|
-
throw this.errorHandler({ error });
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* @summary
|
|
229
|
-
* Replace the current scene of a world.
|
|
230
|
-
*
|
|
231
|
-
* @usage
|
|
232
|
-
* ```ts
|
|
233
|
-
* const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]]
|
|
234
|
-
* const style = {
|
|
235
|
-
* "textColor": "#abc123",
|
|
236
|
-
* "textFontFamily": "Arial",
|
|
237
|
-
* "textSize": 40,
|
|
238
|
-
* "textWeight": "normal",
|
|
239
|
-
* "textWidth": 200
|
|
240
|
-
* }
|
|
241
|
-
* await world.replaceScene(SCENE_ID);
|
|
242
|
-
* ```
|
|
243
|
-
*/
|
|
244
|
-
replaceScene(sceneId) {
|
|
245
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
-
try {
|
|
247
|
-
yield this.topiaPublicApi().put(`/world/${this.urlSlug}/change-scene`, { sceneId }, this.requestOptions);
|
|
248
|
-
}
|
|
249
|
-
catch (error) {
|
|
250
|
-
throw this.errorHandler({ error });
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
_World_droppedAssetsMap = new WeakMap();
|
|
256
|
-
export default World;
|
|
@@ -1,162 +0,0 @@
|
|
|
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 _WorldActivity_visitorsMap;
|
|
22
|
-
// controllers
|
|
23
|
-
import { SDKController } from "controllers/SDKController";
|
|
24
|
-
import { Visitor } from "controllers/Visitor";
|
|
25
|
-
// utils
|
|
26
|
-
import { scatterVisitors } from "utils";
|
|
27
|
-
/**
|
|
28
|
-
* @summary
|
|
29
|
-
* Create an instance of WorldActivity class with a given url slug and optional attributes and session credentials.
|
|
30
|
-
*
|
|
31
|
-
* This class is responsible for all activity of a specified world including editing dropped assets, moving current visitors, etc.
|
|
32
|
-
*
|
|
33
|
-
* @usage
|
|
34
|
-
* ```ts
|
|
35
|
-
* await new WorldActivity(topia, "exampleWorld", { attributes: { name: "Example World" } });
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export class WorldActivity extends SDKController {
|
|
39
|
-
constructor(topia, urlSlug, options = { credentials: {} }) {
|
|
40
|
-
super(topia, options.credentials);
|
|
41
|
-
_WorldActivity_visitorsMap.set(this, void 0);
|
|
42
|
-
__classPrivateFieldSet(this, _WorldActivity_visitorsMap, {}, "f");
|
|
43
|
-
this.urlSlug = urlSlug;
|
|
44
|
-
}
|
|
45
|
-
get visitors() {
|
|
46
|
-
return __classPrivateFieldGet(this, _WorldActivity_visitorsMap, "f");
|
|
47
|
-
}
|
|
48
|
-
//////// visitors
|
|
49
|
-
fetchVisitors() {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
try {
|
|
52
|
-
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors`, this.requestOptions);
|
|
53
|
-
// create temp map and then update private property only once
|
|
54
|
-
const tempVisitorsMap = {};
|
|
55
|
-
for (const id in response.data) {
|
|
56
|
-
tempVisitorsMap[id] = new Visitor(this.topia, response.data[id].visitorId, this.urlSlug, {
|
|
57
|
-
attributes: response.data[id],
|
|
58
|
-
credentials: this.credentials,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
__classPrivateFieldSet(this, _WorldActivity_visitorsMap, tempVisitorsMap, "f");
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
throw this.errorHandler({ error });
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* @summary
|
|
70
|
-
* Retrieve all visitors currently in a world.
|
|
71
|
-
*
|
|
72
|
-
* @usage
|
|
73
|
-
* ```ts
|
|
74
|
-
* const visitors = await world.currentVisitors();
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
currentVisitors() {
|
|
78
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
try {
|
|
80
|
-
yield this.fetchVisitors();
|
|
81
|
-
return this.visitors;
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
return error;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* @summary
|
|
90
|
-
* Move all visitors currently in a world to a single set of coordinates.
|
|
91
|
-
* Optionally refetch visitors, teleport or walk visitors to new location,
|
|
92
|
-
* and scatter visitors by any number so that they don't all move to the exact same location.
|
|
93
|
-
*
|
|
94
|
-
* @usage
|
|
95
|
-
* ```ts
|
|
96
|
-
* await world.moveAllVisitors({
|
|
97
|
-
* shouldFetchVisitors: true,
|
|
98
|
-
* shouldTeleportVisitors: true,
|
|
99
|
-
* scatterVisitorsBy: 40,
|
|
100
|
-
* x: 100,
|
|
101
|
-
* y: 100,
|
|
102
|
-
* });
|
|
103
|
-
* ```
|
|
104
|
-
*
|
|
105
|
-
* @result
|
|
106
|
-
* Updates each Visitor instance and world.visitors map.
|
|
107
|
-
*/
|
|
108
|
-
moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
|
|
109
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
if (shouldFetchVisitors)
|
|
111
|
-
yield this.fetchVisitors();
|
|
112
|
-
const allPromises = [];
|
|
113
|
-
if (!this.visitors)
|
|
114
|
-
return;
|
|
115
|
-
const objectKeys = Object.keys(this.visitors);
|
|
116
|
-
objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _WorldActivity_visitorsMap, "f")[key].moveVisitor({
|
|
117
|
-
shouldTeleportVisitor: shouldTeleportVisitors,
|
|
118
|
-
x: scatterVisitors(x, scatterVisitorsBy),
|
|
119
|
-
y: scatterVisitors(y, scatterVisitorsBy),
|
|
120
|
-
})));
|
|
121
|
-
const outcomes = yield Promise.all(allPromises);
|
|
122
|
-
return outcomes;
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* @summary
|
|
127
|
-
* Teleport or walk a list of visitors currently in a world to various coordinates.
|
|
128
|
-
*
|
|
129
|
-
* @usage
|
|
130
|
-
* ```ts
|
|
131
|
-
* const visitorsToMove = [
|
|
132
|
-
* {
|
|
133
|
-
* visitorObj: world.visitors["1"],
|
|
134
|
-
* shouldTeleportVisitor: true,
|
|
135
|
-
* x: 100,
|
|
136
|
-
* y: 100
|
|
137
|
-
* }, {
|
|
138
|
-
* visitorObj: world.visitors["2"],
|
|
139
|
-
* shouldTeleportVisitor: false,
|
|
140
|
-
* x: 100,
|
|
141
|
-
* y: 100
|
|
142
|
-
* }
|
|
143
|
-
* ];
|
|
144
|
-
* await world.moveVisitors(visitorsToMove);
|
|
145
|
-
* ```
|
|
146
|
-
*
|
|
147
|
-
* @result
|
|
148
|
-
* Updates each Visitor instance and world.visitors map.
|
|
149
|
-
*/
|
|
150
|
-
moveVisitors(visitorsToMove) {
|
|
151
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
const allPromises = [];
|
|
153
|
-
visitorsToMove.forEach((v) => {
|
|
154
|
-
allPromises.push(v.visitorObj.moveVisitor({ shouldTeleportVisitor: v.shouldTeleportVisitor, x: v.x, y: v.y }));
|
|
155
|
-
});
|
|
156
|
-
const outcomes = yield Promise.all(allPromises);
|
|
157
|
-
return outcomes;
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
_WorldActivity_visitorsMap = new WeakMap();
|
|
162
|
-
export default WorldActivity;
|
|
@@ -1,37 +0,0 @@
|
|
|
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,
|
|
19
|
-
apiKey: "exampleKey",
|
|
20
|
-
apiProtocol: "https",
|
|
21
|
-
interactiveKey: "key",
|
|
22
|
-
interactiveSecret: "secret",
|
|
23
|
-
});
|
|
24
|
-
mock = new MockAdapter(topia.axios);
|
|
25
|
-
Asset = new AssetFactory(topia);
|
|
26
|
-
testAsset = Asset.create("test");
|
|
27
|
-
}));
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
mock.restore();
|
|
30
|
-
jest.resetAllMocks();
|
|
31
|
-
});
|
|
32
|
-
it("should return an array of assets owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
mock.onGet(`https://${apiDomain}/api/v1/assets/topia-assets`).reply(200);
|
|
34
|
-
yield testAsset.fetchPlatformAssets();
|
|
35
|
-
expect(mock.history.get.length).toBe(1);
|
|
36
|
-
}));
|
|
37
|
-
});
|