@rtsdk/topia 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__mocks__/index.js +2 -0
- package/dist/__mocks__/visitors.js +56 -0
- package/dist/__mocks__/worlds.js +51 -0
- package/dist/controllers/World.js +122 -0
- package/dist/controllers/__tests__/world.test.js +111 -0
- package/dist/controllers/index.js +1 -0
- package/dist/index.js +150 -31
- package/dist/types/Visitor.js +1 -0
- package/dist/types/index.js +1 -0
- package/package.json +6 -3
- package/dist/index.test.js +0 -16
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export var visitors = {
|
|
2
|
+
"798": {
|
|
3
|
+
playerId: 798,
|
|
4
|
+
color: "0x7AD3BA",
|
|
5
|
+
moveTo: {
|
|
6
|
+
x: -1458,
|
|
7
|
+
y: -351
|
|
8
|
+
},
|
|
9
|
+
moveFrom: null,
|
|
10
|
+
username: "Lina",
|
|
11
|
+
sitting: false,
|
|
12
|
+
gestureType: 0,
|
|
13
|
+
performer: false,
|
|
14
|
+
performerNear: false,
|
|
15
|
+
shareScreen: false,
|
|
16
|
+
isBackground: false,
|
|
17
|
+
muted: true,
|
|
18
|
+
hidden: true,
|
|
19
|
+
newId: null,
|
|
20
|
+
displayName: "",
|
|
21
|
+
movedOn: null,
|
|
22
|
+
lastUpdate: 1669915215216,
|
|
23
|
+
isMobile: false,
|
|
24
|
+
token: "a92863e4-c21c-4270-a7ed-cdee2574e3ec",
|
|
25
|
+
isAdmin: false,
|
|
26
|
+
isRecording: false,
|
|
27
|
+
isRecordingBot: false
|
|
28
|
+
},
|
|
29
|
+
"799": {
|
|
30
|
+
playerId: 799,
|
|
31
|
+
color: "0xA0D2A7",
|
|
32
|
+
moveTo: {
|
|
33
|
+
x: -1504,
|
|
34
|
+
y: -260
|
|
35
|
+
},
|
|
36
|
+
moveFrom: null,
|
|
37
|
+
username: "Definitely Not Lina",
|
|
38
|
+
sitting: false,
|
|
39
|
+
gestureType: 0,
|
|
40
|
+
performer: false,
|
|
41
|
+
performerNear: false,
|
|
42
|
+
shareScreen: false,
|
|
43
|
+
isBackground: false,
|
|
44
|
+
muted: true,
|
|
45
|
+
hidden: true,
|
|
46
|
+
newId: null,
|
|
47
|
+
displayName: "",
|
|
48
|
+
movedOn: null,
|
|
49
|
+
lastUpdate: 1669915214590,
|
|
50
|
+
isMobile: false,
|
|
51
|
+
token: "23fecaae-6b55-4e98-9e0c-6f869bb19463",
|
|
52
|
+
isAdmin: false,
|
|
53
|
+
isRecording: false,
|
|
54
|
+
isRecordingBot: false
|
|
55
|
+
}
|
|
56
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var baseImageURL = "https://firebasestorage.googleapis.com/v0/b/topia-ba1c8.appspot.com/o/heroImages%";
|
|
2
|
+
export var worlds = [
|
|
3
|
+
{
|
|
4
|
+
description: "This is the a welcome lobby that anybody can enter to learn more about Topia.",
|
|
5
|
+
name: "Welcome",
|
|
6
|
+
heroImage: "".concat(baseImageURL, "2Fwelcome_banner.png?alt=media&token=548e1515-205e-4ef0-a0ca-bc4cc39c4f40"),
|
|
7
|
+
urlSlug: "welcome"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
background: null,
|
|
11
|
+
created: {
|
|
12
|
+
_seconds: 1605310924,
|
|
13
|
+
_nanoseconds: 165000000
|
|
14
|
+
},
|
|
15
|
+
controls: {
|
|
16
|
+
isShowingCurrentGuests: true,
|
|
17
|
+
hideShareScreen: false,
|
|
18
|
+
isZoneConversationHidden: false,
|
|
19
|
+
allowUserToTurnOnNotifications: true,
|
|
20
|
+
isPeerConversationHidden: false,
|
|
21
|
+
disableHideVideo: false,
|
|
22
|
+
isWorldConversationHidden: false,
|
|
23
|
+
allowUsersToTurnOnNotifications: true,
|
|
24
|
+
allowMuteAll: true,
|
|
25
|
+
isMobileDisabled: false
|
|
26
|
+
},
|
|
27
|
+
description: "A place to play, test, create scenes, and more!",
|
|
28
|
+
enforceWhitelistOnLogin: false,
|
|
29
|
+
forceAuthOnLogin: true,
|
|
30
|
+
height: 3096,
|
|
31
|
+
heroImage: "https://firebasestorage.googleapis.com/v0/b/topia-ba1c8.appspot.com/o/heroImages%2F2OB4pQL4b6ReyRfh6TOVJlx8vDz2-lina-1632521548284.png?alt=media&token=b95f15ac-f598-438e-95e8-4c048ec091a7",
|
|
32
|
+
mapExists: true,
|
|
33
|
+
name: "Lina's World",
|
|
34
|
+
redirectTo: null,
|
|
35
|
+
spawnPosition: {
|
|
36
|
+
radius: 100,
|
|
37
|
+
y: -348,
|
|
38
|
+
x: -1448
|
|
39
|
+
},
|
|
40
|
+
tileBackgroundEverywhere: null,
|
|
41
|
+
useTopiaPassword: false,
|
|
42
|
+
width: 4096
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
alt: "descriptive text for screen reader",
|
|
46
|
+
description: "Donec ullamcorper nulla non metus auctor fringilla. Donec ullamcorper nulla non metus auctor fringilla. Donec ullamcorper nulla non metus auctor fringilla",
|
|
47
|
+
name: "World Name that goes on for days",
|
|
48
|
+
heroImage: "https://bit.ly/2QdnMge",
|
|
49
|
+
urlSlug: "world-name-that-goes-on-forever-because-it-free"
|
|
50
|
+
},
|
|
51
|
+
];
|
|
@@ -0,0 +1,122 @@
|
|
|
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import axios from "axios";
|
|
38
|
+
var API_URL = "https://api.topia.io/api";
|
|
39
|
+
var World = /** @class */ (function () {
|
|
40
|
+
function World(apiKey, urlSlug) {
|
|
41
|
+
this.apiKey = apiKey;
|
|
42
|
+
this.urlSlug = urlSlug;
|
|
43
|
+
}
|
|
44
|
+
World.prototype.fetchDetails = function () {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
+
var _this = this;
|
|
47
|
+
return __generator(this, function (_a) {
|
|
48
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
49
|
+
axios
|
|
50
|
+
.get("".concat(API_URL, "/world/").concat(_this.urlSlug, "/world-details"), {
|
|
51
|
+
headers: { Authorization: _this.apiKey }
|
|
52
|
+
})
|
|
53
|
+
.then(function (response) {
|
|
54
|
+
resolve(response.data);
|
|
55
|
+
})["catch"](reject);
|
|
56
|
+
})];
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
World.prototype.fetchVisitors = function () {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
+
var _this = this;
|
|
63
|
+
return __generator(this, function (_a) {
|
|
64
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
65
|
+
axios
|
|
66
|
+
.get("".concat(API_URL, "/world/").concat(_this.urlSlug, "/visitors"), {
|
|
67
|
+
headers: { Authorization: _this.apiKey }
|
|
68
|
+
})
|
|
69
|
+
.then(function (response) {
|
|
70
|
+
resolve(response.data);
|
|
71
|
+
})["catch"](reject);
|
|
72
|
+
})];
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
World.prototype.moveVisitors = function (visitors) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
+
var allPromises, outcomes;
|
|
79
|
+
var _this = this;
|
|
80
|
+
return __generator(this, function (_a) {
|
|
81
|
+
switch (_a.label) {
|
|
82
|
+
case 0:
|
|
83
|
+
allPromises = [];
|
|
84
|
+
visitors.map(function (visitor) { return __awaiter(_this, void 0, void 0, function () {
|
|
85
|
+
var promise;
|
|
86
|
+
var _this = this;
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
promise = new Promise(function (resolve, reject) {
|
|
89
|
+
var requestOptions = {
|
|
90
|
+
headers: { Authorization: _this.apiKey },
|
|
91
|
+
body: {
|
|
92
|
+
moveTo: {
|
|
93
|
+
x: visitor.coordinates.x,
|
|
94
|
+
y: visitor.coordinates.y
|
|
95
|
+
},
|
|
96
|
+
teleport: true
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
axios
|
|
100
|
+
.put("".concat(API_URL, "/world/").concat(_this.urlSlug, "/visitors/").concat(visitor.id, "/move"), requestOptions)
|
|
101
|
+
.then(function (response) {
|
|
102
|
+
resolve(response.data);
|
|
103
|
+
})["catch"](reject);
|
|
104
|
+
});
|
|
105
|
+
allPromises.push(promise);
|
|
106
|
+
return [2 /*return*/];
|
|
107
|
+
});
|
|
108
|
+
}); });
|
|
109
|
+
return [4 /*yield*/, Promise.allSettled(allPromises)];
|
|
110
|
+
case 1:
|
|
111
|
+
outcomes = _a.sent();
|
|
112
|
+
// const succeeded = outcomes.filter((o) => o.status === "fulfilled");
|
|
113
|
+
// const failed = outcomes.filter((o) => o.status === "rejected");
|
|
114
|
+
return [2 /*return*/, outcomes];
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
return World;
|
|
120
|
+
}());
|
|
121
|
+
export { World };
|
|
122
|
+
export default World;
|
|
@@ -0,0 +1,111 @@
|
|
|
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { visitors, worlds } from "../../__mocks__";
|
|
38
|
+
import { World } from "../../controllers";
|
|
39
|
+
afterEach(function () {
|
|
40
|
+
jest.resetAllMocks();
|
|
41
|
+
});
|
|
42
|
+
describe("get world details", function () {
|
|
43
|
+
it("should return details of a world", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
44
|
+
var testWorld, mockDetails;
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
switch (_a.label) {
|
|
47
|
+
case 0: return [4 /*yield*/, new World("key", "lina")];
|
|
48
|
+
case 1:
|
|
49
|
+
testWorld = _a.sent();
|
|
50
|
+
testWorld.fetchDetails = jest.fn().mockReturnValue(worlds[1]);
|
|
51
|
+
return [4 /*yield*/, testWorld.fetchDetails()];
|
|
52
|
+
case 2:
|
|
53
|
+
mockDetails = _a.sent();
|
|
54
|
+
expect(testWorld.fetchDetails).toHaveBeenCalled();
|
|
55
|
+
expect(mockDetails).toBeDefined();
|
|
56
|
+
return [2 /*return*/];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}); });
|
|
60
|
+
});
|
|
61
|
+
describe("get and move visitors", function () {
|
|
62
|
+
it("should return a list of current visitors for a given world", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
63
|
+
var testWorld, mockVisitors;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
|
+
case 0: return [4 /*yield*/, new World("key", "lina")];
|
|
67
|
+
case 1:
|
|
68
|
+
testWorld = _a.sent();
|
|
69
|
+
testWorld.fetchVisitors = jest.fn().mockReturnValue(visitors);
|
|
70
|
+
return [4 /*yield*/, testWorld.fetchVisitors()];
|
|
71
|
+
case 2:
|
|
72
|
+
mockVisitors = _a.sent();
|
|
73
|
+
expect(testWorld.fetchVisitors).toHaveBeenCalled();
|
|
74
|
+
expect(mockVisitors).toBeDefined();
|
|
75
|
+
return [2 /*return*/];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}); });
|
|
79
|
+
it("should move a visitor to specified coordinates", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
+
var testWorld, visitors;
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
switch (_a.label) {
|
|
83
|
+
case 0: return [4 /*yield*/, new World("key", "lina")];
|
|
84
|
+
case 1:
|
|
85
|
+
testWorld = _a.sent();
|
|
86
|
+
testWorld.moveVisitors = jest.fn();
|
|
87
|
+
visitors = [
|
|
88
|
+
{
|
|
89
|
+
id: "1",
|
|
90
|
+
coordinates: {
|
|
91
|
+
x: 100,
|
|
92
|
+
y: 100
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: "2",
|
|
97
|
+
coordinates: {
|
|
98
|
+
x: 200,
|
|
99
|
+
y: 200
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
return [4 /*yield*/, testWorld.moveVisitors(visitors)];
|
|
104
|
+
case 2:
|
|
105
|
+
_a.sent();
|
|
106
|
+
expect(testWorld.moveVisitors).toHaveBeenCalled();
|
|
107
|
+
return [2 /*return*/];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}); });
|
|
111
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { World } from "./World";
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import require$$1 from 'util';
|
|
2
|
+
import stream from 'stream';
|
|
3
|
+
import require$$1$1 from 'path';
|
|
4
|
+
import require$$3 from 'http';
|
|
5
|
+
import require$$4 from 'https';
|
|
6
|
+
import require$$0$1 from 'url';
|
|
7
|
+
import require$$6 from 'fs';
|
|
8
|
+
import require$$4$1 from 'assert';
|
|
9
|
+
import require$$1$2 from 'tty';
|
|
10
|
+
import require$$0$2 from 'os';
|
|
11
|
+
import zlib from 'zlib';
|
|
12
|
+
import EventEmitter from 'events';
|
|
13
|
+
|
|
14
|
+
/******************************************************************************
|
|
15
|
+
Copyright (c) Microsoft Corporation.
|
|
16
|
+
|
|
17
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
18
|
+
purpose with or without fee is hereby granted.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
21
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
22
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
23
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
24
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
25
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
26
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
27
|
+
***************************************************************************** */
|
|
28
|
+
|
|
29
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
30
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
31
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
32
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
33
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
34
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
35
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function __generator(thisArg, body) {
|
|
40
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
41
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
42
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
43
|
+
function step(op) {
|
|
44
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
45
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
46
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
47
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
48
|
+
switch (op[0]) {
|
|
49
|
+
case 0: case 1: t = op; break;
|
|
50
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
51
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
52
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
53
|
+
default:
|
|
54
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
55
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
56
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
57
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
58
|
+
if (t[2]) _.ops.pop();
|
|
59
|
+
_.trys.pop(); continue;
|
|
60
|
+
}
|
|
61
|
+
op = body.call(thisArg, _);
|
|
62
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
63
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
17
66
|
|
|
18
67
|
function bind(fn, thisArg) {
|
|
19
68
|
return function wrap() {
|
|
@@ -17815,18 +17864,88 @@ axios.formToJSON = thing => {
|
|
|
17815
17864
|
return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
|
17816
17865
|
};
|
|
17817
17866
|
|
|
17818
|
-
|
|
17819
|
-
|
|
17820
|
-
|
|
17821
|
-
|
|
17822
|
-
|
|
17823
|
-
|
|
17824
|
-
|
|
17825
|
-
|
|
17826
|
-
|
|
17827
|
-
|
|
17828
|
-
|
|
17829
|
-
|
|
17830
|
-
|
|
17831
|
-
|
|
17832
|
-
|
|
17867
|
+
var API_URL = "https://api.topia.io/api";
|
|
17868
|
+
var World = /** @class */ (function () {
|
|
17869
|
+
function World(apiKey, urlSlug) {
|
|
17870
|
+
this.apiKey = apiKey;
|
|
17871
|
+
this.urlSlug = urlSlug;
|
|
17872
|
+
}
|
|
17873
|
+
World.prototype.fetchDetails = function () {
|
|
17874
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
17875
|
+
var _this = this;
|
|
17876
|
+
return __generator(this, function (_a) {
|
|
17877
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
17878
|
+
axios
|
|
17879
|
+
.get("".concat(API_URL, "/world/").concat(_this.urlSlug, "/world-details"), {
|
|
17880
|
+
headers: { Authorization: _this.apiKey }
|
|
17881
|
+
})
|
|
17882
|
+
.then(function (response) {
|
|
17883
|
+
resolve(response.data);
|
|
17884
|
+
})["catch"](reject);
|
|
17885
|
+
})];
|
|
17886
|
+
});
|
|
17887
|
+
});
|
|
17888
|
+
};
|
|
17889
|
+
World.prototype.fetchVisitors = function () {
|
|
17890
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
17891
|
+
var _this = this;
|
|
17892
|
+
return __generator(this, function (_a) {
|
|
17893
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
17894
|
+
axios
|
|
17895
|
+
.get("".concat(API_URL, "/world/").concat(_this.urlSlug, "/visitors"), {
|
|
17896
|
+
headers: { Authorization: _this.apiKey }
|
|
17897
|
+
})
|
|
17898
|
+
.then(function (response) {
|
|
17899
|
+
resolve(response.data);
|
|
17900
|
+
})["catch"](reject);
|
|
17901
|
+
})];
|
|
17902
|
+
});
|
|
17903
|
+
});
|
|
17904
|
+
};
|
|
17905
|
+
World.prototype.moveVisitors = function (visitors) {
|
|
17906
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
17907
|
+
var allPromises, outcomes;
|
|
17908
|
+
var _this = this;
|
|
17909
|
+
return __generator(this, function (_a) {
|
|
17910
|
+
switch (_a.label) {
|
|
17911
|
+
case 0:
|
|
17912
|
+
allPromises = [];
|
|
17913
|
+
visitors.map(function (visitor) { return __awaiter(_this, void 0, void 0, function () {
|
|
17914
|
+
var promise;
|
|
17915
|
+
var _this = this;
|
|
17916
|
+
return __generator(this, function (_a) {
|
|
17917
|
+
promise = new Promise(function (resolve, reject) {
|
|
17918
|
+
var requestOptions = {
|
|
17919
|
+
headers: { Authorization: _this.apiKey },
|
|
17920
|
+
body: {
|
|
17921
|
+
moveTo: {
|
|
17922
|
+
x: visitor.coordinates.x,
|
|
17923
|
+
y: visitor.coordinates.y
|
|
17924
|
+
},
|
|
17925
|
+
teleport: true
|
|
17926
|
+
}
|
|
17927
|
+
};
|
|
17928
|
+
axios
|
|
17929
|
+
.put("".concat(API_URL, "/world/").concat(_this.urlSlug, "/visitors/").concat(visitor.id, "/move"), requestOptions)
|
|
17930
|
+
.then(function (response) {
|
|
17931
|
+
resolve(response.data);
|
|
17932
|
+
})["catch"](reject);
|
|
17933
|
+
});
|
|
17934
|
+
allPromises.push(promise);
|
|
17935
|
+
return [2 /*return*/];
|
|
17936
|
+
});
|
|
17937
|
+
}); });
|
|
17938
|
+
return [4 /*yield*/, Promise.allSettled(allPromises)];
|
|
17939
|
+
case 1:
|
|
17940
|
+
outcomes = _a.sent();
|
|
17941
|
+
// const succeeded = outcomes.filter((o) => o.status === "fulfilled");
|
|
17942
|
+
// const failed = outcomes.filter((o) => o.status === "rejected");
|
|
17943
|
+
return [2 /*return*/, outcomes];
|
|
17944
|
+
}
|
|
17945
|
+
});
|
|
17946
|
+
});
|
|
17947
|
+
};
|
|
17948
|
+
return World;
|
|
17949
|
+
}());
|
|
17950
|
+
|
|
17951
|
+
export { World };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
},
|
|
6
6
|
"description": "MC Javascript SDK - Topia Client Library",
|
|
7
7
|
"devDependencies": {
|
|
8
|
+
"@rollup/plugin-alias": "^4.0.2",
|
|
8
9
|
"@rollup/plugin-commonjs": "^23.0.2",
|
|
9
10
|
"@rollup/plugin-json": "^5.0.1",
|
|
10
11
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
@@ -20,7 +21,8 @@
|
|
|
20
21
|
"rollup": "^3.4.0",
|
|
21
22
|
"rollup-plugin-typescript2": "^0.34.1",
|
|
22
23
|
"ts-jest": "^29.0.3",
|
|
23
|
-
"typescript": "^4.9.3"
|
|
24
|
+
"typescript": "^4.9.3",
|
|
25
|
+
"yalc": "^1.0.0-pre.53"
|
|
24
26
|
},
|
|
25
27
|
"files": [
|
|
26
28
|
"dist/*"
|
|
@@ -44,8 +46,9 @@
|
|
|
44
46
|
"build": "tsc && rollup -c",
|
|
45
47
|
"test": "ENV=testing jest --watchAll=false",
|
|
46
48
|
"lint": "eslint \"src/**\"",
|
|
47
|
-
"
|
|
49
|
+
"pkg": "npm publish",
|
|
50
|
+
"local-publish": "yarn build && yalc publish --push --no-scripts"
|
|
48
51
|
},
|
|
49
52
|
"type": "module",
|
|
50
|
-
"version": "0.0.
|
|
53
|
+
"version": "0.0.8"
|
|
51
54
|
}
|
package/dist/index.test.js
DELETED
|
@@ -1,16 +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 { getWorldDetails } from ".";
|
|
11
|
-
describe("getWorldDetails", () => {
|
|
12
|
-
it("should return details of a world", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
-
const result = yield getWorldDetails("lina");
|
|
14
|
-
expect(result).toBeDefined();
|
|
15
|
-
}));
|
|
16
|
-
});
|