@workadventure/room-api-client 1.0.0
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/LICENSE.txt +21 -0
- package/README.md +79 -0
- package/dist/compiled_proto/google/protobuf/empty.d.ts +28 -0
- package/dist/compiled_proto/google/protobuf/empty.js +66 -0
- package/dist/compiled_proto/google/protobuf/struct.d.ts +115 -0
- package/dist/compiled_proto/google/protobuf/struct.js +446 -0
- package/dist/compiled_proto/room-api.d.ts +170 -0
- package/dist/compiled_proto/room-api.js +199 -0
- package/dist/example.d.ts +1 -0
- package/dist/example.js +45 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +30 -0
- package/package.json +62 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 WorkAdventu.re
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
|
|
2
|
+
# @workadventure/room-api-client
|
|
3
|
+
|
|
4
|
+
Easily create a GRPC client to connect your service to the [Room API](https://github.com/thecodingmachine/workadventure/blob/master/docs/master/roomAPI.md) of a [WorkAdventure](https://workadventu.re) server.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @workadventure/room-api-client
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage/Examples
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import { createRoomApiClient } from "@workadventure/room-api-client";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* By default, the client targets the official WorkAdventure server,
|
|
20
|
+
* but you can also define customs domain and port.
|
|
21
|
+
* Example :
|
|
22
|
+
* const client = createRoomApiClient("My AWESOME KEY", "mydomain.net", "5221");
|
|
23
|
+
*/
|
|
24
|
+
const client = createRoomApiClient("My AWESOME KEY");
|
|
25
|
+
|
|
26
|
+
// URL of the room you wish to interact with
|
|
27
|
+
const roomUrl = "https://play.workadventu.re/@/my-team/my-world";
|
|
28
|
+
|
|
29
|
+
// Name of the variable with which you want to interact
|
|
30
|
+
const variableName = "textField";
|
|
31
|
+
|
|
32
|
+
async function init() {
|
|
33
|
+
// Save a variable
|
|
34
|
+
await client.saveVariable({
|
|
35
|
+
name: variableName,
|
|
36
|
+
room: roomUrl,
|
|
37
|
+
value: "Default Value",
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
console.log("Value saved: Default Value");
|
|
41
|
+
|
|
42
|
+
// Read a variable
|
|
43
|
+
const value = await client.readVariable({
|
|
44
|
+
name: variableName,
|
|
45
|
+
room: roomUrl,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
console.log("Value read:", Value.unwrap(value));
|
|
49
|
+
|
|
50
|
+
// Save a variable in 5sec
|
|
51
|
+
setTimeout(async () => {
|
|
52
|
+
await client.saveVariable({
|
|
53
|
+
name: variableName,
|
|
54
|
+
room: roomUrl,
|
|
55
|
+
value: "New Value",
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
console.log("Value saved: New Value");
|
|
59
|
+
}, 5000);
|
|
60
|
+
|
|
61
|
+
// Listen a variable
|
|
62
|
+
const listenVariable = client.listenVariable({
|
|
63
|
+
name: variableName,
|
|
64
|
+
room: roomUrl,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
for await (const value of listenVariable) {
|
|
68
|
+
console.log("Value listened:", Value.unwrap(value));
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
init();
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Warning
|
|
78
|
+
|
|
79
|
+
You can see in the example we are using the `Value.unwrap` function, this is because the variable functions return a `Value` object, which is a wrapper around the actual value. 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.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as _m0 from "protobufjs/minimal";
|
|
2
|
+
export declare const protobufPackage = "google.protobuf";
|
|
3
|
+
/**
|
|
4
|
+
* A generic empty message that you can re-use to avoid defining duplicated
|
|
5
|
+
* empty messages in your APIs. A typical example is to use it as the request
|
|
6
|
+
* or the response type of an API method. For instance:
|
|
7
|
+
*
|
|
8
|
+
* service Foo {
|
|
9
|
+
* rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* The JSON representation for `Empty` is empty JSON object `{}`.
|
|
13
|
+
*/
|
|
14
|
+
export interface Empty {
|
|
15
|
+
}
|
|
16
|
+
export declare const Empty: {
|
|
17
|
+
encode(_: Empty, writer?: _m0.Writer): _m0.Writer;
|
|
18
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): Empty;
|
|
19
|
+
fromJSON(_: any): Empty;
|
|
20
|
+
toJSON(_: Empty): unknown;
|
|
21
|
+
create(base?: DeepPartial<Empty>): Empty;
|
|
22
|
+
fromPartial(_: DeepPartial<Empty>): Empty;
|
|
23
|
+
};
|
|
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 {} ? {
|
|
26
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
27
|
+
} : Partial<T>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Empty = exports.protobufPackage = void 0;
|
|
27
|
+
/* eslint-disable */
|
|
28
|
+
const _m0 = __importStar(require("protobufjs/minimal"));
|
|
29
|
+
exports.protobufPackage = "google.protobuf";
|
|
30
|
+
function createBaseEmpty() {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
exports.Empty = {
|
|
34
|
+
encode(_, writer = _m0.Writer.create()) {
|
|
35
|
+
return writer;
|
|
36
|
+
},
|
|
37
|
+
decode(input, length) {
|
|
38
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
39
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
40
|
+
const message = createBaseEmpty();
|
|
41
|
+
while (reader.pos < end) {
|
|
42
|
+
const tag = reader.uint32();
|
|
43
|
+
switch (tag >>> 3) {
|
|
44
|
+
}
|
|
45
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
reader.skipType(tag & 7);
|
|
49
|
+
}
|
|
50
|
+
return message;
|
|
51
|
+
},
|
|
52
|
+
fromJSON(_) {
|
|
53
|
+
return {};
|
|
54
|
+
},
|
|
55
|
+
toJSON(_) {
|
|
56
|
+
const obj = {};
|
|
57
|
+
return obj;
|
|
58
|
+
},
|
|
59
|
+
create(base) {
|
|
60
|
+
return exports.Empty.fromPartial(base ?? {});
|
|
61
|
+
},
|
|
62
|
+
fromPartial(_) {
|
|
63
|
+
const message = createBaseEmpty();
|
|
64
|
+
return message;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as _m0 from "protobufjs/minimal";
|
|
2
|
+
export declare const protobufPackage = "google.protobuf";
|
|
3
|
+
/**
|
|
4
|
+
* `NullValue` is a singleton enumeration to represent the null value for the
|
|
5
|
+
* `Value` type union.
|
|
6
|
+
*
|
|
7
|
+
* The JSON representation for `NullValue` is JSON `null`.
|
|
8
|
+
*/
|
|
9
|
+
export declare enum NullValue {
|
|
10
|
+
/** NULL_VALUE - Null value. */
|
|
11
|
+
NULL_VALUE = 0,
|
|
12
|
+
UNRECOGNIZED = -1
|
|
13
|
+
}
|
|
14
|
+
export declare function nullValueFromJSON(object: any): NullValue;
|
|
15
|
+
export declare function nullValueToJSON(object: NullValue): string;
|
|
16
|
+
/**
|
|
17
|
+
* `Struct` represents a structured data value, consisting of fields
|
|
18
|
+
* which map to dynamically typed values. In some languages, `Struct`
|
|
19
|
+
* might be supported by a native representation. For example, in
|
|
20
|
+
* scripting languages like JS a struct is represented as an
|
|
21
|
+
* object. The details of that representation are described together
|
|
22
|
+
* with the proto support for the language.
|
|
23
|
+
*
|
|
24
|
+
* The JSON representation for `Struct` is JSON object.
|
|
25
|
+
*/
|
|
26
|
+
export interface Struct {
|
|
27
|
+
/** Unordered map of dynamically typed values. */
|
|
28
|
+
fields: {
|
|
29
|
+
[key: string]: any | undefined;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface Struct_FieldsEntry {
|
|
33
|
+
key: string;
|
|
34
|
+
value: any | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* `Value` represents a dynamically typed value which can be either
|
|
38
|
+
* null, a number, a string, a boolean, a recursive struct value, or a
|
|
39
|
+
* list of values. A producer of value is expected to set one of these
|
|
40
|
+
* variants. Absence of any variant indicates an error.
|
|
41
|
+
*
|
|
42
|
+
* The JSON representation for `Value` is JSON value.
|
|
43
|
+
*/
|
|
44
|
+
export interface Value {
|
|
45
|
+
/** Represents a null value. */
|
|
46
|
+
nullValue?: NullValue | undefined;
|
|
47
|
+
/** Represents a double value. */
|
|
48
|
+
numberValue?: number | undefined;
|
|
49
|
+
/** Represents a string value. */
|
|
50
|
+
stringValue?: string | undefined;
|
|
51
|
+
/** Represents a boolean value. */
|
|
52
|
+
boolValue?: boolean | undefined;
|
|
53
|
+
/** Represents a structured value. */
|
|
54
|
+
structValue?: {
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
} | undefined;
|
|
57
|
+
/** Represents a repeated `Value`. */
|
|
58
|
+
listValue?: Array<any> | undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* `ListValue` is a wrapper around a repeated field of values.
|
|
62
|
+
*
|
|
63
|
+
* The JSON representation for `ListValue` is JSON array.
|
|
64
|
+
*/
|
|
65
|
+
export interface ListValue {
|
|
66
|
+
/** Repeated field of dynamically typed values. */
|
|
67
|
+
values: any[];
|
|
68
|
+
}
|
|
69
|
+
export declare const Struct: {
|
|
70
|
+
encode(message: Struct, writer?: _m0.Writer): _m0.Writer;
|
|
71
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): Struct;
|
|
72
|
+
fromJSON(object: any): Struct;
|
|
73
|
+
toJSON(message: Struct): unknown;
|
|
74
|
+
create(base?: DeepPartial<Struct>): Struct;
|
|
75
|
+
fromPartial(object: DeepPartial<Struct>): Struct;
|
|
76
|
+
wrap(object: {
|
|
77
|
+
[key: string]: any;
|
|
78
|
+
} | undefined): Struct;
|
|
79
|
+
unwrap(message: Struct): {
|
|
80
|
+
[key: string]: any;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
export declare const Struct_FieldsEntry: {
|
|
84
|
+
encode(message: Struct_FieldsEntry, writer?: _m0.Writer): _m0.Writer;
|
|
85
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): Struct_FieldsEntry;
|
|
86
|
+
fromJSON(object: any): Struct_FieldsEntry;
|
|
87
|
+
toJSON(message: Struct_FieldsEntry): unknown;
|
|
88
|
+
create(base?: DeepPartial<Struct_FieldsEntry>): Struct_FieldsEntry;
|
|
89
|
+
fromPartial(object: DeepPartial<Struct_FieldsEntry>): Struct_FieldsEntry;
|
|
90
|
+
};
|
|
91
|
+
export declare const Value: {
|
|
92
|
+
encode(message: Value, writer?: _m0.Writer): _m0.Writer;
|
|
93
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): Value;
|
|
94
|
+
fromJSON(object: any): Value;
|
|
95
|
+
toJSON(message: Value): unknown;
|
|
96
|
+
create(base?: DeepPartial<Value>): Value;
|
|
97
|
+
fromPartial(object: DeepPartial<Value>): Value;
|
|
98
|
+
wrap(value: any): Value;
|
|
99
|
+
unwrap(message: any): string | number | boolean | Object | null | Array<any> | undefined;
|
|
100
|
+
};
|
|
101
|
+
export declare const ListValue: {
|
|
102
|
+
encode(message: ListValue, writer?: _m0.Writer): _m0.Writer;
|
|
103
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): ListValue;
|
|
104
|
+
fromJSON(object: any): ListValue;
|
|
105
|
+
toJSON(message: ListValue): unknown;
|
|
106
|
+
create(base?: DeepPartial<ListValue>): ListValue;
|
|
107
|
+
fromPartial(object: DeepPartial<ListValue>): ListValue;
|
|
108
|
+
wrap(array: Array<any> | undefined): ListValue;
|
|
109
|
+
unwrap(message: ListValue): Array<any>;
|
|
110
|
+
};
|
|
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 {} ? {
|
|
113
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
114
|
+
} : Partial<T>;
|
|
115
|
+
export {};
|
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ListValue = exports.Value = exports.Struct_FieldsEntry = exports.Struct = exports.nullValueToJSON = exports.nullValueFromJSON = exports.NullValue = exports.protobufPackage = void 0;
|
|
27
|
+
/* eslint-disable */
|
|
28
|
+
const _m0 = __importStar(require("protobufjs/minimal"));
|
|
29
|
+
exports.protobufPackage = "google.protobuf";
|
|
30
|
+
/**
|
|
31
|
+
* `NullValue` is a singleton enumeration to represent the null value for the
|
|
32
|
+
* `Value` type union.
|
|
33
|
+
*
|
|
34
|
+
* The JSON representation for `NullValue` is JSON `null`.
|
|
35
|
+
*/
|
|
36
|
+
var NullValue;
|
|
37
|
+
(function (NullValue) {
|
|
38
|
+
/** NULL_VALUE - Null value. */
|
|
39
|
+
NullValue[NullValue["NULL_VALUE"] = 0] = "NULL_VALUE";
|
|
40
|
+
NullValue[NullValue["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
|
|
41
|
+
})(NullValue = exports.NullValue || (exports.NullValue = {}));
|
|
42
|
+
function nullValueFromJSON(object) {
|
|
43
|
+
switch (object) {
|
|
44
|
+
case 0:
|
|
45
|
+
case "NULL_VALUE":
|
|
46
|
+
return NullValue.NULL_VALUE;
|
|
47
|
+
case -1:
|
|
48
|
+
case "UNRECOGNIZED":
|
|
49
|
+
default:
|
|
50
|
+
return NullValue.UNRECOGNIZED;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.nullValueFromJSON = nullValueFromJSON;
|
|
54
|
+
function nullValueToJSON(object) {
|
|
55
|
+
switch (object) {
|
|
56
|
+
case NullValue.NULL_VALUE:
|
|
57
|
+
return "NULL_VALUE";
|
|
58
|
+
case NullValue.UNRECOGNIZED:
|
|
59
|
+
default:
|
|
60
|
+
return "UNRECOGNIZED";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.nullValueToJSON = nullValueToJSON;
|
|
64
|
+
function createBaseStruct() {
|
|
65
|
+
return { fields: {} };
|
|
66
|
+
}
|
|
67
|
+
exports.Struct = {
|
|
68
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
69
|
+
Object.entries(message.fields).forEach(([key, value]) => {
|
|
70
|
+
if (value !== undefined) {
|
|
71
|
+
exports.Struct_FieldsEntry.encode({ key: key, value }, writer.uint32(10).fork()).ldelim();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return writer;
|
|
75
|
+
},
|
|
76
|
+
decode(input, length) {
|
|
77
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
78
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
79
|
+
const message = createBaseStruct();
|
|
80
|
+
while (reader.pos < end) {
|
|
81
|
+
const tag = reader.uint32();
|
|
82
|
+
switch (tag >>> 3) {
|
|
83
|
+
case 1:
|
|
84
|
+
if (tag != 10) {
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
const entry1 = exports.Struct_FieldsEntry.decode(reader, reader.uint32());
|
|
88
|
+
if (entry1.value !== undefined) {
|
|
89
|
+
message.fields[entry1.key] = entry1.value;
|
|
90
|
+
}
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
reader.skipType(tag & 7);
|
|
97
|
+
}
|
|
98
|
+
return message;
|
|
99
|
+
},
|
|
100
|
+
fromJSON(object) {
|
|
101
|
+
return {
|
|
102
|
+
fields: isObject(object.fields)
|
|
103
|
+
? Object.entries(object.fields).reduce((acc, [key, value]) => {
|
|
104
|
+
acc[key] = value;
|
|
105
|
+
return acc;
|
|
106
|
+
}, {})
|
|
107
|
+
: {},
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
toJSON(message) {
|
|
111
|
+
const obj = {};
|
|
112
|
+
obj.fields = {};
|
|
113
|
+
if (message.fields) {
|
|
114
|
+
Object.entries(message.fields).forEach(([k, v]) => {
|
|
115
|
+
obj.fields[k] = v;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return obj;
|
|
119
|
+
},
|
|
120
|
+
create(base) {
|
|
121
|
+
return exports.Struct.fromPartial(base ?? {});
|
|
122
|
+
},
|
|
123
|
+
fromPartial(object) {
|
|
124
|
+
const message = createBaseStruct();
|
|
125
|
+
message.fields = Object.entries(object.fields ?? {}).reduce((acc, [key, value]) => {
|
|
126
|
+
if (value !== undefined) {
|
|
127
|
+
acc[key] = value;
|
|
128
|
+
}
|
|
129
|
+
return acc;
|
|
130
|
+
}, {});
|
|
131
|
+
return message;
|
|
132
|
+
},
|
|
133
|
+
wrap(object) {
|
|
134
|
+
const struct = createBaseStruct();
|
|
135
|
+
if (object !== undefined) {
|
|
136
|
+
Object.keys(object).forEach((key) => {
|
|
137
|
+
struct.fields[key] = object[key];
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return struct;
|
|
141
|
+
},
|
|
142
|
+
unwrap(message) {
|
|
143
|
+
const object = {};
|
|
144
|
+
if (message.fields) {
|
|
145
|
+
Object.keys(message.fields).forEach((key) => {
|
|
146
|
+
object[key] = message.fields[key];
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return object;
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
function createBaseStruct_FieldsEntry() {
|
|
153
|
+
return { key: "", value: undefined };
|
|
154
|
+
}
|
|
155
|
+
exports.Struct_FieldsEntry = {
|
|
156
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
157
|
+
if (message.key !== "") {
|
|
158
|
+
writer.uint32(10).string(message.key);
|
|
159
|
+
}
|
|
160
|
+
if (message.value !== undefined) {
|
|
161
|
+
exports.Value.encode(exports.Value.wrap(message.value), writer.uint32(18).fork()).ldelim();
|
|
162
|
+
}
|
|
163
|
+
return writer;
|
|
164
|
+
},
|
|
165
|
+
decode(input, length) {
|
|
166
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
167
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
168
|
+
const message = createBaseStruct_FieldsEntry();
|
|
169
|
+
while (reader.pos < end) {
|
|
170
|
+
const tag = reader.uint32();
|
|
171
|
+
switch (tag >>> 3) {
|
|
172
|
+
case 1:
|
|
173
|
+
if (tag != 10) {
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
message.key = reader.string();
|
|
177
|
+
continue;
|
|
178
|
+
case 2:
|
|
179
|
+
if (tag != 18) {
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
message.value = exports.Value.unwrap(exports.Value.decode(reader, reader.uint32()));
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
reader.skipType(tag & 7);
|
|
189
|
+
}
|
|
190
|
+
return message;
|
|
191
|
+
},
|
|
192
|
+
fromJSON(object) {
|
|
193
|
+
return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined };
|
|
194
|
+
},
|
|
195
|
+
toJSON(message) {
|
|
196
|
+
const obj = {};
|
|
197
|
+
message.key !== undefined && (obj.key = message.key);
|
|
198
|
+
message.value !== undefined && (obj.value = message.value);
|
|
199
|
+
return obj;
|
|
200
|
+
},
|
|
201
|
+
create(base) {
|
|
202
|
+
return exports.Struct_FieldsEntry.fromPartial(base ?? {});
|
|
203
|
+
},
|
|
204
|
+
fromPartial(object) {
|
|
205
|
+
const message = createBaseStruct_FieldsEntry();
|
|
206
|
+
message.key = object.key ?? "";
|
|
207
|
+
message.value = object.value ?? undefined;
|
|
208
|
+
return message;
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
function createBaseValue() {
|
|
212
|
+
return {
|
|
213
|
+
nullValue: undefined,
|
|
214
|
+
numberValue: undefined,
|
|
215
|
+
stringValue: undefined,
|
|
216
|
+
boolValue: undefined,
|
|
217
|
+
structValue: undefined,
|
|
218
|
+
listValue: undefined,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
exports.Value = {
|
|
222
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
223
|
+
if (message.nullValue !== undefined) {
|
|
224
|
+
writer.uint32(8).int32(message.nullValue);
|
|
225
|
+
}
|
|
226
|
+
if (message.numberValue !== undefined) {
|
|
227
|
+
writer.uint32(17).double(message.numberValue);
|
|
228
|
+
}
|
|
229
|
+
if (message.stringValue !== undefined) {
|
|
230
|
+
writer.uint32(26).string(message.stringValue);
|
|
231
|
+
}
|
|
232
|
+
if (message.boolValue !== undefined) {
|
|
233
|
+
writer.uint32(32).bool(message.boolValue);
|
|
234
|
+
}
|
|
235
|
+
if (message.structValue !== undefined) {
|
|
236
|
+
exports.Struct.encode(exports.Struct.wrap(message.structValue), writer.uint32(42).fork()).ldelim();
|
|
237
|
+
}
|
|
238
|
+
if (message.listValue !== undefined) {
|
|
239
|
+
exports.ListValue.encode(exports.ListValue.wrap(message.listValue), writer.uint32(50).fork()).ldelim();
|
|
240
|
+
}
|
|
241
|
+
return writer;
|
|
242
|
+
},
|
|
243
|
+
decode(input, length) {
|
|
244
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
245
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
246
|
+
const message = createBaseValue();
|
|
247
|
+
while (reader.pos < end) {
|
|
248
|
+
const tag = reader.uint32();
|
|
249
|
+
switch (tag >>> 3) {
|
|
250
|
+
case 1:
|
|
251
|
+
if (tag != 8) {
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
message.nullValue = reader.int32();
|
|
255
|
+
continue;
|
|
256
|
+
case 2:
|
|
257
|
+
if (tag != 17) {
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
message.numberValue = reader.double();
|
|
261
|
+
continue;
|
|
262
|
+
case 3:
|
|
263
|
+
if (tag != 26) {
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
message.stringValue = reader.string();
|
|
267
|
+
continue;
|
|
268
|
+
case 4:
|
|
269
|
+
if (tag != 32) {
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
message.boolValue = reader.bool();
|
|
273
|
+
continue;
|
|
274
|
+
case 5:
|
|
275
|
+
if (tag != 42) {
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
message.structValue = exports.Struct.unwrap(exports.Struct.decode(reader, reader.uint32()));
|
|
279
|
+
continue;
|
|
280
|
+
case 6:
|
|
281
|
+
if (tag != 50) {
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
message.listValue = exports.ListValue.unwrap(exports.ListValue.decode(reader, reader.uint32()));
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
reader.skipType(tag & 7);
|
|
291
|
+
}
|
|
292
|
+
return message;
|
|
293
|
+
},
|
|
294
|
+
fromJSON(object) {
|
|
295
|
+
return {
|
|
296
|
+
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,
|
|
300
|
+
structValue: isObject(object.structValue) ? object.structValue : undefined,
|
|
301
|
+
listValue: Array.isArray(object.listValue) ? [...object.listValue] : undefined,
|
|
302
|
+
};
|
|
303
|
+
},
|
|
304
|
+
toJSON(message) {
|
|
305
|
+
const obj = {};
|
|
306
|
+
message.nullValue !== undefined &&
|
|
307
|
+
(obj.nullValue = message.nullValue !== undefined ? nullValueToJSON(message.nullValue) : undefined);
|
|
308
|
+
message.numberValue !== undefined && (obj.numberValue = message.numberValue);
|
|
309
|
+
message.stringValue !== undefined && (obj.stringValue = message.stringValue);
|
|
310
|
+
message.boolValue !== undefined && (obj.boolValue = message.boolValue);
|
|
311
|
+
message.structValue !== undefined && (obj.structValue = message.structValue);
|
|
312
|
+
message.listValue !== undefined && (obj.listValue = message.listValue);
|
|
313
|
+
return obj;
|
|
314
|
+
},
|
|
315
|
+
create(base) {
|
|
316
|
+
return exports.Value.fromPartial(base ?? {});
|
|
317
|
+
},
|
|
318
|
+
fromPartial(object) {
|
|
319
|
+
const message = createBaseValue();
|
|
320
|
+
message.nullValue = object.nullValue ?? undefined;
|
|
321
|
+
message.numberValue = object.numberValue ?? undefined;
|
|
322
|
+
message.stringValue = object.stringValue ?? undefined;
|
|
323
|
+
message.boolValue = object.boolValue ?? undefined;
|
|
324
|
+
message.structValue = object.structValue ?? undefined;
|
|
325
|
+
message.listValue = object.listValue ?? undefined;
|
|
326
|
+
return message;
|
|
327
|
+
},
|
|
328
|
+
wrap(value) {
|
|
329
|
+
const result = createBaseValue();
|
|
330
|
+
if (value === null) {
|
|
331
|
+
result.nullValue = NullValue.NULL_VALUE;
|
|
332
|
+
}
|
|
333
|
+
else if (typeof value === "boolean") {
|
|
334
|
+
result.boolValue = value;
|
|
335
|
+
}
|
|
336
|
+
else if (typeof value === "number") {
|
|
337
|
+
result.numberValue = value;
|
|
338
|
+
}
|
|
339
|
+
else if (typeof value === "string") {
|
|
340
|
+
result.stringValue = value;
|
|
341
|
+
}
|
|
342
|
+
else if (Array.isArray(value)) {
|
|
343
|
+
result.listValue = value;
|
|
344
|
+
}
|
|
345
|
+
else if (typeof value === "object") {
|
|
346
|
+
result.structValue = value;
|
|
347
|
+
}
|
|
348
|
+
else if (typeof value !== "undefined") {
|
|
349
|
+
throw new Error("Unsupported any value type: " + typeof value);
|
|
350
|
+
}
|
|
351
|
+
return result;
|
|
352
|
+
},
|
|
353
|
+
unwrap(message) {
|
|
354
|
+
if (message.stringValue !== undefined) {
|
|
355
|
+
return message.stringValue;
|
|
356
|
+
}
|
|
357
|
+
else if (message?.numberValue !== undefined) {
|
|
358
|
+
return message.numberValue;
|
|
359
|
+
}
|
|
360
|
+
else if (message?.boolValue !== undefined) {
|
|
361
|
+
return message.boolValue;
|
|
362
|
+
}
|
|
363
|
+
else if (message?.structValue !== undefined) {
|
|
364
|
+
return message.structValue;
|
|
365
|
+
}
|
|
366
|
+
else if (message?.listValue !== undefined) {
|
|
367
|
+
return message.listValue;
|
|
368
|
+
}
|
|
369
|
+
else if (message?.nullValue !== undefined) {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
return undefined;
|
|
373
|
+
},
|
|
374
|
+
};
|
|
375
|
+
function createBaseListValue() {
|
|
376
|
+
return { values: [] };
|
|
377
|
+
}
|
|
378
|
+
exports.ListValue = {
|
|
379
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
380
|
+
for (const v of message.values) {
|
|
381
|
+
exports.Value.encode(exports.Value.wrap(v), writer.uint32(10).fork()).ldelim();
|
|
382
|
+
}
|
|
383
|
+
return writer;
|
|
384
|
+
},
|
|
385
|
+
decode(input, length) {
|
|
386
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
387
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
388
|
+
const message = createBaseListValue();
|
|
389
|
+
while (reader.pos < end) {
|
|
390
|
+
const tag = reader.uint32();
|
|
391
|
+
switch (tag >>> 3) {
|
|
392
|
+
case 1:
|
|
393
|
+
if (tag != 10) {
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
message.values.push(exports.Value.unwrap(exports.Value.decode(reader, reader.uint32())));
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
reader.skipType(tag & 7);
|
|
403
|
+
}
|
|
404
|
+
return message;
|
|
405
|
+
},
|
|
406
|
+
fromJSON(object) {
|
|
407
|
+
return { values: Array.isArray(object?.values) ? [...object.values] : [] };
|
|
408
|
+
},
|
|
409
|
+
toJSON(message) {
|
|
410
|
+
const obj = {};
|
|
411
|
+
if (message.values) {
|
|
412
|
+
obj.values = message.values.map((e) => e);
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
obj.values = [];
|
|
416
|
+
}
|
|
417
|
+
return obj;
|
|
418
|
+
},
|
|
419
|
+
create(base) {
|
|
420
|
+
return exports.ListValue.fromPartial(base ?? {});
|
|
421
|
+
},
|
|
422
|
+
fromPartial(object) {
|
|
423
|
+
const message = createBaseListValue();
|
|
424
|
+
message.values = object.values?.map((e) => e) || [];
|
|
425
|
+
return message;
|
|
426
|
+
},
|
|
427
|
+
wrap(array) {
|
|
428
|
+
const result = createBaseListValue();
|
|
429
|
+
result.values = array ?? [];
|
|
430
|
+
return result;
|
|
431
|
+
},
|
|
432
|
+
unwrap(message) {
|
|
433
|
+
if (message?.hasOwnProperty("values") && Array.isArray(message.values)) {
|
|
434
|
+
return message.values;
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
return message;
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
};
|
|
441
|
+
function isObject(value) {
|
|
442
|
+
return typeof value === "object" && value !== null;
|
|
443
|
+
}
|
|
444
|
+
function isSet(value) {
|
|
445
|
+
return value !== null && value !== undefined;
|
|
446
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { CallContext, CallOptions } from "nice-grpc-common";
|
|
2
|
+
import * as _m0 from "protobufjs/minimal";
|
|
3
|
+
import { Empty } from "./google/protobuf/empty";
|
|
4
|
+
import { Value } from "./google/protobuf/struct";
|
|
5
|
+
export declare const protobufPackage = "roomApi";
|
|
6
|
+
export interface VariableRequest {
|
|
7
|
+
room: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SaveVariableRequest {
|
|
11
|
+
room: string;
|
|
12
|
+
name: string;
|
|
13
|
+
value: any | undefined;
|
|
14
|
+
}
|
|
15
|
+
export declare const VariableRequest: {
|
|
16
|
+
encode(message: VariableRequest, writer?: _m0.Writer): _m0.Writer;
|
|
17
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): VariableRequest;
|
|
18
|
+
fromJSON(object: any): VariableRequest;
|
|
19
|
+
toJSON(message: VariableRequest): unknown;
|
|
20
|
+
create(base?: DeepPartial<VariableRequest>): VariableRequest;
|
|
21
|
+
fromPartial(object: DeepPartial<VariableRequest>): VariableRequest;
|
|
22
|
+
};
|
|
23
|
+
export declare const SaveVariableRequest: {
|
|
24
|
+
encode(message: SaveVariableRequest, writer?: _m0.Writer): _m0.Writer;
|
|
25
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): SaveVariableRequest;
|
|
26
|
+
fromJSON(object: any): SaveVariableRequest;
|
|
27
|
+
toJSON(message: SaveVariableRequest): unknown;
|
|
28
|
+
create(base?: DeepPartial<SaveVariableRequest>): SaveVariableRequest;
|
|
29
|
+
fromPartial(object: DeepPartial<SaveVariableRequest>): SaveVariableRequest;
|
|
30
|
+
};
|
|
31
|
+
export type RoomApiDefinition = typeof RoomApiDefinition;
|
|
32
|
+
export declare const RoomApiDefinition: {
|
|
33
|
+
readonly name: "RoomApi";
|
|
34
|
+
readonly fullName: "roomApi.RoomApi";
|
|
35
|
+
readonly methods: {
|
|
36
|
+
/** Get the current value of the given variable */
|
|
37
|
+
readonly readVariable: {
|
|
38
|
+
readonly name: "readVariable";
|
|
39
|
+
readonly requestType: {
|
|
40
|
+
encode(message: VariableRequest, writer?: _m0.Writer): _m0.Writer;
|
|
41
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): VariableRequest;
|
|
42
|
+
fromJSON(object: any): VariableRequest;
|
|
43
|
+
toJSON(message: VariableRequest): unknown;
|
|
44
|
+
create(base?: DeepPartial<VariableRequest>): VariableRequest;
|
|
45
|
+
fromPartial(object: DeepPartial<VariableRequest>): VariableRequest;
|
|
46
|
+
};
|
|
47
|
+
readonly requestStream: false;
|
|
48
|
+
readonly responseType: {
|
|
49
|
+
encode(message: Value, writer?: _m0.Writer): _m0.Writer;
|
|
50
|
+
decode(input: Uint8Array | _m0.Reader, length?: number | undefined): Value;
|
|
51
|
+
fromJSON(object: any): Value;
|
|
52
|
+
toJSON(message: Value): unknown;
|
|
53
|
+
create(base?: {
|
|
54
|
+
nullValue?: import("./google/protobuf/struct").NullValue | undefined;
|
|
55
|
+
numberValue?: number | undefined;
|
|
56
|
+
stringValue?: string | undefined;
|
|
57
|
+
boolValue?: boolean | undefined;
|
|
58
|
+
structValue?: {
|
|
59
|
+
[x: string]: any;
|
|
60
|
+
} | undefined;
|
|
61
|
+
listValue?: any[] | undefined;
|
|
62
|
+
} | undefined): Value;
|
|
63
|
+
fromPartial(object: {
|
|
64
|
+
nullValue?: import("./google/protobuf/struct").NullValue | undefined;
|
|
65
|
+
numberValue?: number | undefined;
|
|
66
|
+
stringValue?: string | undefined;
|
|
67
|
+
boolValue?: boolean | undefined;
|
|
68
|
+
structValue?: {
|
|
69
|
+
[x: string]: any;
|
|
70
|
+
} | undefined;
|
|
71
|
+
listValue?: any[] | undefined;
|
|
72
|
+
}): Value;
|
|
73
|
+
wrap(value: any): Value;
|
|
74
|
+
unwrap(message: any): string | number | boolean | Object | any[] | null | undefined;
|
|
75
|
+
};
|
|
76
|
+
readonly responseStream: false;
|
|
77
|
+
readonly options: {};
|
|
78
|
+
};
|
|
79
|
+
/** Listen to value updates for a given variable */
|
|
80
|
+
readonly listenVariable: {
|
|
81
|
+
readonly name: "listenVariable";
|
|
82
|
+
readonly requestType: {
|
|
83
|
+
encode(message: VariableRequest, writer?: _m0.Writer): _m0.Writer;
|
|
84
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): VariableRequest;
|
|
85
|
+
fromJSON(object: any): VariableRequest;
|
|
86
|
+
toJSON(message: VariableRequest): unknown;
|
|
87
|
+
create(base?: DeepPartial<VariableRequest>): VariableRequest;
|
|
88
|
+
fromPartial(object: DeepPartial<VariableRequest>): VariableRequest;
|
|
89
|
+
};
|
|
90
|
+
readonly requestStream: false;
|
|
91
|
+
readonly responseType: {
|
|
92
|
+
encode(message: Value, writer?: _m0.Writer): _m0.Writer;
|
|
93
|
+
decode(input: Uint8Array | _m0.Reader, length?: number | undefined): Value;
|
|
94
|
+
fromJSON(object: any): Value;
|
|
95
|
+
toJSON(message: Value): unknown;
|
|
96
|
+
create(base?: {
|
|
97
|
+
nullValue?: import("./google/protobuf/struct").NullValue | undefined;
|
|
98
|
+
numberValue?: number | undefined;
|
|
99
|
+
stringValue?: string | undefined;
|
|
100
|
+
boolValue?: boolean | undefined;
|
|
101
|
+
structValue?: {
|
|
102
|
+
[x: string]: any;
|
|
103
|
+
} | undefined;
|
|
104
|
+
listValue?: any[] | undefined;
|
|
105
|
+
} | undefined): Value;
|
|
106
|
+
fromPartial(object: {
|
|
107
|
+
nullValue?: import("./google/protobuf/struct").NullValue | undefined;
|
|
108
|
+
numberValue?: number | undefined;
|
|
109
|
+
stringValue?: string | undefined;
|
|
110
|
+
boolValue?: boolean | undefined;
|
|
111
|
+
structValue?: {
|
|
112
|
+
[x: string]: any;
|
|
113
|
+
} | undefined;
|
|
114
|
+
listValue?: any[] | undefined;
|
|
115
|
+
}): Value;
|
|
116
|
+
wrap(value: any): Value;
|
|
117
|
+
unwrap(message: any): string | number | boolean | Object | any[] | null | undefined;
|
|
118
|
+
};
|
|
119
|
+
readonly responseStream: true;
|
|
120
|
+
readonly options: {};
|
|
121
|
+
};
|
|
122
|
+
/** Set the value of the given variable */
|
|
123
|
+
readonly saveVariable: {
|
|
124
|
+
readonly name: "saveVariable";
|
|
125
|
+
readonly requestType: {
|
|
126
|
+
encode(message: SaveVariableRequest, writer?: _m0.Writer): _m0.Writer;
|
|
127
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): SaveVariableRequest;
|
|
128
|
+
fromJSON(object: any): SaveVariableRequest;
|
|
129
|
+
toJSON(message: SaveVariableRequest): unknown;
|
|
130
|
+
create(base?: DeepPartial<SaveVariableRequest>): SaveVariableRequest;
|
|
131
|
+
fromPartial(object: DeepPartial<SaveVariableRequest>): SaveVariableRequest;
|
|
132
|
+
};
|
|
133
|
+
readonly requestStream: false;
|
|
134
|
+
readonly responseType: {
|
|
135
|
+
encode(_: Empty, writer?: _m0.Writer): _m0.Writer;
|
|
136
|
+
decode(input: Uint8Array | _m0.Reader, length?: number | undefined): Empty;
|
|
137
|
+
fromJSON(_: any): Empty;
|
|
138
|
+
toJSON(_: Empty): unknown;
|
|
139
|
+
create(base?: {} | undefined): Empty;
|
|
140
|
+
fromPartial(_: {}): Empty;
|
|
141
|
+
};
|
|
142
|
+
readonly responseStream: false;
|
|
143
|
+
readonly options: {};
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
export interface RoomApiServiceImplementation<CallContextExt = {}> {
|
|
148
|
+
/** Get the current value of the given variable */
|
|
149
|
+
readVariable(request: VariableRequest, context: CallContext & CallContextExt): Promise<DeepPartial<Value>>;
|
|
150
|
+
/** Listen to value updates for a given variable */
|
|
151
|
+
listenVariable(request: VariableRequest, context: CallContext & CallContextExt): ServerStreamingMethodResult<DeepPartial<Value>>;
|
|
152
|
+
/** Set the value of the given variable */
|
|
153
|
+
saveVariable(request: SaveVariableRequest, context: CallContext & CallContextExt): Promise<DeepPartial<Empty>>;
|
|
154
|
+
}
|
|
155
|
+
export interface RoomApiClient<CallOptionsExt = {}> {
|
|
156
|
+
/** Get the current value of the given variable */
|
|
157
|
+
readVariable(request: DeepPartial<VariableRequest>, options?: CallOptions & CallOptionsExt): Promise<Value>;
|
|
158
|
+
/** Listen to value updates for a given variable */
|
|
159
|
+
listenVariable(request: DeepPartial<VariableRequest>, options?: CallOptions & CallOptionsExt): AsyncIterable<Value>;
|
|
160
|
+
/** Set the value of the given variable */
|
|
161
|
+
saveVariable(request: DeepPartial<SaveVariableRequest>, options?: CallOptions & CallOptionsExt): Promise<Empty>;
|
|
162
|
+
}
|
|
163
|
+
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 {} ? {
|
|
165
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
166
|
+
} : Partial<T>;
|
|
167
|
+
export type ServerStreamingMethodResult<Response> = {
|
|
168
|
+
[Symbol.asyncIterator](): AsyncIterator<Response, void>;
|
|
169
|
+
};
|
|
170
|
+
export {};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.RoomApiDefinition = exports.SaveVariableRequest = exports.VariableRequest = exports.protobufPackage = void 0;
|
|
27
|
+
const _m0 = __importStar(require("protobufjs/minimal"));
|
|
28
|
+
const empty_1 = require("./google/protobuf/empty");
|
|
29
|
+
const struct_1 = require("./google/protobuf/struct");
|
|
30
|
+
exports.protobufPackage = "roomApi";
|
|
31
|
+
function createBaseVariableRequest() {
|
|
32
|
+
return { room: "", name: "" };
|
|
33
|
+
}
|
|
34
|
+
exports.VariableRequest = {
|
|
35
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
36
|
+
if (message.room !== "") {
|
|
37
|
+
writer.uint32(10).string(message.room);
|
|
38
|
+
}
|
|
39
|
+
if (message.name !== "") {
|
|
40
|
+
writer.uint32(18).string(message.name);
|
|
41
|
+
}
|
|
42
|
+
return writer;
|
|
43
|
+
},
|
|
44
|
+
decode(input, length) {
|
|
45
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
46
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
47
|
+
const message = createBaseVariableRequest();
|
|
48
|
+
while (reader.pos < end) {
|
|
49
|
+
const tag = reader.uint32();
|
|
50
|
+
switch (tag >>> 3) {
|
|
51
|
+
case 1:
|
|
52
|
+
if (tag != 10) {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
message.room = reader.string();
|
|
56
|
+
continue;
|
|
57
|
+
case 2:
|
|
58
|
+
if (tag != 18) {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
message.name = reader.string();
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
reader.skipType(tag & 7);
|
|
68
|
+
}
|
|
69
|
+
return message;
|
|
70
|
+
},
|
|
71
|
+
fromJSON(object) {
|
|
72
|
+
return { room: isSet(object.room) ? String(object.room) : "", name: isSet(object.name) ? String(object.name) : "" };
|
|
73
|
+
},
|
|
74
|
+
toJSON(message) {
|
|
75
|
+
const obj = {};
|
|
76
|
+
message.room !== undefined && (obj.room = message.room);
|
|
77
|
+
message.name !== undefined && (obj.name = message.name);
|
|
78
|
+
return obj;
|
|
79
|
+
},
|
|
80
|
+
create(base) {
|
|
81
|
+
return exports.VariableRequest.fromPartial(base ?? {});
|
|
82
|
+
},
|
|
83
|
+
fromPartial(object) {
|
|
84
|
+
const message = createBaseVariableRequest();
|
|
85
|
+
message.room = object.room ?? "";
|
|
86
|
+
message.name = object.name ?? "";
|
|
87
|
+
return message;
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
function createBaseSaveVariableRequest() {
|
|
91
|
+
return { room: "", name: "", value: undefined };
|
|
92
|
+
}
|
|
93
|
+
exports.SaveVariableRequest = {
|
|
94
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
95
|
+
if (message.room !== "") {
|
|
96
|
+
writer.uint32(10).string(message.room);
|
|
97
|
+
}
|
|
98
|
+
if (message.name !== "") {
|
|
99
|
+
writer.uint32(18).string(message.name);
|
|
100
|
+
}
|
|
101
|
+
if (message.value !== undefined) {
|
|
102
|
+
struct_1.Value.encode(struct_1.Value.wrap(message.value), writer.uint32(26).fork()).ldelim();
|
|
103
|
+
}
|
|
104
|
+
return writer;
|
|
105
|
+
},
|
|
106
|
+
decode(input, length) {
|
|
107
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
108
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
109
|
+
const message = createBaseSaveVariableRequest();
|
|
110
|
+
while (reader.pos < end) {
|
|
111
|
+
const tag = reader.uint32();
|
|
112
|
+
switch (tag >>> 3) {
|
|
113
|
+
case 1:
|
|
114
|
+
if (tag != 10) {
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
message.room = reader.string();
|
|
118
|
+
continue;
|
|
119
|
+
case 2:
|
|
120
|
+
if (tag != 18) {
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
message.name = reader.string();
|
|
124
|
+
continue;
|
|
125
|
+
case 3:
|
|
126
|
+
if (tag != 26) {
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
message.value = struct_1.Value.unwrap(struct_1.Value.decode(reader, reader.uint32()));
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if ((tag & 7) == 4 || tag == 0) {
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
reader.skipType(tag & 7);
|
|
136
|
+
}
|
|
137
|
+
return message;
|
|
138
|
+
},
|
|
139
|
+
fromJSON(object) {
|
|
140
|
+
return {
|
|
141
|
+
room: isSet(object.room) ? String(object.room) : "",
|
|
142
|
+
name: isSet(object.name) ? String(object.name) : "",
|
|
143
|
+
value: isSet(object?.value) ? object.value : undefined,
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
toJSON(message) {
|
|
147
|
+
const obj = {};
|
|
148
|
+
message.room !== undefined && (obj.room = message.room);
|
|
149
|
+
message.name !== undefined && (obj.name = message.name);
|
|
150
|
+
message.value !== undefined && (obj.value = message.value);
|
|
151
|
+
return obj;
|
|
152
|
+
},
|
|
153
|
+
create(base) {
|
|
154
|
+
return exports.SaveVariableRequest.fromPartial(base ?? {});
|
|
155
|
+
},
|
|
156
|
+
fromPartial(object) {
|
|
157
|
+
const message = createBaseSaveVariableRequest();
|
|
158
|
+
message.room = object.room ?? "";
|
|
159
|
+
message.name = object.name ?? "";
|
|
160
|
+
message.value = object.value ?? undefined;
|
|
161
|
+
return message;
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
exports.RoomApiDefinition = {
|
|
165
|
+
name: "RoomApi",
|
|
166
|
+
fullName: "roomApi.RoomApi",
|
|
167
|
+
methods: {
|
|
168
|
+
/** Get the current value of the given variable */
|
|
169
|
+
readVariable: {
|
|
170
|
+
name: "readVariable",
|
|
171
|
+
requestType: exports.VariableRequest,
|
|
172
|
+
requestStream: false,
|
|
173
|
+
responseType: struct_1.Value,
|
|
174
|
+
responseStream: false,
|
|
175
|
+
options: {},
|
|
176
|
+
},
|
|
177
|
+
/** Listen to value updates for a given variable */
|
|
178
|
+
listenVariable: {
|
|
179
|
+
name: "listenVariable",
|
|
180
|
+
requestType: exports.VariableRequest,
|
|
181
|
+
requestStream: false,
|
|
182
|
+
responseType: struct_1.Value,
|
|
183
|
+
responseStream: true,
|
|
184
|
+
options: {},
|
|
185
|
+
},
|
|
186
|
+
/** Set the value of the given variable */
|
|
187
|
+
saveVariable: {
|
|
188
|
+
name: "saveVariable",
|
|
189
|
+
requestType: exports.SaveVariableRequest,
|
|
190
|
+
requestStream: false,
|
|
191
|
+
responseType: empty_1.Empty,
|
|
192
|
+
responseStream: false,
|
|
193
|
+
options: {},
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
function isSet(value) {
|
|
198
|
+
return value !== null && value !== undefined;
|
|
199
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/example.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const struct_1 = require("./compiled_proto/google/protobuf/struct");
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
const apiKey = process.env.ROOM_API_SECRET_KEY;
|
|
6
|
+
if (!apiKey) {
|
|
7
|
+
throw new Error("No ROOM_API_SECRET_KEY defined on environment variables!");
|
|
8
|
+
}
|
|
9
|
+
const client = (0, index_1.createRoomApiClient)(apiKey, "room-api.workadventure.localhost", 80);
|
|
10
|
+
const roomUrl = "http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json";
|
|
11
|
+
const variableName = "textField";
|
|
12
|
+
async function init() {
|
|
13
|
+
// Save a variable
|
|
14
|
+
await client.saveVariable({
|
|
15
|
+
name: variableName,
|
|
16
|
+
room: roomUrl,
|
|
17
|
+
value: "Default Value",
|
|
18
|
+
});
|
|
19
|
+
console.log("Value saved: Default Value");
|
|
20
|
+
// Read a variable
|
|
21
|
+
const value = await client.readVariable({
|
|
22
|
+
name: variableName,
|
|
23
|
+
room: roomUrl,
|
|
24
|
+
});
|
|
25
|
+
console.log("Value read:", struct_1.Value.unwrap(value));
|
|
26
|
+
// Save a variable in 5sec
|
|
27
|
+
setTimeout(async () => {
|
|
28
|
+
await client.saveVariable({
|
|
29
|
+
name: variableName,
|
|
30
|
+
room: roomUrl,
|
|
31
|
+
value: "New Value",
|
|
32
|
+
});
|
|
33
|
+
console.log("Value saved: New Value");
|
|
34
|
+
}, 5000);
|
|
35
|
+
// Listen a variable
|
|
36
|
+
const listenVariable = client.listenVariable({
|
|
37
|
+
name: variableName,
|
|
38
|
+
room: roomUrl,
|
|
39
|
+
});
|
|
40
|
+
for await (const value of listenVariable) {
|
|
41
|
+
console.log("Value listened:", struct_1.Value.unwrap(value));
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
init();
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createRoomApiClient = void 0;
|
|
18
|
+
__exportStar(require("./compiled_proto/room-api"), exports);
|
|
19
|
+
const nice_grpc_1 = require("nice-grpc");
|
|
20
|
+
const room_api_1 = require("./compiled_proto/room-api");
|
|
21
|
+
const createRoomApiClient = (apiKey, host = "room-api.workadventu.re", port = 443) => {
|
|
22
|
+
const channel = (0, nice_grpc_1.createChannel)(`${host}:${port}`, port === 443 || host.startsWith("https://") ? nice_grpc_1.ChannelCredentials.createSsl() : nice_grpc_1.ChannelCredentials.createInsecure());
|
|
23
|
+
const client = (0, nice_grpc_1.createClient)(room_api_1.RoomApiDefinition, channel, {
|
|
24
|
+
"*": {
|
|
25
|
+
metadata: new nice_grpc_1.Metadata({ "X-API-Key": apiKey }),
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return client;
|
|
29
|
+
};
|
|
30
|
+
exports.createRoomApiClient = createRoomApiClient;
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@workadventure/room-api-client",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Workadventure Room Api Client",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"/dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
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
|
+
"build": "tsc --build",
|
|
13
|
+
"example": "ts-node ./src/example.ts",
|
|
14
|
+
"lint": "eslint --ext .js,.ts .",
|
|
15
|
+
"lint-fix": "eslint --fix --ext .js,.ts .",
|
|
16
|
+
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"",
|
|
17
|
+
"format-check": "prettier --ignore-path .gitignore \"**/*.+(js|ts|json)\"",
|
|
18
|
+
"precommit": "lint-staged"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/thecodingmachine/workadventure.git#master"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"workadventure",
|
|
26
|
+
"room",
|
|
27
|
+
"api",
|
|
28
|
+
"grpc"
|
|
29
|
+
],
|
|
30
|
+
"author": "WorkAdventure",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/thecodingmachine/workadventure/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/thecodingmachine/workadventure/tree/master/libs/room-api-clients/room-api-client-js#readme",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"long": "^5.2.1",
|
|
38
|
+
"nice-grpc": "^2.1.3",
|
|
39
|
+
"protobufjs": "^7.2.2"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^18.15.5",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^5.56.0",
|
|
44
|
+
"@typescript-eslint/parser": "^5.56.0",
|
|
45
|
+
"eslint": "^8.36.0",
|
|
46
|
+
"eslint-config-prettier": "^8.8.0",
|
|
47
|
+
"grpc-tools": "^1.12.4",
|
|
48
|
+
"lint-staged": "^13.2.0",
|
|
49
|
+
"prettier": "^2.8.6",
|
|
50
|
+
"ts-node": "^10.9.1",
|
|
51
|
+
"ts-proto": "^1.143.0",
|
|
52
|
+
"typescript": "^5.0.2"
|
|
53
|
+
},
|
|
54
|
+
"lint-staged": {
|
|
55
|
+
"*.{js,ts}": [
|
|
56
|
+
"eslint --fix"
|
|
57
|
+
],
|
|
58
|
+
"*.{js,ts,json}": [
|
|
59
|
+
"prettier --write"
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
}
|