@rtsdk/topia 0.0.25 → 0.0.27
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 +41039 -0
- package/dist/index.js +11 -7
- package/dist/src/__mocks__/visitors.js +3 -3
- package/dist/src/controllers/SDKController.js +1 -1
- package/dist/src/controllers/Topia.js +4 -3
- package/dist/src/controllers/User.js +1 -1
- package/dist/src/controllers/Visitor.js +4 -1
- package/dist/src/controllers/WorldActivity.js +2 -1
- package/dist/src/controllers/__tests__/asset.test.js +1 -0
- package/dist/src/controllers/__tests__/droppedAsset.test.js +1 -0
- package/dist/src/controllers/__tests__/scene.test.js +1 -0
- package/dist/src/controllers/__tests__/user.test.js +2 -1
- package/dist/src/controllers/__tests__/visitor.test.js +2 -1
- package/dist/src/controllers/__tests__/world.test.js +1 -0
- package/dist/src/controllers/__tests__/worldActivity.test.js +3 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -39735,7 +39735,7 @@ const {
|
|
|
39735
39735
|
* assetId: "exampleAsset",
|
|
39736
39736
|
* interactiveNonce: "exampleNonce"
|
|
39737
39737
|
* interactivePublicKey: "examplePublicKey",
|
|
39738
|
-
*
|
|
39738
|
+
* visitorId: 1,
|
|
39739
39739
|
* url: "https://topia.io",
|
|
39740
39740
|
* }
|
|
39741
39741
|
* const topia = await new Topia({
|
|
@@ -40545,7 +40545,7 @@ var _User_assetsMap, _User_scenesMap, _User_worldsMap;
|
|
|
40545
40545
|
*
|
|
40546
40546
|
* @usage
|
|
40547
40547
|
* ```ts
|
|
40548
|
-
* await new User(topia, { interactiveNonce: "exampleNonce", interactivePublicKey: "examplePublicKey",
|
|
40548
|
+
* await new User(topia, { interactiveNonce: "exampleNonce", interactivePublicKey: "examplePublicKey", visitorId: 1 });
|
|
40549
40549
|
* ```
|
|
40550
40550
|
*/
|
|
40551
40551
|
class User extends SDKController {
|
|
@@ -40682,9 +40682,12 @@ class Visitor extends User {
|
|
|
40682
40682
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40683
40683
|
try {
|
|
40684
40684
|
const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors/${this.id}`, this.requestOptions);
|
|
40685
|
-
if (((_a = response.data) === null || _a === void 0 ? void 0 : _a.
|
|
40685
|
+
if (((_a = response.data) === null || _a === void 0 ? void 0 : _a.visitorId) === this.id) {
|
|
40686
40686
|
Object.assign(this, response.data);
|
|
40687
40687
|
}
|
|
40688
|
+
else if (response.data[this.id]) {
|
|
40689
|
+
Object.assign(this, response.data[this.id]);
|
|
40690
|
+
}
|
|
40688
40691
|
else {
|
|
40689
40692
|
throw "This visitor is not active";
|
|
40690
40693
|
}
|
|
@@ -40758,7 +40761,7 @@ class WorldActivity extends SDKController {
|
|
|
40758
40761
|
// create temp map and then update private property only once
|
|
40759
40762
|
const tempVisitorsMap = {};
|
|
40760
40763
|
for (const id in response.data) {
|
|
40761
|
-
tempVisitorsMap[id] = new Visitor(this.topia, response.data[id].
|
|
40764
|
+
tempVisitorsMap[id] = new Visitor(this.topia, response.data[id].visitorId, this.urlSlug, {
|
|
40762
40765
|
attributes: response.data[id],
|
|
40763
40766
|
});
|
|
40764
40767
|
}
|
|
@@ -40879,10 +40882,11 @@ _WorldActivity_visitorsMap = new WeakMap();
|
|
|
40879
40882
|
* ```
|
|
40880
40883
|
*/
|
|
40881
40884
|
class Topia {
|
|
40882
|
-
constructor({ apiKey,
|
|
40885
|
+
constructor({ apiDomain, apiKey, apiProtocol, interactiveKey, interactiveSecret, }) {
|
|
40883
40886
|
getBrowserWarning();
|
|
40884
|
-
this.apiKey = apiKey;
|
|
40885
40887
|
this.apiDomain = apiDomain || "api.topia.io";
|
|
40888
|
+
this.apiKey = apiKey;
|
|
40889
|
+
this.apiProtocol = apiProtocol || "https";
|
|
40886
40890
|
this.interactiveSecret = interactiveSecret;
|
|
40887
40891
|
const headers = {
|
|
40888
40892
|
"ApplicationId": "sdk-js-topia",
|
|
@@ -40893,7 +40897,7 @@ class Topia {
|
|
|
40893
40897
|
if (interactiveKey)
|
|
40894
40898
|
headers.PublicKey = interactiveKey;
|
|
40895
40899
|
this.axios = axios.create({
|
|
40896
|
-
baseURL:
|
|
40900
|
+
baseURL: `${apiProtocol}://${this.apiDomain}/api/v1`,
|
|
40897
40901
|
headers,
|
|
40898
40902
|
});
|
|
40899
40903
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const visitor = {
|
|
2
|
-
|
|
2
|
+
visitorId: 1,
|
|
3
3
|
color: "0x7AD3BA",
|
|
4
4
|
moveTo: {
|
|
5
5
|
x: -1458,
|
|
@@ -27,7 +27,7 @@ export const visitor = {
|
|
|
27
27
|
};
|
|
28
28
|
export const visitors = {
|
|
29
29
|
"1": {
|
|
30
|
-
|
|
30
|
+
visitorId: 1,
|
|
31
31
|
color: "0x7AD3BA",
|
|
32
32
|
moveTo: {
|
|
33
33
|
x: -1458,
|
|
@@ -54,7 +54,7 @@ export const visitors = {
|
|
|
54
54
|
isRecordingBot: false,
|
|
55
55
|
},
|
|
56
56
|
"2": {
|
|
57
|
-
|
|
57
|
+
visitorId: 2,
|
|
58
58
|
color: "0xA0D2A7",
|
|
59
59
|
moveTo: {
|
|
60
60
|
x: -1504,
|
|
@@ -11,7 +11,7 @@ import { AxiosError } from "axios";
|
|
|
11
11
|
* assetId: "exampleAsset",
|
|
12
12
|
* interactiveNonce: "exampleNonce"
|
|
13
13
|
* interactivePublicKey: "examplePublicKey",
|
|
14
|
-
*
|
|
14
|
+
* visitorId: 1,
|
|
15
15
|
* url: "https://topia.io",
|
|
16
16
|
* }
|
|
17
17
|
* const topia = await new Topia({
|
|
@@ -16,10 +16,11 @@ import { getBrowserWarning } from "utils";
|
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
export class Topia {
|
|
19
|
-
constructor({ apiKey,
|
|
19
|
+
constructor({ apiDomain, apiKey, apiProtocol, interactiveKey, interactiveSecret, }) {
|
|
20
20
|
getBrowserWarning();
|
|
21
|
-
this.apiKey = apiKey;
|
|
22
21
|
this.apiDomain = apiDomain || "api.topia.io";
|
|
22
|
+
this.apiKey = apiKey;
|
|
23
|
+
this.apiProtocol = apiProtocol || "https";
|
|
23
24
|
this.interactiveSecret = interactiveSecret;
|
|
24
25
|
const headers = {
|
|
25
26
|
"ApplicationId": "sdk-js-topia",
|
|
@@ -30,7 +31,7 @@ export class Topia {
|
|
|
30
31
|
if (interactiveKey)
|
|
31
32
|
headers.PublicKey = interactiveKey;
|
|
32
33
|
this.axios = axios.create({
|
|
33
|
-
baseURL:
|
|
34
|
+
baseURL: `${apiProtocol}://${this.apiDomain}/api/v1`,
|
|
34
35
|
headers,
|
|
35
36
|
});
|
|
36
37
|
}
|
|
@@ -30,7 +30,7 @@ import { World } from "controllers/World";
|
|
|
30
30
|
*
|
|
31
31
|
* @usage
|
|
32
32
|
* ```ts
|
|
33
|
-
* await new User(topia, { interactiveNonce: "exampleNonce", interactivePublicKey: "examplePublicKey",
|
|
33
|
+
* await new User(topia, { interactiveNonce: "exampleNonce", interactivePublicKey: "examplePublicKey", visitorId: 1 });
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
36
|
export class User extends SDKController {
|
|
@@ -41,9 +41,12 @@ export class Visitor extends User {
|
|
|
41
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
42
|
try {
|
|
43
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.
|
|
44
|
+
if (((_a = response.data) === null || _a === void 0 ? void 0 : _a.visitorId) === this.id) {
|
|
45
45
|
Object.assign(this, response.data);
|
|
46
46
|
}
|
|
47
|
+
else if (response.data[this.id]) {
|
|
48
|
+
Object.assign(this, response.data[this.id]);
|
|
49
|
+
}
|
|
47
50
|
else {
|
|
48
51
|
throw "This visitor is not active";
|
|
49
52
|
}
|
|
@@ -19,6 +19,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
19
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
20
|
};
|
|
21
21
|
var _WorldActivity_visitorsMap;
|
|
22
|
+
// controllers
|
|
22
23
|
import { SDKController } from "controllers/SDKController";
|
|
23
24
|
import { Visitor } from "controllers/Visitor";
|
|
24
25
|
// utils
|
|
@@ -52,7 +53,7 @@ export class WorldActivity extends SDKController {
|
|
|
52
53
|
// create temp map and then update private property only once
|
|
53
54
|
const tempVisitorsMap = {};
|
|
54
55
|
for (const id in response.data) {
|
|
55
|
-
tempVisitorsMap[id] = new Visitor(this.topia, response.data[id].
|
|
56
|
+
tempVisitorsMap[id] = new Visitor(this.topia, response.data[id].visitorId, this.urlSlug, {
|
|
56
57
|
attributes: response.data[id],
|
|
57
58
|
});
|
|
58
59
|
}
|
|
@@ -11,13 +11,14 @@ import MockAdapter from "axios-mock-adapter";
|
|
|
11
11
|
import { droppedAssets, scenes, worlds } from "__mocks__";
|
|
12
12
|
import { Topia } from "controllers";
|
|
13
13
|
import { UserFactory } from "factories";
|
|
14
|
-
const apiDomain = "api.topia.io";
|
|
14
|
+
const apiDomain = "api-stage.topia.io";
|
|
15
15
|
describe("User Class", () => {
|
|
16
16
|
let mock, testUser, topia, User;
|
|
17
17
|
beforeEach(() => {
|
|
18
18
|
topia = new Topia({
|
|
19
19
|
apiDomain,
|
|
20
20
|
apiKey: "key",
|
|
21
|
+
apiProtocol: "https",
|
|
21
22
|
});
|
|
22
23
|
mock = new MockAdapter(topia.axios);
|
|
23
24
|
User = new UserFactory(topia);
|
|
@@ -12,7 +12,7 @@ import { visitor } from "__mocks__";
|
|
|
12
12
|
import { Topia } from "controllers";
|
|
13
13
|
import { VisitorFactory } from "factories";
|
|
14
14
|
const apiDomain = "api.topia.io";
|
|
15
|
-
const id = visitor.
|
|
15
|
+
const id = visitor.visitorId;
|
|
16
16
|
const urlSlug = "exampleWorld";
|
|
17
17
|
describe("Visitor Class", () => {
|
|
18
18
|
let mock, testVisitor, topia, Visitor;
|
|
@@ -20,6 +20,7 @@ describe("Visitor Class", () => {
|
|
|
20
20
|
topia = new Topia({
|
|
21
21
|
apiDomain,
|
|
22
22
|
apiKey: "key",
|
|
23
|
+
apiProtocol: "https",
|
|
23
24
|
});
|
|
24
25
|
mock = new MockAdapter(topia.axios);
|
|
25
26
|
Visitor = new VisitorFactory(topia);
|
|
@@ -19,6 +19,7 @@ describe("WorldActivity Class", () => {
|
|
|
19
19
|
topia = new Topia({
|
|
20
20
|
apiDomain: "api.topia.io",
|
|
21
21
|
apiKey: "key",
|
|
22
|
+
apiProtocol: "https",
|
|
22
23
|
});
|
|
23
24
|
mock = new MockAdapter(topia.axios);
|
|
24
25
|
WorldActivity = new WorldActivityFactory(topia);
|
|
@@ -50,8 +51,8 @@ describe("WorldActivity Class", () => {
|
|
|
50
51
|
it("should move a list of visitors to uniquely specified coordinates", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
52
|
mock.onPut(`${BASE_URL}/visitors/1/move`).reply(200);
|
|
52
53
|
mock.onPut(`${BASE_URL}/visitors/2/move`).reply(200);
|
|
53
|
-
const v1 = new Visitor(topia, visitors["1"].
|
|
54
|
-
const v2 = new Visitor(topia, visitors["2"].
|
|
54
|
+
const v1 = new Visitor(topia, visitors["1"].visitorId, urlSlug, { attributes: visitors["1"] });
|
|
55
|
+
const v2 = new Visitor(topia, visitors["2"].visitorId, urlSlug, { attributes: visitors["2"] });
|
|
55
56
|
const testVisitors = [
|
|
56
57
|
{ visitorObj: v1, shouldTeleportVisitor: true, x: 0, y: 0 },
|
|
57
58
|
{ visitorObj: v2, shouldTeleportVisitor: false, x: 100, y: 100 },
|
package/package.json
CHANGED