@momo2555/koppeliajs 0.0.127 → 0.0.129
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/scripts/console.d.ts +8 -0
- package/dist/scripts/console.js +14 -0
- package/dist/scripts/device.d.ts +5 -0
- package/dist/scripts/device.js +15 -0
- package/dist/scripts/koppelia.d.ts +4 -0
- package/dist/scripts/koppelia.js +24 -0
- package/dist/scripts/resident.d.ts +12 -0
- package/dist/scripts/resident.js +24 -0
- package/package.json +1 -1
|
@@ -67,6 +67,14 @@ export declare class Console {
|
|
|
67
67
|
*/
|
|
68
68
|
get ready(): boolean;
|
|
69
69
|
getMediaUrl(path: string): string;
|
|
70
|
+
/**
|
|
71
|
+
* Call thus function to fix the link and make it work for both controller and monitor
|
|
72
|
+
* Sometimes, the link is get from monitor or controller and save as a game state. But
|
|
73
|
+
* When the oher client will get the link will not work. Using this function for all media
|
|
74
|
+
* Url is a good practice.
|
|
75
|
+
* @param mediaUrl
|
|
76
|
+
*/
|
|
77
|
+
fixMediaUrl(mediaUrl: string): string;
|
|
70
78
|
getMedia(path: string): Promise<MediaResponseData>;
|
|
71
79
|
private _initEvents;
|
|
72
80
|
private _processReceivedData;
|
package/dist/scripts/console.js
CHANGED
|
@@ -115,6 +115,20 @@ export class Console {
|
|
|
115
115
|
path = "/" + path;
|
|
116
116
|
return this._mediaApiUrl + path;
|
|
117
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Call thus function to fix the link and make it work for both controller and monitor
|
|
120
|
+
* Sometimes, the link is get from monitor or controller and save as a game state. But
|
|
121
|
+
* When the oher client will get the link will not work. Using this function for all media
|
|
122
|
+
* Url is a good practice.
|
|
123
|
+
* @param mediaUrl
|
|
124
|
+
*/
|
|
125
|
+
fixMediaUrl(mediaUrl) {
|
|
126
|
+
let url = new URL(mediaUrl);
|
|
127
|
+
let fixedurl = new URL(this._mediaApiUrl);
|
|
128
|
+
fixedurl.pathname = url.pathname;
|
|
129
|
+
fixedurl.search = url.search;
|
|
130
|
+
return fixedurl.toString();
|
|
131
|
+
}
|
|
118
132
|
async getMedia(path) {
|
|
119
133
|
const response = await fetch(this.getMediaUrl(path));
|
|
120
134
|
if (!response.ok) {
|
package/dist/scripts/device.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Console } from './console.js';
|
|
2
|
+
import { Resident } from './resident.js';
|
|
2
3
|
/**
|
|
3
4
|
* This class reprensts a device
|
|
4
5
|
*/
|
|
@@ -13,6 +14,8 @@ export declare class Device {
|
|
|
13
14
|
private _name;
|
|
14
15
|
private _console;
|
|
15
16
|
private _attachedEvents;
|
|
17
|
+
private _resident?;
|
|
18
|
+
private isAttachedToResident;
|
|
16
19
|
constructor(console: Console, address?: string);
|
|
17
20
|
get color(): Color;
|
|
18
21
|
get name(): string;
|
|
@@ -45,5 +48,7 @@ export declare class Device {
|
|
|
45
48
|
fromObject(object: {
|
|
46
49
|
[key: string]: any;
|
|
47
50
|
}): void;
|
|
51
|
+
get resident(): Resident | undefined;
|
|
52
|
+
get isAssociatedToResident(): boolean;
|
|
48
53
|
}
|
|
49
54
|
export {};
|
package/dist/scripts/device.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { Console } from './console.js';
|
|
2
2
|
import { Message, MessageType, PeerType } from './message.js';
|
|
3
|
+
import { Resident } from './resident.js';
|
|
3
4
|
export class Device {
|
|
4
5
|
_address;
|
|
5
6
|
_color;
|
|
6
7
|
_name;
|
|
7
8
|
_console;
|
|
8
9
|
_attachedEvents;
|
|
10
|
+
_resident;
|
|
11
|
+
isAttachedToResident;
|
|
9
12
|
constructor(console, address = "") {
|
|
10
13
|
this._address = address;
|
|
11
14
|
this._color = { r: 0, g: 0, b: 0 };
|
|
12
15
|
this._name = "";
|
|
13
16
|
this._console = console;
|
|
14
17
|
this._attachedEvents = [];
|
|
18
|
+
this.isAttachedToResident = false;
|
|
15
19
|
}
|
|
16
20
|
// public set color(color: Color) {
|
|
17
21
|
// this._color = color;
|
|
@@ -128,5 +132,16 @@ export class Device {
|
|
|
128
132
|
if (object.name !== undefined) {
|
|
129
133
|
this._name = object.name;
|
|
130
134
|
}
|
|
135
|
+
if (object.resident !== undefined) {
|
|
136
|
+
this.isAttachedToResident = true;
|
|
137
|
+
this._resident = new Resident();
|
|
138
|
+
this._resident.fromObject(object.resident);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
get resident() {
|
|
142
|
+
return this._resident;
|
|
143
|
+
}
|
|
144
|
+
get isAssociatedToResident() {
|
|
145
|
+
return this.isAttachedToResident;
|
|
131
146
|
}
|
|
132
147
|
}
|
|
@@ -2,6 +2,7 @@ import { type Writable } from "svelte/store";
|
|
|
2
2
|
import { type AnyState } from "./state.js";
|
|
3
3
|
import { Device } from "./device.js";
|
|
4
4
|
import { Play } from "./play.js";
|
|
5
|
+
import { Resident } from "./resident.js";
|
|
5
6
|
export declare class Koppelia {
|
|
6
7
|
private _console;
|
|
7
8
|
private _state;
|
|
@@ -32,6 +33,8 @@ export declare class Koppelia {
|
|
|
32
33
|
* @param stageName
|
|
33
34
|
*/
|
|
34
35
|
goto(stageName: string): void;
|
|
36
|
+
fixMediaUrl(mediaUrl: string): string;
|
|
37
|
+
getMediaLink(path: string): string;
|
|
35
38
|
/**
|
|
36
39
|
* Get the list of devices in a callback
|
|
37
40
|
* @param callback
|
|
@@ -51,6 +54,7 @@ export declare class Koppelia {
|
|
|
51
54
|
* @returns the List of plays an array of objects of type Play,
|
|
52
55
|
*/
|
|
53
56
|
getPlays(count?: number, index?: number, orderBy?: string): Promise<Play[]>;
|
|
57
|
+
getResidents(): Promise<Resident[]>;
|
|
54
58
|
/**
|
|
55
59
|
* Get the current play that has been set
|
|
56
60
|
* @returns the current play
|
package/dist/scripts/koppelia.js
CHANGED
|
@@ -7,6 +7,7 @@ import { Stage } from "./stage.js";
|
|
|
7
7
|
import { Device } from "./device.js";
|
|
8
8
|
import { Play } from "./play.js";
|
|
9
9
|
import { PUBLIC_GAME_ID } from '$env/static/public';
|
|
10
|
+
import { Resident } from "./resident.js";
|
|
10
11
|
export class Koppelia {
|
|
11
12
|
_console;
|
|
12
13
|
_state;
|
|
@@ -81,6 +82,12 @@ export class Koppelia {
|
|
|
81
82
|
goto(stageName) {
|
|
82
83
|
this._stage.goto(stageName);
|
|
83
84
|
}
|
|
85
|
+
fixMediaUrl(mediaUrl) {
|
|
86
|
+
return this._console.fixMediaUrl(mediaUrl);
|
|
87
|
+
}
|
|
88
|
+
getMediaLink(path) {
|
|
89
|
+
return this._console.getMediaUrl(path);
|
|
90
|
+
}
|
|
84
91
|
/**
|
|
85
92
|
* Get the list of devices in a callback
|
|
86
93
|
* @param callback
|
|
@@ -139,6 +146,23 @@ export class Koppelia {
|
|
|
139
146
|
});
|
|
140
147
|
});
|
|
141
148
|
}
|
|
149
|
+
async getResidents() {
|
|
150
|
+
return new Promise((resolve, reject) => {
|
|
151
|
+
let getResidentsRequest = new Message();
|
|
152
|
+
getResidentsRequest.setRequest("getResidentsList");
|
|
153
|
+
getResidentsRequest.setDestination(PeerType.MASTER, "");
|
|
154
|
+
this._console.sendMessage(getResidentsRequest, (response) => {
|
|
155
|
+
let ResidentRawList = response.getParam("residents", {});
|
|
156
|
+
let residents = [];
|
|
157
|
+
for (let residentId in ResidentRawList) {
|
|
158
|
+
let resident = new Resident();
|
|
159
|
+
resident.fromObject(ResidentRawList[residentId]);
|
|
160
|
+
residents.push(resident);
|
|
161
|
+
}
|
|
162
|
+
resolve(residents);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
142
166
|
/**
|
|
143
167
|
* Get the current play that has been set
|
|
144
168
|
* @returns the current play
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Koppelia } from "./koppelia.js";
|
|
2
|
+
export class Resident {
|
|
3
|
+
_name = "";
|
|
4
|
+
_id = "";
|
|
5
|
+
_image = "";
|
|
6
|
+
constructor() {
|
|
7
|
+
}
|
|
8
|
+
get id() {
|
|
9
|
+
return this._id;
|
|
10
|
+
}
|
|
11
|
+
get name() {
|
|
12
|
+
return this._name;
|
|
13
|
+
}
|
|
14
|
+
get imageUrl() {
|
|
15
|
+
let koppelia = Koppelia.instance;
|
|
16
|
+
let path = "/media/residence/" + this._id + "/" + this._image;
|
|
17
|
+
return koppelia.getMediaLink(path);
|
|
18
|
+
}
|
|
19
|
+
fromObject(object) {
|
|
20
|
+
this._name = object["resident_name"];
|
|
21
|
+
this._id = object["resident_id"];
|
|
22
|
+
this._image = object["resident_image"];
|
|
23
|
+
}
|
|
24
|
+
}
|