@workadventure/room-api-client 1.17.7 → 1.18.3
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/README.md +87 -5
- package/dist/compiled_proto/google/protobuf/empty.d.ts +1 -1
- package/dist/compiled_proto/google/protobuf/empty.js +1 -1
- package/dist/compiled_proto/google/protobuf/struct.d.ts +1 -1
- package/dist/compiled_proto/google/protobuf/struct.js +58 -40
- package/dist/compiled_proto/room-api.d.ts +93 -1
- package/dist/compiled_proto/room-api.js +284 -16
- package/dist/example_events.js +36 -0
- package/dist/example_variables.d.ts +1 -0
- package/dist/{example.js → example_variables.js} +2 -0
- package/package.json +4 -3
- /package/dist/{example.d.ts → example_events.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -10,7 +10,38 @@ Easily create a GRPC client to connect your service to the [Room API](https://gi
|
|
|
10
10
|
npm install @workadventure/room-api-client
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Instantiating the client
|
|
14
|
+
|
|
15
|
+
Use the `createRoomApiClient` function to create a client.
|
|
16
|
+
|
|
17
|
+
The client expects an API key as first parameter. See [the Authentication section of the Room API documentation](https://docs.workadventu.re/developer/room-api)
|
|
18
|
+
to learn how to get your own API key.
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
const client = createRoomApiClient("MY AWESOME KEY");
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
By default, the client targets the official WorkAdventure server. If you are using a self-hosted version, you
|
|
25
|
+
must in addition pass in parameter the domain name and port of your WorkAdventure RoomApi endpoint.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
const client = createRoomApiClient("My AWESOME KEY", "play.example.com", "5221");
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Setting / Reading / Tracking variables
|
|
32
|
+
|
|
33
|
+
The Room API client allows you to set, read and track variables in a room using the following methods:
|
|
34
|
+
|
|
35
|
+
- `client.saveVariable({ name: string, room: string, value: unknown }): Promise<void>`
|
|
36
|
+
- `client.readVariable({ name: string, room: string }): Promise<Value>`
|
|
37
|
+
- `client.listenVariable({ name: string, room: string }): AsyncIterable<Value>`
|
|
38
|
+
|
|
39
|
+
> [!WARNING]
|
|
40
|
+
> `readVariable` and `listenVariable` return a `Value` object. To get the underlying value, you must call the `Value.unwrap` function.
|
|
41
|
+
> This is because the functions can return nothing due to an error, and the `Value` object allows you to check if the value is an error or not.
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Example
|
|
14
45
|
|
|
15
46
|
```javascript
|
|
16
47
|
import { createRoomApiClient } from "@workadventure/room-api-client";
|
|
@@ -24,7 +55,7 @@ import { createRoomApiClient } from "@workadventure/room-api-client";
|
|
|
24
55
|
const client = createRoomApiClient("My AWESOME KEY");
|
|
25
56
|
|
|
26
57
|
// URL of the room you wish to interact with
|
|
27
|
-
const roomUrl = "https://play.workadventu.re/@/my-
|
|
58
|
+
const roomUrl = "https://play.workadventu.re/@/my-organization/my-world/my-room";
|
|
28
59
|
|
|
29
60
|
// Name of the variable with which you want to interact
|
|
30
61
|
const variableName = "textField";
|
|
@@ -71,9 +102,60 @@ async function init() {
|
|
|
71
102
|
}
|
|
72
103
|
|
|
73
104
|
init();
|
|
74
|
-
|
|
75
105
|
```
|
|
76
106
|
|
|
77
|
-
## Warning
|
|
78
107
|
|
|
79
|
-
|
|
108
|
+
## Sending events / listening to events
|
|
109
|
+
|
|
110
|
+
The Room API client allows you to send and listen to events in a room using the following methods:
|
|
111
|
+
|
|
112
|
+
- `client.broadcastEvent({ name: string, room: string, data: unknown }): Promise<void>`
|
|
113
|
+
- `client.listenToEvent({ name: string, room: string }): AsyncIterable<any>`
|
|
114
|
+
|
|
115
|
+
### Example
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
import { createRoomApiClient } from "@workadventure/room-api-client";
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* By default, the client targets the official WorkAdventure server,
|
|
122
|
+
* but you can also define customs domain and port.
|
|
123
|
+
* Example :
|
|
124
|
+
* const client = createRoomApiClient("My AWESOME KEY", "mydomain.net", "5221");
|
|
125
|
+
*/
|
|
126
|
+
const client = createRoomApiClient("My AWESOME KEY");
|
|
127
|
+
|
|
128
|
+
// URL of the room you wish to interact with
|
|
129
|
+
const roomUrl = "https://play.workadventu.re/@/my-organization/my-world/my-room";
|
|
130
|
+
|
|
131
|
+
// Name of the event with which you want to interact
|
|
132
|
+
const eventName = "my-event";
|
|
133
|
+
|
|
134
|
+
async function init() {
|
|
135
|
+
// Send an event in 5 seconds
|
|
136
|
+
setTimeout(async () => {
|
|
137
|
+
await client.broadcastEvent({
|
|
138
|
+
name: eventName,
|
|
139
|
+
room: roomUrl,
|
|
140
|
+
data: "Default Value",
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
console.log("Event sent: Default Value");
|
|
144
|
+
}, 5000);
|
|
145
|
+
|
|
146
|
+
// Listen a event
|
|
147
|
+
const events = client.listenToEvent({
|
|
148
|
+
name: eventName,
|
|
149
|
+
room: roomUrl,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
for await (const event of events) {
|
|
153
|
+
console.log("Event received:");
|
|
154
|
+
console.log("Sender:", event.senderId);
|
|
155
|
+
console.log("Value:", event.data);
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
init();
|
|
161
|
+
```
|
|
@@ -22,7 +22,7 @@ export declare const Empty: {
|
|
|
22
22
|
fromPartial(_: DeepPartial<Empty>): Empty;
|
|
23
23
|
};
|
|
24
24
|
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
25
|
-
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
25
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
26
26
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
27
27
|
} : Partial<T>;
|
|
28
28
|
export {};
|
|
@@ -109,7 +109,7 @@ export declare const ListValue: {
|
|
|
109
109
|
unwrap(message: ListValue): Array<any>;
|
|
110
110
|
};
|
|
111
111
|
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
112
|
-
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
112
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
113
113
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
114
114
|
} : Partial<T>;
|
|
115
115
|
export {};
|
|
@@ -81,7 +81,7 @@ exports.Struct = {
|
|
|
81
81
|
const tag = reader.uint32();
|
|
82
82
|
switch (tag >>> 3) {
|
|
83
83
|
case 1:
|
|
84
|
-
if (tag
|
|
84
|
+
if (tag !== 10) {
|
|
85
85
|
break;
|
|
86
86
|
}
|
|
87
87
|
const entry1 = exports.Struct_FieldsEntry.decode(reader, reader.uint32());
|
|
@@ -90,7 +90,7 @@ exports.Struct = {
|
|
|
90
90
|
}
|
|
91
91
|
continue;
|
|
92
92
|
}
|
|
93
|
-
if ((tag & 7)
|
|
93
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
94
94
|
break;
|
|
95
95
|
}
|
|
96
96
|
reader.skipType(tag & 7);
|
|
@@ -109,11 +109,14 @@ exports.Struct = {
|
|
|
109
109
|
},
|
|
110
110
|
toJSON(message) {
|
|
111
111
|
const obj = {};
|
|
112
|
-
obj.fields = {};
|
|
113
112
|
if (message.fields) {
|
|
114
|
-
Object.entries(message.fields)
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
const entries = Object.entries(message.fields);
|
|
114
|
+
if (entries.length > 0) {
|
|
115
|
+
obj.fields = {};
|
|
116
|
+
entries.forEach(([k, v]) => {
|
|
117
|
+
obj.fields[k] = v;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
117
120
|
}
|
|
118
121
|
return obj;
|
|
119
122
|
},
|
|
@@ -170,19 +173,19 @@ exports.Struct_FieldsEntry = {
|
|
|
170
173
|
const tag = reader.uint32();
|
|
171
174
|
switch (tag >>> 3) {
|
|
172
175
|
case 1:
|
|
173
|
-
if (tag
|
|
176
|
+
if (tag !== 10) {
|
|
174
177
|
break;
|
|
175
178
|
}
|
|
176
179
|
message.key = reader.string();
|
|
177
180
|
continue;
|
|
178
181
|
case 2:
|
|
179
|
-
if (tag
|
|
182
|
+
if (tag !== 18) {
|
|
180
183
|
break;
|
|
181
184
|
}
|
|
182
185
|
message.value = exports.Value.unwrap(exports.Value.decode(reader, reader.uint32()));
|
|
183
186
|
continue;
|
|
184
187
|
}
|
|
185
|
-
if ((tag & 7)
|
|
188
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
186
189
|
break;
|
|
187
190
|
}
|
|
188
191
|
reader.skipType(tag & 7);
|
|
@@ -190,12 +193,19 @@ exports.Struct_FieldsEntry = {
|
|
|
190
193
|
return message;
|
|
191
194
|
},
|
|
192
195
|
fromJSON(object) {
|
|
193
|
-
return {
|
|
196
|
+
return {
|
|
197
|
+
key: isSet(object.key) ? globalThis.String(object.key) : "",
|
|
198
|
+
value: isSet(object?.value) ? object.value : undefined,
|
|
199
|
+
};
|
|
194
200
|
},
|
|
195
201
|
toJSON(message) {
|
|
196
202
|
const obj = {};
|
|
197
|
-
message.key !==
|
|
198
|
-
|
|
203
|
+
if (message.key !== "") {
|
|
204
|
+
obj.key = message.key;
|
|
205
|
+
}
|
|
206
|
+
if (message.value !== undefined) {
|
|
207
|
+
obj.value = message.value;
|
|
208
|
+
}
|
|
199
209
|
return obj;
|
|
200
210
|
},
|
|
201
211
|
create(base) {
|
|
@@ -248,43 +258,43 @@ exports.Value = {
|
|
|
248
258
|
const tag = reader.uint32();
|
|
249
259
|
switch (tag >>> 3) {
|
|
250
260
|
case 1:
|
|
251
|
-
if (tag
|
|
261
|
+
if (tag !== 8) {
|
|
252
262
|
break;
|
|
253
263
|
}
|
|
254
264
|
message.nullValue = reader.int32();
|
|
255
265
|
continue;
|
|
256
266
|
case 2:
|
|
257
|
-
if (tag
|
|
267
|
+
if (tag !== 17) {
|
|
258
268
|
break;
|
|
259
269
|
}
|
|
260
270
|
message.numberValue = reader.double();
|
|
261
271
|
continue;
|
|
262
272
|
case 3:
|
|
263
|
-
if (tag
|
|
273
|
+
if (tag !== 26) {
|
|
264
274
|
break;
|
|
265
275
|
}
|
|
266
276
|
message.stringValue = reader.string();
|
|
267
277
|
continue;
|
|
268
278
|
case 4:
|
|
269
|
-
if (tag
|
|
279
|
+
if (tag !== 32) {
|
|
270
280
|
break;
|
|
271
281
|
}
|
|
272
282
|
message.boolValue = reader.bool();
|
|
273
283
|
continue;
|
|
274
284
|
case 5:
|
|
275
|
-
if (tag
|
|
285
|
+
if (tag !== 42) {
|
|
276
286
|
break;
|
|
277
287
|
}
|
|
278
288
|
message.structValue = exports.Struct.unwrap(exports.Struct.decode(reader, reader.uint32()));
|
|
279
289
|
continue;
|
|
280
290
|
case 6:
|
|
281
|
-
if (tag
|
|
291
|
+
if (tag !== 50) {
|
|
282
292
|
break;
|
|
283
293
|
}
|
|
284
294
|
message.listValue = exports.ListValue.unwrap(exports.ListValue.decode(reader, reader.uint32()));
|
|
285
295
|
continue;
|
|
286
296
|
}
|
|
287
|
-
if ((tag & 7)
|
|
297
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
288
298
|
break;
|
|
289
299
|
}
|
|
290
300
|
reader.skipType(tag & 7);
|
|
@@ -294,22 +304,33 @@ exports.Value = {
|
|
|
294
304
|
fromJSON(object) {
|
|
295
305
|
return {
|
|
296
306
|
nullValue: isSet(object.nullValue) ? nullValueFromJSON(object.nullValue) : undefined,
|
|
297
|
-
numberValue: isSet(object.numberValue) ? Number(object.numberValue) : undefined,
|
|
298
|
-
stringValue: isSet(object.stringValue) ? String(object.stringValue) : undefined,
|
|
299
|
-
boolValue: isSet(object.boolValue) ? Boolean(object.boolValue) : undefined,
|
|
307
|
+
numberValue: isSet(object.numberValue) ? globalThis.Number(object.numberValue) : undefined,
|
|
308
|
+
stringValue: isSet(object.stringValue) ? globalThis.String(object.stringValue) : undefined,
|
|
309
|
+
boolValue: isSet(object.boolValue) ? globalThis.Boolean(object.boolValue) : undefined,
|
|
300
310
|
structValue: isObject(object.structValue) ? object.structValue : undefined,
|
|
301
|
-
listValue: Array.isArray(object.listValue) ? [...object.listValue] : undefined,
|
|
311
|
+
listValue: globalThis.Array.isArray(object.listValue) ? [...object.listValue] : undefined,
|
|
302
312
|
};
|
|
303
313
|
},
|
|
304
314
|
toJSON(message) {
|
|
305
315
|
const obj = {};
|
|
306
|
-
message.nullValue !== undefined
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
message.
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
message.
|
|
316
|
+
if (message.nullValue !== undefined) {
|
|
317
|
+
obj.nullValue = nullValueToJSON(message.nullValue);
|
|
318
|
+
}
|
|
319
|
+
if (message.numberValue !== undefined) {
|
|
320
|
+
obj.numberValue = message.numberValue;
|
|
321
|
+
}
|
|
322
|
+
if (message.stringValue !== undefined) {
|
|
323
|
+
obj.stringValue = message.stringValue;
|
|
324
|
+
}
|
|
325
|
+
if (message.boolValue !== undefined) {
|
|
326
|
+
obj.boolValue = message.boolValue;
|
|
327
|
+
}
|
|
328
|
+
if (message.structValue !== undefined) {
|
|
329
|
+
obj.structValue = message.structValue;
|
|
330
|
+
}
|
|
331
|
+
if (message.listValue !== undefined) {
|
|
332
|
+
obj.listValue = message.listValue;
|
|
333
|
+
}
|
|
313
334
|
return obj;
|
|
314
335
|
},
|
|
315
336
|
create(base) {
|
|
@@ -339,7 +360,7 @@ exports.Value = {
|
|
|
339
360
|
else if (typeof value === "string") {
|
|
340
361
|
result.stringValue = value;
|
|
341
362
|
}
|
|
342
|
-
else if (Array.isArray(value)) {
|
|
363
|
+
else if (globalThis.Array.isArray(value)) {
|
|
343
364
|
result.listValue = value;
|
|
344
365
|
}
|
|
345
366
|
else if (typeof value === "object") {
|
|
@@ -390,13 +411,13 @@ exports.ListValue = {
|
|
|
390
411
|
const tag = reader.uint32();
|
|
391
412
|
switch (tag >>> 3) {
|
|
392
413
|
case 1:
|
|
393
|
-
if (tag
|
|
414
|
+
if (tag !== 10) {
|
|
394
415
|
break;
|
|
395
416
|
}
|
|
396
417
|
message.values.push(exports.Value.unwrap(exports.Value.decode(reader, reader.uint32())));
|
|
397
418
|
continue;
|
|
398
419
|
}
|
|
399
|
-
if ((tag & 7)
|
|
420
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
400
421
|
break;
|
|
401
422
|
}
|
|
402
423
|
reader.skipType(tag & 7);
|
|
@@ -404,15 +425,12 @@ exports.ListValue = {
|
|
|
404
425
|
return message;
|
|
405
426
|
},
|
|
406
427
|
fromJSON(object) {
|
|
407
|
-
return { values: Array.isArray(object?.values) ? [...object.values] : [] };
|
|
428
|
+
return { values: globalThis.Array.isArray(object?.values) ? [...object.values] : [] };
|
|
408
429
|
},
|
|
409
430
|
toJSON(message) {
|
|
410
431
|
const obj = {};
|
|
411
|
-
if (message.values) {
|
|
412
|
-
obj.values = message.values
|
|
413
|
-
}
|
|
414
|
-
else {
|
|
415
|
-
obj.values = [];
|
|
432
|
+
if (message.values?.length) {
|
|
433
|
+
obj.values = message.values;
|
|
416
434
|
}
|
|
417
435
|
return obj;
|
|
418
436
|
},
|
|
@@ -430,7 +448,7 @@ exports.ListValue = {
|
|
|
430
448
|
return result;
|
|
431
449
|
},
|
|
432
450
|
unwrap(message) {
|
|
433
|
-
if (message?.hasOwnProperty("values") && Array.isArray(message.values)) {
|
|
451
|
+
if (message?.hasOwnProperty("values") && globalThis.Array.isArray(message.values)) {
|
|
434
452
|
return message.values;
|
|
435
453
|
}
|
|
436
454
|
else {
|
|
@@ -12,6 +12,20 @@ export interface SaveVariableRequest {
|
|
|
12
12
|
name: string;
|
|
13
13
|
value: any | undefined;
|
|
14
14
|
}
|
|
15
|
+
export interface EventRequest {
|
|
16
|
+
room: string;
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
19
|
+
export interface EventResponse {
|
|
20
|
+
data: any | undefined;
|
|
21
|
+
senderId?: number | undefined;
|
|
22
|
+
}
|
|
23
|
+
export interface DispatchEventRequest {
|
|
24
|
+
room: string;
|
|
25
|
+
name: string;
|
|
26
|
+
data: any | undefined;
|
|
27
|
+
targetUserIds: number[];
|
|
28
|
+
}
|
|
15
29
|
export declare const VariableRequest: {
|
|
16
30
|
encode(message: VariableRequest, writer?: _m0.Writer): _m0.Writer;
|
|
17
31
|
decode(input: _m0.Reader | Uint8Array, length?: number): VariableRequest;
|
|
@@ -28,6 +42,30 @@ export declare const SaveVariableRequest: {
|
|
|
28
42
|
create(base?: DeepPartial<SaveVariableRequest>): SaveVariableRequest;
|
|
29
43
|
fromPartial(object: DeepPartial<SaveVariableRequest>): SaveVariableRequest;
|
|
30
44
|
};
|
|
45
|
+
export declare const EventRequest: {
|
|
46
|
+
encode(message: EventRequest, writer?: _m0.Writer): _m0.Writer;
|
|
47
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): EventRequest;
|
|
48
|
+
fromJSON(object: any): EventRequest;
|
|
49
|
+
toJSON(message: EventRequest): unknown;
|
|
50
|
+
create(base?: DeepPartial<EventRequest>): EventRequest;
|
|
51
|
+
fromPartial(object: DeepPartial<EventRequest>): EventRequest;
|
|
52
|
+
};
|
|
53
|
+
export declare const EventResponse: {
|
|
54
|
+
encode(message: EventResponse, writer?: _m0.Writer): _m0.Writer;
|
|
55
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): EventResponse;
|
|
56
|
+
fromJSON(object: any): EventResponse;
|
|
57
|
+
toJSON(message: EventResponse): unknown;
|
|
58
|
+
create(base?: DeepPartial<EventResponse>): EventResponse;
|
|
59
|
+
fromPartial(object: DeepPartial<EventResponse>): EventResponse;
|
|
60
|
+
};
|
|
61
|
+
export declare const DispatchEventRequest: {
|
|
62
|
+
encode(message: DispatchEventRequest, writer?: _m0.Writer): _m0.Writer;
|
|
63
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): DispatchEventRequest;
|
|
64
|
+
fromJSON(object: any): DispatchEventRequest;
|
|
65
|
+
toJSON(message: DispatchEventRequest): unknown;
|
|
66
|
+
create(base?: DeepPartial<DispatchEventRequest>): DispatchEventRequest;
|
|
67
|
+
fromPartial(object: DeepPartial<DispatchEventRequest>): DispatchEventRequest;
|
|
68
|
+
};
|
|
31
69
|
export type RoomApiDefinition = typeof RoomApiDefinition;
|
|
32
70
|
export declare const RoomApiDefinition: {
|
|
33
71
|
readonly name: "RoomApi";
|
|
@@ -142,6 +180,52 @@ export declare const RoomApiDefinition: {
|
|
|
142
180
|
readonly responseStream: false;
|
|
143
181
|
readonly options: {};
|
|
144
182
|
};
|
|
183
|
+
/** Dispatch an event to all users in the room */
|
|
184
|
+
readonly broadcastEvent: {
|
|
185
|
+
readonly name: "broadcastEvent";
|
|
186
|
+
readonly requestType: {
|
|
187
|
+
encode(message: DispatchEventRequest, writer?: _m0.Writer): _m0.Writer;
|
|
188
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): DispatchEventRequest;
|
|
189
|
+
fromJSON(object: any): DispatchEventRequest;
|
|
190
|
+
toJSON(message: DispatchEventRequest): unknown;
|
|
191
|
+
create(base?: DeepPartial<DispatchEventRequest>): DispatchEventRequest;
|
|
192
|
+
fromPartial(object: DeepPartial<DispatchEventRequest>): DispatchEventRequest;
|
|
193
|
+
};
|
|
194
|
+
readonly requestStream: false;
|
|
195
|
+
readonly responseType: {
|
|
196
|
+
encode(_: Empty, writer?: _m0.Writer): _m0.Writer;
|
|
197
|
+
decode(input: Uint8Array | _m0.Reader, length?: number | undefined): Empty;
|
|
198
|
+
fromJSON(_: any): Empty;
|
|
199
|
+
toJSON(_: Empty): unknown;
|
|
200
|
+
create(base?: {} | undefined): Empty;
|
|
201
|
+
fromPartial(_: {}): Empty;
|
|
202
|
+
};
|
|
203
|
+
readonly responseStream: false;
|
|
204
|
+
readonly options: {};
|
|
205
|
+
};
|
|
206
|
+
/** Listen to events dispatched in the room */
|
|
207
|
+
readonly listenToEvent: {
|
|
208
|
+
readonly name: "listenToEvent";
|
|
209
|
+
readonly requestType: {
|
|
210
|
+
encode(message: EventRequest, writer?: _m0.Writer): _m0.Writer;
|
|
211
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): EventRequest;
|
|
212
|
+
fromJSON(object: any): EventRequest;
|
|
213
|
+
toJSON(message: EventRequest): unknown;
|
|
214
|
+
create(base?: DeepPartial<EventRequest>): EventRequest;
|
|
215
|
+
fromPartial(object: DeepPartial<EventRequest>): EventRequest;
|
|
216
|
+
};
|
|
217
|
+
readonly requestStream: false;
|
|
218
|
+
readonly responseType: {
|
|
219
|
+
encode(message: EventResponse, writer?: _m0.Writer): _m0.Writer;
|
|
220
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): EventResponse;
|
|
221
|
+
fromJSON(object: any): EventResponse;
|
|
222
|
+
toJSON(message: EventResponse): unknown;
|
|
223
|
+
create(base?: DeepPartial<EventResponse>): EventResponse;
|
|
224
|
+
fromPartial(object: DeepPartial<EventResponse>): EventResponse;
|
|
225
|
+
};
|
|
226
|
+
readonly responseStream: true;
|
|
227
|
+
readonly options: {};
|
|
228
|
+
};
|
|
145
229
|
};
|
|
146
230
|
};
|
|
147
231
|
export interface RoomApiServiceImplementation<CallContextExt = {}> {
|
|
@@ -151,6 +235,10 @@ export interface RoomApiServiceImplementation<CallContextExt = {}> {
|
|
|
151
235
|
listenVariable(request: VariableRequest, context: CallContext & CallContextExt): ServerStreamingMethodResult<DeepPartial<Value>>;
|
|
152
236
|
/** Set the value of the given variable */
|
|
153
237
|
saveVariable(request: SaveVariableRequest, context: CallContext & CallContextExt): Promise<DeepPartial<Empty>>;
|
|
238
|
+
/** Dispatch an event to all users in the room */
|
|
239
|
+
broadcastEvent(request: DispatchEventRequest, context: CallContext & CallContextExt): Promise<DeepPartial<Empty>>;
|
|
240
|
+
/** Listen to events dispatched in the room */
|
|
241
|
+
listenToEvent(request: EventRequest, context: CallContext & CallContextExt): ServerStreamingMethodResult<DeepPartial<EventResponse>>;
|
|
154
242
|
}
|
|
155
243
|
export interface RoomApiClient<CallOptionsExt = {}> {
|
|
156
244
|
/** Get the current value of the given variable */
|
|
@@ -159,9 +247,13 @@ export interface RoomApiClient<CallOptionsExt = {}> {
|
|
|
159
247
|
listenVariable(request: DeepPartial<VariableRequest>, options?: CallOptions & CallOptionsExt): AsyncIterable<Value>;
|
|
160
248
|
/** Set the value of the given variable */
|
|
161
249
|
saveVariable(request: DeepPartial<SaveVariableRequest>, options?: CallOptions & CallOptionsExt): Promise<Empty>;
|
|
250
|
+
/** Dispatch an event to all users in the room */
|
|
251
|
+
broadcastEvent(request: DeepPartial<DispatchEventRequest>, options?: CallOptions & CallOptionsExt): Promise<Empty>;
|
|
252
|
+
/** Listen to events dispatched in the room */
|
|
253
|
+
listenToEvent(request: DeepPartial<EventRequest>, options?: CallOptions & CallOptionsExt): AsyncIterable<EventResponse>;
|
|
162
254
|
}
|
|
163
255
|
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
164
|
-
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
256
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
165
257
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
166
258
|
} : Partial<T>;
|
|
167
259
|
export type ServerStreamingMethodResult<Response> = {
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.RoomApiDefinition = exports.SaveVariableRequest = exports.VariableRequest = exports.protobufPackage = void 0;
|
|
26
|
+
exports.RoomApiDefinition = exports.DispatchEventRequest = exports.EventResponse = exports.EventRequest = exports.SaveVariableRequest = exports.VariableRequest = exports.protobufPackage = void 0;
|
|
27
27
|
const _m0 = __importStar(require("protobufjs/minimal"));
|
|
28
28
|
const empty_1 = require("./google/protobuf/empty");
|
|
29
29
|
const struct_1 = require("./google/protobuf/struct");
|
|
@@ -49,19 +49,19 @@ exports.VariableRequest = {
|
|
|
49
49
|
const tag = reader.uint32();
|
|
50
50
|
switch (tag >>> 3) {
|
|
51
51
|
case 1:
|
|
52
|
-
if (tag
|
|
52
|
+
if (tag !== 10) {
|
|
53
53
|
break;
|
|
54
54
|
}
|
|
55
55
|
message.room = reader.string();
|
|
56
56
|
continue;
|
|
57
57
|
case 2:
|
|
58
|
-
if (tag
|
|
58
|
+
if (tag !== 18) {
|
|
59
59
|
break;
|
|
60
60
|
}
|
|
61
61
|
message.name = reader.string();
|
|
62
62
|
continue;
|
|
63
63
|
}
|
|
64
|
-
if ((tag & 7)
|
|
64
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
65
65
|
break;
|
|
66
66
|
}
|
|
67
67
|
reader.skipType(tag & 7);
|
|
@@ -69,12 +69,19 @@ exports.VariableRequest = {
|
|
|
69
69
|
return message;
|
|
70
70
|
},
|
|
71
71
|
fromJSON(object) {
|
|
72
|
-
return {
|
|
72
|
+
return {
|
|
73
|
+
room: isSet(object.room) ? globalThis.String(object.room) : "",
|
|
74
|
+
name: isSet(object.name) ? globalThis.String(object.name) : "",
|
|
75
|
+
};
|
|
73
76
|
},
|
|
74
77
|
toJSON(message) {
|
|
75
78
|
const obj = {};
|
|
76
|
-
message.room !==
|
|
77
|
-
|
|
79
|
+
if (message.room !== "") {
|
|
80
|
+
obj.room = message.room;
|
|
81
|
+
}
|
|
82
|
+
if (message.name !== "") {
|
|
83
|
+
obj.name = message.name;
|
|
84
|
+
}
|
|
78
85
|
return obj;
|
|
79
86
|
},
|
|
80
87
|
create(base) {
|
|
@@ -111,25 +118,25 @@ exports.SaveVariableRequest = {
|
|
|
111
118
|
const tag = reader.uint32();
|
|
112
119
|
switch (tag >>> 3) {
|
|
113
120
|
case 1:
|
|
114
|
-
if (tag
|
|
121
|
+
if (tag !== 10) {
|
|
115
122
|
break;
|
|
116
123
|
}
|
|
117
124
|
message.room = reader.string();
|
|
118
125
|
continue;
|
|
119
126
|
case 2:
|
|
120
|
-
if (tag
|
|
127
|
+
if (tag !== 18) {
|
|
121
128
|
break;
|
|
122
129
|
}
|
|
123
130
|
message.name = reader.string();
|
|
124
131
|
continue;
|
|
125
132
|
case 3:
|
|
126
|
-
if (tag
|
|
133
|
+
if (tag !== 26) {
|
|
127
134
|
break;
|
|
128
135
|
}
|
|
129
136
|
message.value = struct_1.Value.unwrap(struct_1.Value.decode(reader, reader.uint32()));
|
|
130
137
|
continue;
|
|
131
138
|
}
|
|
132
|
-
if ((tag & 7)
|
|
139
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
133
140
|
break;
|
|
134
141
|
}
|
|
135
142
|
reader.skipType(tag & 7);
|
|
@@ -138,16 +145,22 @@ exports.SaveVariableRequest = {
|
|
|
138
145
|
},
|
|
139
146
|
fromJSON(object) {
|
|
140
147
|
return {
|
|
141
|
-
room: isSet(object.room) ? String(object.room) : "",
|
|
142
|
-
name: isSet(object.name) ? String(object.name) : "",
|
|
148
|
+
room: isSet(object.room) ? globalThis.String(object.room) : "",
|
|
149
|
+
name: isSet(object.name) ? globalThis.String(object.name) : "",
|
|
143
150
|
value: isSet(object?.value) ? object.value : undefined,
|
|
144
151
|
};
|
|
145
152
|
},
|
|
146
153
|
toJSON(message) {
|
|
147
154
|
const obj = {};
|
|
148
|
-
message.room !==
|
|
149
|
-
|
|
150
|
-
|
|
155
|
+
if (message.room !== "") {
|
|
156
|
+
obj.room = message.room;
|
|
157
|
+
}
|
|
158
|
+
if (message.name !== "") {
|
|
159
|
+
obj.name = message.name;
|
|
160
|
+
}
|
|
161
|
+
if (message.value !== undefined) {
|
|
162
|
+
obj.value = message.value;
|
|
163
|
+
}
|
|
151
164
|
return obj;
|
|
152
165
|
},
|
|
153
166
|
create(base) {
|
|
@@ -161,6 +174,243 @@ exports.SaveVariableRequest = {
|
|
|
161
174
|
return message;
|
|
162
175
|
},
|
|
163
176
|
};
|
|
177
|
+
function createBaseEventRequest() {
|
|
178
|
+
return { room: "", name: "" };
|
|
179
|
+
}
|
|
180
|
+
exports.EventRequest = {
|
|
181
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
182
|
+
if (message.room !== "") {
|
|
183
|
+
writer.uint32(10).string(message.room);
|
|
184
|
+
}
|
|
185
|
+
if (message.name !== "") {
|
|
186
|
+
writer.uint32(18).string(message.name);
|
|
187
|
+
}
|
|
188
|
+
return writer;
|
|
189
|
+
},
|
|
190
|
+
decode(input, length) {
|
|
191
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
192
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
193
|
+
const message = createBaseEventRequest();
|
|
194
|
+
while (reader.pos < end) {
|
|
195
|
+
const tag = reader.uint32();
|
|
196
|
+
switch (tag >>> 3) {
|
|
197
|
+
case 1:
|
|
198
|
+
if (tag !== 10) {
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
message.room = reader.string();
|
|
202
|
+
continue;
|
|
203
|
+
case 2:
|
|
204
|
+
if (tag !== 18) {
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
message.name = reader.string();
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
reader.skipType(tag & 7);
|
|
214
|
+
}
|
|
215
|
+
return message;
|
|
216
|
+
},
|
|
217
|
+
fromJSON(object) {
|
|
218
|
+
return {
|
|
219
|
+
room: isSet(object.room) ? globalThis.String(object.room) : "",
|
|
220
|
+
name: isSet(object.name) ? globalThis.String(object.name) : "",
|
|
221
|
+
};
|
|
222
|
+
},
|
|
223
|
+
toJSON(message) {
|
|
224
|
+
const obj = {};
|
|
225
|
+
if (message.room !== "") {
|
|
226
|
+
obj.room = message.room;
|
|
227
|
+
}
|
|
228
|
+
if (message.name !== "") {
|
|
229
|
+
obj.name = message.name;
|
|
230
|
+
}
|
|
231
|
+
return obj;
|
|
232
|
+
},
|
|
233
|
+
create(base) {
|
|
234
|
+
return exports.EventRequest.fromPartial(base ?? {});
|
|
235
|
+
},
|
|
236
|
+
fromPartial(object) {
|
|
237
|
+
const message = createBaseEventRequest();
|
|
238
|
+
message.room = object.room ?? "";
|
|
239
|
+
message.name = object.name ?? "";
|
|
240
|
+
return message;
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
function createBaseEventResponse() {
|
|
244
|
+
return { data: undefined, senderId: undefined };
|
|
245
|
+
}
|
|
246
|
+
exports.EventResponse = {
|
|
247
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
248
|
+
if (message.data !== undefined) {
|
|
249
|
+
struct_1.Value.encode(struct_1.Value.wrap(message.data), writer.uint32(10).fork()).ldelim();
|
|
250
|
+
}
|
|
251
|
+
if (message.senderId !== undefined) {
|
|
252
|
+
writer.uint32(16).int32(message.senderId);
|
|
253
|
+
}
|
|
254
|
+
return writer;
|
|
255
|
+
},
|
|
256
|
+
decode(input, length) {
|
|
257
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
258
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
259
|
+
const message = createBaseEventResponse();
|
|
260
|
+
while (reader.pos < end) {
|
|
261
|
+
const tag = reader.uint32();
|
|
262
|
+
switch (tag >>> 3) {
|
|
263
|
+
case 1:
|
|
264
|
+
if (tag !== 10) {
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
message.data = struct_1.Value.unwrap(struct_1.Value.decode(reader, reader.uint32()));
|
|
268
|
+
continue;
|
|
269
|
+
case 2:
|
|
270
|
+
if (tag !== 16) {
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
message.senderId = reader.int32();
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
reader.skipType(tag & 7);
|
|
280
|
+
}
|
|
281
|
+
return message;
|
|
282
|
+
},
|
|
283
|
+
fromJSON(object) {
|
|
284
|
+
return {
|
|
285
|
+
data: isSet(object?.data) ? object.data : undefined,
|
|
286
|
+
senderId: isSet(object.senderId) ? globalThis.Number(object.senderId) : undefined,
|
|
287
|
+
};
|
|
288
|
+
},
|
|
289
|
+
toJSON(message) {
|
|
290
|
+
const obj = {};
|
|
291
|
+
if (message.data !== undefined) {
|
|
292
|
+
obj.data = message.data;
|
|
293
|
+
}
|
|
294
|
+
if (message.senderId !== undefined) {
|
|
295
|
+
obj.senderId = Math.round(message.senderId);
|
|
296
|
+
}
|
|
297
|
+
return obj;
|
|
298
|
+
},
|
|
299
|
+
create(base) {
|
|
300
|
+
return exports.EventResponse.fromPartial(base ?? {});
|
|
301
|
+
},
|
|
302
|
+
fromPartial(object) {
|
|
303
|
+
const message = createBaseEventResponse();
|
|
304
|
+
message.data = object.data ?? undefined;
|
|
305
|
+
message.senderId = object.senderId ?? undefined;
|
|
306
|
+
return message;
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
function createBaseDispatchEventRequest() {
|
|
310
|
+
return { room: "", name: "", data: undefined, targetUserIds: [] };
|
|
311
|
+
}
|
|
312
|
+
exports.DispatchEventRequest = {
|
|
313
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
314
|
+
if (message.room !== "") {
|
|
315
|
+
writer.uint32(10).string(message.room);
|
|
316
|
+
}
|
|
317
|
+
if (message.name !== "") {
|
|
318
|
+
writer.uint32(18).string(message.name);
|
|
319
|
+
}
|
|
320
|
+
if (message.data !== undefined) {
|
|
321
|
+
struct_1.Value.encode(struct_1.Value.wrap(message.data), writer.uint32(26).fork()).ldelim();
|
|
322
|
+
}
|
|
323
|
+
writer.uint32(34).fork();
|
|
324
|
+
for (const v of message.targetUserIds) {
|
|
325
|
+
writer.int32(v);
|
|
326
|
+
}
|
|
327
|
+
writer.ldelim();
|
|
328
|
+
return writer;
|
|
329
|
+
},
|
|
330
|
+
decode(input, length) {
|
|
331
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
332
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
333
|
+
const message = createBaseDispatchEventRequest();
|
|
334
|
+
while (reader.pos < end) {
|
|
335
|
+
const tag = reader.uint32();
|
|
336
|
+
switch (tag >>> 3) {
|
|
337
|
+
case 1:
|
|
338
|
+
if (tag !== 10) {
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
message.room = reader.string();
|
|
342
|
+
continue;
|
|
343
|
+
case 2:
|
|
344
|
+
if (tag !== 18) {
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
message.name = reader.string();
|
|
348
|
+
continue;
|
|
349
|
+
case 3:
|
|
350
|
+
if (tag !== 26) {
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
message.data = struct_1.Value.unwrap(struct_1.Value.decode(reader, reader.uint32()));
|
|
354
|
+
continue;
|
|
355
|
+
case 4:
|
|
356
|
+
if (tag === 32) {
|
|
357
|
+
message.targetUserIds.push(reader.int32());
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (tag === 34) {
|
|
361
|
+
const end2 = reader.uint32() + reader.pos;
|
|
362
|
+
while (reader.pos < end2) {
|
|
363
|
+
message.targetUserIds.push(reader.int32());
|
|
364
|
+
}
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
reader.skipType(tag & 7);
|
|
373
|
+
}
|
|
374
|
+
return message;
|
|
375
|
+
},
|
|
376
|
+
fromJSON(object) {
|
|
377
|
+
return {
|
|
378
|
+
room: isSet(object.room) ? globalThis.String(object.room) : "",
|
|
379
|
+
name: isSet(object.name) ? globalThis.String(object.name) : "",
|
|
380
|
+
data: isSet(object?.data) ? object.data : undefined,
|
|
381
|
+
targetUserIds: globalThis.Array.isArray(object?.targetUserIds)
|
|
382
|
+
? object.targetUserIds.map((e) => globalThis.Number(e))
|
|
383
|
+
: [],
|
|
384
|
+
};
|
|
385
|
+
},
|
|
386
|
+
toJSON(message) {
|
|
387
|
+
const obj = {};
|
|
388
|
+
if (message.room !== "") {
|
|
389
|
+
obj.room = message.room;
|
|
390
|
+
}
|
|
391
|
+
if (message.name !== "") {
|
|
392
|
+
obj.name = message.name;
|
|
393
|
+
}
|
|
394
|
+
if (message.data !== undefined) {
|
|
395
|
+
obj.data = message.data;
|
|
396
|
+
}
|
|
397
|
+
if (message.targetUserIds?.length) {
|
|
398
|
+
obj.targetUserIds = message.targetUserIds.map((e) => Math.round(e));
|
|
399
|
+
}
|
|
400
|
+
return obj;
|
|
401
|
+
},
|
|
402
|
+
create(base) {
|
|
403
|
+
return exports.DispatchEventRequest.fromPartial(base ?? {});
|
|
404
|
+
},
|
|
405
|
+
fromPartial(object) {
|
|
406
|
+
const message = createBaseDispatchEventRequest();
|
|
407
|
+
message.room = object.room ?? "";
|
|
408
|
+
message.name = object.name ?? "";
|
|
409
|
+
message.data = object.data ?? undefined;
|
|
410
|
+
message.targetUserIds = object.targetUserIds?.map((e) => e) || [];
|
|
411
|
+
return message;
|
|
412
|
+
},
|
|
413
|
+
};
|
|
164
414
|
exports.RoomApiDefinition = {
|
|
165
415
|
name: "RoomApi",
|
|
166
416
|
fullName: "roomApi.RoomApi",
|
|
@@ -192,6 +442,24 @@ exports.RoomApiDefinition = {
|
|
|
192
442
|
responseStream: false,
|
|
193
443
|
options: {},
|
|
194
444
|
},
|
|
445
|
+
/** Dispatch an event to all users in the room */
|
|
446
|
+
broadcastEvent: {
|
|
447
|
+
name: "broadcastEvent",
|
|
448
|
+
requestType: exports.DispatchEventRequest,
|
|
449
|
+
requestStream: false,
|
|
450
|
+
responseType: empty_1.Empty,
|
|
451
|
+
responseStream: false,
|
|
452
|
+
options: {},
|
|
453
|
+
},
|
|
454
|
+
/** Listen to events dispatched in the room */
|
|
455
|
+
listenToEvent: {
|
|
456
|
+
name: "listenToEvent",
|
|
457
|
+
requestType: exports.EventRequest,
|
|
458
|
+
requestStream: false,
|
|
459
|
+
responseType: exports.EventResponse,
|
|
460
|
+
responseStream: true,
|
|
461
|
+
options: {},
|
|
462
|
+
},
|
|
195
463
|
},
|
|
196
464
|
};
|
|
197
465
|
function isSet(value) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_1 = require("./index");
|
|
4
|
+
const apiKey = process.env.ROOM_API_SECRET_KEY;
|
|
5
|
+
if (!apiKey) {
|
|
6
|
+
throw new Error("No ROOM_API_SECRET_KEY defined on environment variables!");
|
|
7
|
+
}
|
|
8
|
+
const client = (0, index_1.createRoomApiClient)(apiKey, "room-api.workadventure.localhost", 80);
|
|
9
|
+
// URL of the room you wish to interact with
|
|
10
|
+
const roomUrl = "http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json";
|
|
11
|
+
// Name of the event with which you want to interact
|
|
12
|
+
const eventName = "my-event";
|
|
13
|
+
async function init() {
|
|
14
|
+
// Send an event in 5 seconds
|
|
15
|
+
setTimeout(async () => {
|
|
16
|
+
console.log("Sending event: { foo: \"Default Value\" }");
|
|
17
|
+
await client.broadcastEvent({
|
|
18
|
+
name: eventName,
|
|
19
|
+
room: roomUrl,
|
|
20
|
+
data: { foo: "Default Value" },
|
|
21
|
+
});
|
|
22
|
+
console.log("Event sent: { foo: \"Default Value\" }");
|
|
23
|
+
}, 1000);
|
|
24
|
+
// Listen a event
|
|
25
|
+
const events = client.listenToEvent({
|
|
26
|
+
name: eventName,
|
|
27
|
+
room: roomUrl,
|
|
28
|
+
});
|
|
29
|
+
for await (const event of events) {
|
|
30
|
+
console.log("Event", event);
|
|
31
|
+
console.log("Sender:", event.senderId);
|
|
32
|
+
console.log("Value:", event.data);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
init();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -22,6 +22,7 @@ async function init() {
|
|
|
22
22
|
name: variableName,
|
|
23
23
|
room: roomUrl,
|
|
24
24
|
});
|
|
25
|
+
console.log("Value read plain:", value);
|
|
25
26
|
console.log("Value read:", struct_1.Value.unwrap(value));
|
|
26
27
|
// Save a variable in 5sec
|
|
27
28
|
setTimeout(async () => {
|
|
@@ -38,6 +39,7 @@ async function init() {
|
|
|
38
39
|
room: roomUrl,
|
|
39
40
|
});
|
|
40
41
|
for await (const value of listenVariable) {
|
|
42
|
+
console.log("Value listened plain:", value);
|
|
41
43
|
console.log("Value listened:", struct_1.Value.unwrap(value));
|
|
42
44
|
break;
|
|
43
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workadventure/room-api-client",
|
|
3
|
-
"version": "v1.
|
|
3
|
+
"version": "v1.18.3",
|
|
4
4
|
"description": "Workadventure Room Api Client",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"ts-proto": "grpc_tools_node_protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./src/compiled_proto --ts_proto_opt=\"outputServices=nice-grpc,outputServices=generic-definitions,useExactTypes=false\" --proto_path=../../../messages/protos ../../../messages/protos/room-api.proto",
|
|
12
12
|
"build": "tsc --build",
|
|
13
|
-
"example": "tsx ./src/
|
|
13
|
+
"example-variables": "tsx ./src/example_variables.ts",
|
|
14
|
+
"example-events": "tsx ./src/example_events.ts",
|
|
14
15
|
"lint": "eslint --ext .js,.ts .",
|
|
15
16
|
"lint-fix": "eslint --fix --ext .js,.ts .",
|
|
16
17
|
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"",
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"grpc-tools": "^1.12.4",
|
|
49
50
|
"lint-staged": "^13.2.0",
|
|
50
51
|
"prettier": "^2.8.6",
|
|
51
|
-
"ts-proto": "^1.
|
|
52
|
+
"ts-proto": "^1.164.1",
|
|
52
53
|
"tsx": "^3.12.10",
|
|
53
54
|
"typescript": "^5.0.2"
|
|
54
55
|
},
|
|
File without changes
|