@rtsdk/topia 0.0.8 → 0.0.9
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__/assets.js +241 -0
- package/dist/__mocks__/index.js +2 -0
- package/dist/__mocks__/scenes.js +104 -0
- package/dist/__mocks__/visitors.js +43 -16
- package/dist/__mocks__/worlds.js +9 -9
- package/dist/controllers/Asset.js +62 -0
- package/dist/controllers/DroppedAsset.js +150 -0
- package/dist/controllers/Scene.js +22 -0
- package/dist/controllers/Visitor.js +70 -0
- package/dist/controllers/World.js +125 -110
- package/dist/controllers/__tests__/asset.test.js +14 -0
- package/dist/controllers/__tests__/droppedAsset.test.js +109 -0
- package/dist/controllers/__tests__/scene.test.js +14 -0
- package/dist/controllers/__tests__/visitor.test.js +12 -0
- package/dist/controllers/__tests__/world.test.js +48 -109
- package/dist/controllers/index.js +4 -0
- package/dist/index.js +448 -125
- package/dist/{types/Visitor.js → interfaces/DroppedAssetInterfaces.js} +0 -0
- package/dist/interfaces/WorldInterfaces.js +1 -0
- package/dist/interfaces/index.js +2 -0
- package/dist/types/DroppedAssetType.js +1 -0
- package/dist/types/DroppedAssetTypes.js +12 -0
- package/dist/types/VisitorType.js +1 -0
- package/dist/types/VisitorTypes.js +1 -0
- package/dist/types/Visitors.js +1 -0
- package/dist/types/index.js +2 -1
- package/dist/utils/__tests__/scatterVisitors.test.js +11 -0
- package/dist/utils/createDroppedAsset.js +72 -0
- package/dist/utils/createVisitor.js +3 -0
- package/dist/utils/getErrorMessage.js +5 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/publicAPI.js +11 -0
- package/dist/utils/scatterVisitors.js +5 -0
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -11,58 +11,15 @@ import require$$0$2 from 'os';
|
|
|
11
11
|
import zlib from 'zlib';
|
|
12
12
|
import EventEmitter from 'events';
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
}
|
|
14
|
+
const createVisitor = (Visitor, apiKey, data, urlSlug) => {
|
|
15
|
+
return new Visitor(apiKey, data.color, data.displayName, data.gestureType, data.hidden, data.isAdmin, data.isBackground, data.isMobile, data.isRecording, data.isRecordingBot, data.lastUpdate, data.moveFrom, data.movedOn, data.moveTo, data.muted, data.performer, data.performerNear, data.playerId, data.shareScreen, data.sitting, urlSlug, data.username);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const getErrorMessage = (error) => {
|
|
19
|
+
console.log("🚀 ~ file: getErrorMessage.ts:2 ~ getErrorMessage ~ error", error);
|
|
20
|
+
const errorMessage = error?.response?.data?.errors[0]?.message;
|
|
21
|
+
return errorMessage || "Something went wrong. Please try again or contact support.";
|
|
22
|
+
};
|
|
66
23
|
|
|
67
24
|
function bind(fn, thisArg) {
|
|
68
25
|
return function wrap() {
|
|
@@ -17864,88 +17821,454 @@ axios.formToJSON = thing => {
|
|
|
17864
17821
|
return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
|
17865
17822
|
};
|
|
17866
17823
|
|
|
17867
|
-
|
|
17868
|
-
|
|
17869
|
-
|
|
17824
|
+
const publicAPI = (apiKey) => {
|
|
17825
|
+
return axios.create({
|
|
17826
|
+
baseURL: "https://api.topia.io/api",
|
|
17827
|
+
headers: {
|
|
17828
|
+
"Accept-Encoding": "",
|
|
17829
|
+
"Authorization": apiKey,
|
|
17830
|
+
"Content-Type": "application/json",
|
|
17831
|
+
},
|
|
17832
|
+
});
|
|
17833
|
+
};
|
|
17834
|
+
|
|
17835
|
+
const scatterVisitors = (original, scatterBy) => {
|
|
17836
|
+
const min = original - scatterBy;
|
|
17837
|
+
const max = original + scatterBy;
|
|
17838
|
+
return Math.floor(Math.random() * (max - min) + min);
|
|
17839
|
+
};
|
|
17840
|
+
|
|
17841
|
+
class Asset {
|
|
17842
|
+
addedOn;
|
|
17843
|
+
apiKey;
|
|
17844
|
+
assetName;
|
|
17845
|
+
creatorTags;
|
|
17846
|
+
id;
|
|
17847
|
+
isPublic;
|
|
17848
|
+
kitId;
|
|
17849
|
+
layer0;
|
|
17850
|
+
layer1;
|
|
17851
|
+
library;
|
|
17852
|
+
originalAssetId;
|
|
17853
|
+
originalKit;
|
|
17854
|
+
ownerId;
|
|
17855
|
+
ownerName;
|
|
17856
|
+
platformAsset;
|
|
17857
|
+
purchased;
|
|
17858
|
+
purchaseDate;
|
|
17859
|
+
purchasedFrom;
|
|
17860
|
+
specialType;
|
|
17861
|
+
transactionId;
|
|
17862
|
+
type;
|
|
17863
|
+
urlSlug;
|
|
17864
|
+
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 = "") {
|
|
17865
|
+
this.addedOn = addedOn;
|
|
17870
17866
|
this.apiKey = apiKey;
|
|
17867
|
+
this.assetName = assetName;
|
|
17868
|
+
this.creatorTags = creatorTags;
|
|
17869
|
+
this.id = id;
|
|
17870
|
+
this.isPublic = isPublic;
|
|
17871
|
+
this.kitId = kitId;
|
|
17872
|
+
this.layer0 = layer0;
|
|
17873
|
+
this.layer1 = layer1;
|
|
17874
|
+
this.library = library;
|
|
17875
|
+
this.originalAssetId = originalAssetId;
|
|
17876
|
+
this.originalKit = originalKit;
|
|
17877
|
+
this.ownerId = ownerId;
|
|
17878
|
+
this.ownerName = ownerName;
|
|
17879
|
+
this.platformAsset = platformAsset;
|
|
17880
|
+
this.purchased = purchased;
|
|
17881
|
+
this.purchaseDate = purchaseDate;
|
|
17882
|
+
this.purchasedFrom = purchasedFrom;
|
|
17883
|
+
this.specialType = specialType;
|
|
17884
|
+
this.transactionId = transactionId;
|
|
17885
|
+
this.type = type;
|
|
17871
17886
|
this.urlSlug = urlSlug;
|
|
17872
17887
|
}
|
|
17873
|
-
|
|
17874
|
-
return
|
|
17875
|
-
|
|
17876
|
-
|
|
17877
|
-
|
|
17878
|
-
|
|
17879
|
-
|
|
17880
|
-
|
|
17881
|
-
|
|
17882
|
-
.then(function (response) {
|
|
17883
|
-
resolve(response.data);
|
|
17884
|
-
})["catch"](reject);
|
|
17885
|
-
})];
|
|
17888
|
+
fetchAssetsByEmail(ownerEmail) {
|
|
17889
|
+
return new Promise((resolve, reject) => {
|
|
17890
|
+
publicAPI(this.apiKey)
|
|
17891
|
+
.get(`/assets/my-assets?email=${ownerEmail}`)
|
|
17892
|
+
.then((response) => {
|
|
17893
|
+
resolve(response.data);
|
|
17894
|
+
})
|
|
17895
|
+
.catch((error) => {
|
|
17896
|
+
reject(new Error(getErrorMessage(error)));
|
|
17886
17897
|
});
|
|
17887
17898
|
});
|
|
17888
|
-
}
|
|
17889
|
-
|
|
17890
|
-
|
|
17891
|
-
|
|
17892
|
-
|
|
17893
|
-
|
|
17894
|
-
|
|
17895
|
-
|
|
17896
|
-
|
|
17897
|
-
|
|
17898
|
-
|
|
17899
|
-
|
|
17900
|
-
|
|
17901
|
-
|
|
17899
|
+
}
|
|
17900
|
+
}
|
|
17901
|
+
|
|
17902
|
+
class DroppedAsset extends Asset {
|
|
17903
|
+
apiKey;
|
|
17904
|
+
text;
|
|
17905
|
+
urlSlug;
|
|
17906
|
+
// TODO: should we explicitly declare each or simplify with Object.assign for all optional properties? (kinda breaks the ts rules but looks so much nicer!)
|
|
17907
|
+
constructor(apiKey, args, text, urlSlug) {
|
|
17908
|
+
super(args.addedOn, apiKey, args.assetName, args.creatorTags, args.id, args.isPublic, args.kitId, args.layer0, args.layer1, args.library, args.originalAssetId, args.originalKit, args.ownerId, args.ownerName, args.platformAsset, args.purchased, args.purchaseDate, args.purchasedFrom, args.specialType, args.transactionId, args.type, urlSlug);
|
|
17909
|
+
this.apiKey = apiKey;
|
|
17910
|
+
this.text = text;
|
|
17911
|
+
this.urlSlug = urlSlug;
|
|
17912
|
+
Object.assign(this, args);
|
|
17913
|
+
this.updateCustomText;
|
|
17914
|
+
}
|
|
17915
|
+
// get dropped asset
|
|
17916
|
+
fetchDroppedAssetById() {
|
|
17917
|
+
return new Promise((resolve, reject) => {
|
|
17918
|
+
publicAPI(this.apiKey)
|
|
17919
|
+
.get(`/world/${this.urlSlug}/assets/${this.id}`)
|
|
17920
|
+
.then((response) => {
|
|
17921
|
+
Object.assign(this, response.data);
|
|
17922
|
+
resolve("Success!");
|
|
17923
|
+
})
|
|
17924
|
+
.catch((error) => {
|
|
17925
|
+
reject(new Error(getErrorMessage(error)));
|
|
17926
|
+
});
|
|
17927
|
+
});
|
|
17928
|
+
}
|
|
17929
|
+
// delete dropped asset
|
|
17930
|
+
deleteDroppedAsset() {
|
|
17931
|
+
return new Promise((resolve, reject) => {
|
|
17932
|
+
publicAPI(this.apiKey)
|
|
17933
|
+
.delete(`/world/${this.urlSlug}/assets/${this.id}`)
|
|
17934
|
+
.then(() => {
|
|
17935
|
+
resolve("Success!");
|
|
17936
|
+
})
|
|
17937
|
+
.catch((error) => {
|
|
17938
|
+
reject(new Error(getErrorMessage(error)));
|
|
17939
|
+
});
|
|
17940
|
+
});
|
|
17941
|
+
}
|
|
17942
|
+
// update dropped assets
|
|
17943
|
+
#updateDroppedAsset = (payload, updateType) => {
|
|
17944
|
+
console.log("apiKey", this.apiKey);
|
|
17945
|
+
return new Promise((resolve, reject) => {
|
|
17946
|
+
publicAPI(this.apiKey)
|
|
17947
|
+
.put(`/world/${this.urlSlug}/assets/${this.id}/${updateType}`, {
|
|
17948
|
+
...payload,
|
|
17949
|
+
})
|
|
17950
|
+
.then(() => {
|
|
17951
|
+
resolve("Success!");
|
|
17952
|
+
})
|
|
17953
|
+
.catch((error) => {
|
|
17954
|
+
reject(new Error(getErrorMessage(error)));
|
|
17902
17955
|
});
|
|
17903
17956
|
});
|
|
17904
17957
|
};
|
|
17905
|
-
|
|
17906
|
-
return
|
|
17907
|
-
|
|
17908
|
-
|
|
17909
|
-
|
|
17910
|
-
|
|
17911
|
-
|
|
17912
|
-
|
|
17913
|
-
|
|
17914
|
-
|
|
17915
|
-
|
|
17916
|
-
|
|
17917
|
-
|
|
17918
|
-
|
|
17919
|
-
|
|
17920
|
-
|
|
17921
|
-
|
|
17922
|
-
|
|
17923
|
-
|
|
17924
|
-
|
|
17925
|
-
|
|
17926
|
-
|
|
17927
|
-
|
|
17928
|
-
|
|
17929
|
-
|
|
17930
|
-
|
|
17931
|
-
|
|
17932
|
-
|
|
17933
|
-
|
|
17934
|
-
|
|
17935
|
-
|
|
17936
|
-
|
|
17937
|
-
|
|
17938
|
-
|
|
17939
|
-
|
|
17940
|
-
|
|
17941
|
-
|
|
17942
|
-
|
|
17943
|
-
|
|
17958
|
+
updateBroadcast({ assetBroadcast, assetBroadcastAll, broadcasterEmail }) {
|
|
17959
|
+
return new Promise((resolve, reject) => {
|
|
17960
|
+
return this.#updateDroppedAsset({ assetBroadcast, assetBroadcastAll, broadcasterEmail }, "set-asset-broadcast")
|
|
17961
|
+
.then(resolve)
|
|
17962
|
+
.catch((error) => {
|
|
17963
|
+
reject(new Error(getErrorMessage(error)));
|
|
17964
|
+
});
|
|
17965
|
+
});
|
|
17966
|
+
}
|
|
17967
|
+
updateClickType({ clickType, clickableLink, clickableLinkTitle, portalName, position, }) {
|
|
17968
|
+
return new Promise((resolve, reject) => {
|
|
17969
|
+
return this.#updateDroppedAsset({ clickType, clickableLink, clickableLinkTitle, portalName, position }, "change-click-type")
|
|
17970
|
+
.then(resolve)
|
|
17971
|
+
.catch((error) => {
|
|
17972
|
+
reject(new Error(getErrorMessage(error)));
|
|
17973
|
+
});
|
|
17974
|
+
});
|
|
17975
|
+
}
|
|
17976
|
+
updateCustomText(style, text) {
|
|
17977
|
+
return new Promise((resolve, reject) => {
|
|
17978
|
+
return this.#updateDroppedAsset({ style, text }, "set-custom-text")
|
|
17979
|
+
.then(resolve)
|
|
17980
|
+
.catch((error) => {
|
|
17981
|
+
reject(new Error(getErrorMessage(error)));
|
|
17982
|
+
});
|
|
17983
|
+
});
|
|
17984
|
+
}
|
|
17985
|
+
updateMediaType({ audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia, }) {
|
|
17986
|
+
return new Promise((resolve, reject) => {
|
|
17987
|
+
return this.#updateDroppedAsset({ audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia }, "change-media-type")
|
|
17988
|
+
.then(resolve)
|
|
17989
|
+
.catch((error) => {
|
|
17990
|
+
reject(new Error(getErrorMessage(error)));
|
|
17991
|
+
});
|
|
17992
|
+
});
|
|
17993
|
+
}
|
|
17994
|
+
updateMuteZone(isMutezone) {
|
|
17995
|
+
return new Promise((resolve, reject) => {
|
|
17996
|
+
return this.#updateDroppedAsset({ isMutezone }, "set-mute-zone")
|
|
17997
|
+
.then(resolve)
|
|
17998
|
+
.catch((error) => {
|
|
17999
|
+
reject(new Error(getErrorMessage(error)));
|
|
18000
|
+
});
|
|
18001
|
+
});
|
|
18002
|
+
}
|
|
18003
|
+
updatePosition(x, y) {
|
|
18004
|
+
return new Promise((resolve, reject) => {
|
|
18005
|
+
return this.#updateDroppedAsset({ x, y }, "set-position")
|
|
18006
|
+
.then(resolve)
|
|
18007
|
+
.catch((error) => {
|
|
18008
|
+
reject(new Error(getErrorMessage(error)));
|
|
18009
|
+
});
|
|
18010
|
+
});
|
|
18011
|
+
}
|
|
18012
|
+
updatePrivateZone({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap, }) {
|
|
18013
|
+
return new Promise((resolve, reject) => {
|
|
18014
|
+
return this.#updateDroppedAsset({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap }, "set-private-zone")
|
|
18015
|
+
.then(resolve)
|
|
18016
|
+
.catch((error) => {
|
|
18017
|
+
reject(new Error(getErrorMessage(error)));
|
|
18018
|
+
});
|
|
18019
|
+
});
|
|
18020
|
+
}
|
|
18021
|
+
updateScale(assetScale) {
|
|
18022
|
+
return new Promise((resolve, reject) => {
|
|
18023
|
+
return this.#updateDroppedAsset({ assetScale }, "change-scale")
|
|
18024
|
+
.then(resolve)
|
|
18025
|
+
.catch((error) => {
|
|
18026
|
+
reject(new Error(getErrorMessage(error)));
|
|
18027
|
+
});
|
|
18028
|
+
});
|
|
18029
|
+
}
|
|
18030
|
+
updateUploadedMediaSelected(mediaId) {
|
|
18031
|
+
return new Promise((resolve, reject) => {
|
|
18032
|
+
return this.#updateDroppedAsset({ mediaId }, "change-uploaded-media-selected")
|
|
18033
|
+
.then(resolve)
|
|
18034
|
+
.catch((error) => {
|
|
18035
|
+
reject(new Error(getErrorMessage(error)));
|
|
18036
|
+
});
|
|
18037
|
+
});
|
|
18038
|
+
}
|
|
18039
|
+
updateWebImageLayers(bottom, top) {
|
|
18040
|
+
return new Promise((resolve, reject) => {
|
|
18041
|
+
return this.#updateDroppedAsset({ bottom, top }, "set-webimage-layers")
|
|
18042
|
+
.then(resolve)
|
|
18043
|
+
.catch((error) => {
|
|
18044
|
+
reject(new Error(getErrorMessage(error)));
|
|
18045
|
+
});
|
|
18046
|
+
});
|
|
18047
|
+
}
|
|
18048
|
+
}
|
|
18049
|
+
|
|
18050
|
+
class Scene {
|
|
18051
|
+
apiKey;
|
|
18052
|
+
email;
|
|
18053
|
+
constructor(apiKey, email) {
|
|
18054
|
+
this.apiKey = apiKey;
|
|
18055
|
+
this.email = email;
|
|
18056
|
+
}
|
|
18057
|
+
fetchScenesByEmail() {
|
|
18058
|
+
return new Promise((resolve, reject) => {
|
|
18059
|
+
publicAPI(this.apiKey)
|
|
18060
|
+
.get(`/scenes/my-scenes?email=${this.email}`)
|
|
18061
|
+
.then((response) => {
|
|
18062
|
+
resolve(response.data);
|
|
18063
|
+
})
|
|
18064
|
+
.catch((error) => {
|
|
18065
|
+
reject(new Error(getErrorMessage(error)));
|
|
18066
|
+
});
|
|
18067
|
+
});
|
|
18068
|
+
}
|
|
18069
|
+
}
|
|
18070
|
+
|
|
18071
|
+
class Visitor {
|
|
18072
|
+
apiKey;
|
|
18073
|
+
color;
|
|
18074
|
+
displayName;
|
|
18075
|
+
gestureType;
|
|
18076
|
+
hidden;
|
|
18077
|
+
isAdmin;
|
|
18078
|
+
isBackground;
|
|
18079
|
+
isMobile;
|
|
18080
|
+
isRecording;
|
|
18081
|
+
isRecordingBot;
|
|
18082
|
+
lastUpdate;
|
|
18083
|
+
moveFrom;
|
|
18084
|
+
movedOn;
|
|
18085
|
+
moveTo;
|
|
18086
|
+
muted;
|
|
18087
|
+
performer;
|
|
18088
|
+
performerNear;
|
|
18089
|
+
playerId;
|
|
18090
|
+
shareScreen;
|
|
18091
|
+
sitting;
|
|
18092
|
+
urlSlug;
|
|
18093
|
+
username;
|
|
18094
|
+
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) {
|
|
18095
|
+
this.apiKey = apiKey;
|
|
18096
|
+
this.color = color;
|
|
18097
|
+
this.displayName = displayName;
|
|
18098
|
+
this.gestureType = gestureType;
|
|
18099
|
+
this.hidden = hidden;
|
|
18100
|
+
this.isAdmin = isAdmin;
|
|
18101
|
+
this.isBackground = isBackground;
|
|
18102
|
+
this.isMobile = isMobile;
|
|
18103
|
+
this.isRecording = isRecording;
|
|
18104
|
+
this.isRecordingBot = isRecordingBot;
|
|
18105
|
+
this.lastUpdate = lastUpdate;
|
|
18106
|
+
this.moveFrom = moveFrom;
|
|
18107
|
+
this.movedOn = movedOn;
|
|
18108
|
+
this.moveTo = moveTo;
|
|
18109
|
+
this.muted = muted;
|
|
18110
|
+
this.performer = performer;
|
|
18111
|
+
this.performerNear = performerNear;
|
|
18112
|
+
this.playerId = playerId;
|
|
18113
|
+
this.shareScreen = shareScreen;
|
|
18114
|
+
this.sitting = sitting;
|
|
18115
|
+
this.urlSlug = urlSlug;
|
|
18116
|
+
this.username = username;
|
|
18117
|
+
this.moveVisitor;
|
|
18118
|
+
}
|
|
18119
|
+
moveVisitor(shouldTeleportVisitor, x, y) {
|
|
18120
|
+
return new Promise((resolve, reject) => {
|
|
18121
|
+
publicAPI(this.apiKey)
|
|
18122
|
+
.put(`/world/${this.urlSlug}/visitors/${this.playerId}/move`, {
|
|
18123
|
+
moveTo: {
|
|
18124
|
+
x,
|
|
18125
|
+
y,
|
|
18126
|
+
},
|
|
18127
|
+
teleport: shouldTeleportVisitor,
|
|
18128
|
+
})
|
|
18129
|
+
.then(() => {
|
|
18130
|
+
this.moveTo = { x, y };
|
|
18131
|
+
resolve("Success!");
|
|
18132
|
+
})
|
|
18133
|
+
.catch((error) => {
|
|
18134
|
+
reject(new Error(getErrorMessage(error)));
|
|
18135
|
+
});
|
|
18136
|
+
});
|
|
18137
|
+
}
|
|
18138
|
+
}
|
|
18139
|
+
|
|
18140
|
+
class World {
|
|
18141
|
+
#droppedAssetsMap;
|
|
18142
|
+
#visitorsMap;
|
|
18143
|
+
apiKey;
|
|
18144
|
+
background;
|
|
18145
|
+
controls;
|
|
18146
|
+
created;
|
|
18147
|
+
description;
|
|
18148
|
+
enforceWhitelistOnLogin;
|
|
18149
|
+
forceAuthOnLogin;
|
|
18150
|
+
height;
|
|
18151
|
+
heroImage;
|
|
18152
|
+
mapExists;
|
|
18153
|
+
name;
|
|
18154
|
+
redirectTo;
|
|
18155
|
+
spawnPosition;
|
|
18156
|
+
tileBackgroundEverywhere;
|
|
18157
|
+
urlSlug;
|
|
18158
|
+
useTopiaPassword;
|
|
18159
|
+
width;
|
|
18160
|
+
get droppedAssets() {
|
|
18161
|
+
return this.#droppedAssetsMap;
|
|
18162
|
+
}
|
|
18163
|
+
get visitors() {
|
|
18164
|
+
return this.#visitorsMap;
|
|
18165
|
+
}
|
|
18166
|
+
constructor(apiKey, urlSlug) {
|
|
18167
|
+
this.apiKey = apiKey;
|
|
18168
|
+
this.urlSlug = urlSlug;
|
|
18169
|
+
}
|
|
18170
|
+
// world details
|
|
18171
|
+
fetchDetails() {
|
|
18172
|
+
return new Promise((resolve, reject) => {
|
|
18173
|
+
publicAPI(this.apiKey)
|
|
18174
|
+
.get(`/world/${this.urlSlug}/world-details`)
|
|
18175
|
+
.then((response) => {
|
|
18176
|
+
Object.assign(this, response.data);
|
|
18177
|
+
resolve("Success!");
|
|
18178
|
+
})
|
|
18179
|
+
.catch((error) => {
|
|
18180
|
+
reject(new Error(getErrorMessage(error)));
|
|
18181
|
+
});
|
|
18182
|
+
});
|
|
18183
|
+
}
|
|
18184
|
+
updateDetails() {
|
|
18185
|
+
return new Promise((resolve, reject) => {
|
|
18186
|
+
publicAPI(this.apiKey)
|
|
18187
|
+
.get(`/world/${this.urlSlug}/world-details`)
|
|
18188
|
+
.then(() => {
|
|
18189
|
+
resolve("Success!");
|
|
18190
|
+
})
|
|
18191
|
+
.catch((error) => {
|
|
18192
|
+
reject(new Error(getErrorMessage(error)));
|
|
18193
|
+
});
|
|
18194
|
+
});
|
|
18195
|
+
}
|
|
18196
|
+
// visitors
|
|
18197
|
+
fetchVisitors() {
|
|
18198
|
+
return new Promise((resolve, reject) => {
|
|
18199
|
+
publicAPI(this.apiKey)
|
|
18200
|
+
.get(`/world/${this.urlSlug}/visitors`)
|
|
18201
|
+
.then((response) => {
|
|
18202
|
+
// create temp map and then update private property only once
|
|
18203
|
+
const tempVisitorsMap = {};
|
|
18204
|
+
for (const playerId in response.data) {
|
|
18205
|
+
tempVisitorsMap[playerId] = createVisitor(Visitor, this.apiKey, response.data[playerId], this.urlSlug);
|
|
17944
18206
|
}
|
|
18207
|
+
this.#visitorsMap = tempVisitorsMap;
|
|
18208
|
+
resolve("Success!");
|
|
18209
|
+
})
|
|
18210
|
+
.catch((error) => {
|
|
18211
|
+
reject(new Error(getErrorMessage(error)));
|
|
17945
18212
|
});
|
|
17946
18213
|
});
|
|
17947
|
-
}
|
|
17948
|
-
|
|
17949
|
-
|
|
18214
|
+
}
|
|
18215
|
+
async currentVisitors() {
|
|
18216
|
+
try {
|
|
18217
|
+
await this.fetchVisitors();
|
|
18218
|
+
return this.visitors;
|
|
18219
|
+
}
|
|
18220
|
+
catch (error) {
|
|
18221
|
+
return error;
|
|
18222
|
+
}
|
|
18223
|
+
}
|
|
18224
|
+
async moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
|
|
18225
|
+
if (shouldFetchVisitors)
|
|
18226
|
+
await this.fetchVisitors();
|
|
18227
|
+
const allPromises = [];
|
|
18228
|
+
if (!this.visitors)
|
|
18229
|
+
return;
|
|
18230
|
+
const objectKeys = Object.keys(this.visitors);
|
|
18231
|
+
objectKeys.forEach((key) => allPromises.push(this.#visitorsMap[key].moveVisitor(shouldTeleportVisitors, scatterVisitors(x, scatterVisitorsBy), scatterVisitors(y, scatterVisitorsBy))));
|
|
18232
|
+
const outcomes = await Promise.allSettled(allPromises);
|
|
18233
|
+
return outcomes;
|
|
18234
|
+
}
|
|
18235
|
+
async moveVisitors(visitorsToMove) {
|
|
18236
|
+
const allPromises = [];
|
|
18237
|
+
visitorsToMove.forEach((v) => {
|
|
18238
|
+
allPromises.push(v.visitorObj.moveVisitor(v.shouldTeleportVisitor, v.x, v.y));
|
|
18239
|
+
});
|
|
18240
|
+
const outcomes = await Promise.allSettled(allPromises);
|
|
18241
|
+
return outcomes;
|
|
18242
|
+
}
|
|
18243
|
+
// dropped assets
|
|
18244
|
+
fetchDroppedAssets() {
|
|
18245
|
+
return new Promise((resolve, reject) => {
|
|
18246
|
+
publicAPI(this.apiKey)
|
|
18247
|
+
.get(`/world/${this.urlSlug}/assets`)
|
|
18248
|
+
.then((response) => {
|
|
18249
|
+
// create temp map and then update private property only once
|
|
18250
|
+
const tempDroppedAssetsMap = {};
|
|
18251
|
+
for (const id in response.data) {
|
|
18252
|
+
// tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
|
|
18253
|
+
tempDroppedAssetsMap[id] = new DroppedAsset(this.apiKey, response.data[id], "", this.urlSlug);
|
|
18254
|
+
}
|
|
18255
|
+
this.#droppedAssetsMap = tempDroppedAssetsMap;
|
|
18256
|
+
resolve("Success!");
|
|
18257
|
+
})
|
|
18258
|
+
.catch((error) => {
|
|
18259
|
+
reject(new Error(getErrorMessage(error)));
|
|
18260
|
+
});
|
|
18261
|
+
});
|
|
18262
|
+
}
|
|
18263
|
+
async updateCustomTextDroppedAssets(droppedAssetsToUpdate, style) {
|
|
18264
|
+
// adds ability to update any styles for specified dropped assets only while preserving text
|
|
18265
|
+
const allPromises = [];
|
|
18266
|
+
droppedAssetsToUpdate.forEach((a) => {
|
|
18267
|
+
allPromises.push(a.updateCustomText(style, a.text));
|
|
18268
|
+
});
|
|
18269
|
+
const outcomes = await Promise.allSettled(allPromises);
|
|
18270
|
+
return outcomes;
|
|
18271
|
+
}
|
|
18272
|
+
}
|
|
17950
18273
|
|
|
17951
|
-
export { World };
|
|
18274
|
+
export { Asset, DroppedAsset, Scene, Visitor, World };
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export var DroppedAssetClickType;
|
|
2
|
+
(function (DroppedAssetClickType) {
|
|
3
|
+
DroppedAssetClickType["NONE"] = "none";
|
|
4
|
+
DroppedAssetClickType["LINK"] = "link";
|
|
5
|
+
DroppedAssetClickType["PORTAL"] = "portal";
|
|
6
|
+
DroppedAssetClickType["TELEPORT"] = "teleport";
|
|
7
|
+
})(DroppedAssetClickType || (DroppedAssetClickType = {}));
|
|
8
|
+
export var DroppedAssetMediaType;
|
|
9
|
+
(function (DroppedAssetMediaType) {
|
|
10
|
+
DroppedAssetMediaType["NONE"] = "none";
|
|
11
|
+
DroppedAssetMediaType["LINK"] = "link";
|
|
12
|
+
})(DroppedAssetMediaType || (DroppedAssetMediaType = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./DroppedAssetTypes";
|
|
2
|
+
export * from "./VisitorTypes";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { scatterVisitors } from "../scatterVisitors";
|
|
2
|
+
afterEach(() => {
|
|
3
|
+
jest.resetAllMocks();
|
|
4
|
+
});
|
|
5
|
+
describe("Visitor Class", () => {
|
|
6
|
+
it("should create an instance of Visitor", () => {
|
|
7
|
+
const testScatter = scatterVisitors(10, 50);
|
|
8
|
+
expect(testScatter).toBeGreaterThan(-40);
|
|
9
|
+
expect(testScatter).toBeLessThan(60);
|
|
10
|
+
});
|
|
11
|
+
});
|