hypha-rpc 0.20.17 → 0.20.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hypha-rpc-websocket.js +95 -49
- package/dist/hypha-rpc-websocket.js.map +1 -1
- package/dist/hypha-rpc-websocket.min.js +1 -1
- package/dist/hypha-rpc-websocket.min.js.map +1 -1
- package/dist/hypha-rpc-websocket.min.mjs +1 -1
- package/dist/hypha-rpc-websocket.min.mjs.map +1 -1
- package/dist/hypha-rpc-websocket.mjs +95 -49
- package/dist/hypha-rpc-websocket.mjs.map +1 -1
- package/index.d.ts +3 -4
- package/package.json +2 -2
- package/src/rpc.js +38 -11
- package/src/webrtc-client.js +13 -3
- package/src/websocket-client.js +44 -35
- package/tests/websocket_client_test.js +6 -2
- package/webpack.config.js +20 -23
|
@@ -271,6 +271,8 @@ class Timer {
|
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
+
class RemoteService extends Object {}
|
|
275
|
+
|
|
274
276
|
/**
|
|
275
277
|
* RPC object represents a single site in the
|
|
276
278
|
* communication protocol between the application and the plugin
|
|
@@ -345,7 +347,10 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
345
347
|
const onConnected = async (connectionInfo) => {
|
|
346
348
|
if (!this._silent && this._connection.manager_id) {
|
|
347
349
|
console.log("Connection established, reporting services...");
|
|
348
|
-
const manager = await this.get_manager_service(
|
|
350
|
+
const manager = await this.get_manager_service({
|
|
351
|
+
timeout: 10,
|
|
352
|
+
case_conversion: "camel",
|
|
353
|
+
});
|
|
349
354
|
for (let service of Object.values(this._services)) {
|
|
350
355
|
const serviceInfo = this._extract_service_info(service);
|
|
351
356
|
await manager.registerService(serviceInfo);
|
|
@@ -510,12 +515,16 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
510
515
|
await this._connection.disconnect();
|
|
511
516
|
}
|
|
512
517
|
|
|
513
|
-
async get_manager_service(
|
|
518
|
+
async get_manager_service(config) {
|
|
519
|
+
config = config || {};
|
|
520
|
+
let { timeout, case_conversion } = config;
|
|
514
521
|
(0,_utils__WEBPACK_IMPORTED_MODULE_0__.assert)(this._connection.manager_id, "Manager id is not set");
|
|
515
522
|
const svc = await this.get_remote_service(
|
|
516
523
|
`*/${this._connection.manager_id}:default`,
|
|
517
|
-
|
|
518
|
-
|
|
524
|
+
{
|
|
525
|
+
timeout: timeout,
|
|
526
|
+
case_conversion: case_conversion,
|
|
527
|
+
},
|
|
519
528
|
);
|
|
520
529
|
return svc;
|
|
521
530
|
}
|
|
@@ -551,7 +560,8 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
551
560
|
`Permission denied for getting protected service: ${service_id}, workspace mismatch: ${ws} != ${context["ws"]}`,
|
|
552
561
|
);
|
|
553
562
|
}
|
|
554
|
-
async get_remote_service(service_uri,
|
|
563
|
+
async get_remote_service(service_uri, config) {
|
|
564
|
+
let { timeout, case_conversion } = config || {};
|
|
555
565
|
timeout = timeout === undefined ? this._method_timeout : timeout;
|
|
556
566
|
if (!service_uri && this._connection.manager_id) {
|
|
557
567
|
service_uri = "*/" + this._connection.manager_id;
|
|
@@ -584,8 +594,12 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
584
594
|
"Timeout Error: Failed to get remote service: " + service_uri,
|
|
585
595
|
);
|
|
586
596
|
svc.id = `${provider}:${service_id}`;
|
|
587
|
-
if (case_conversion)
|
|
588
|
-
|
|
597
|
+
if (case_conversion)
|
|
598
|
+
return Object.assign(
|
|
599
|
+
new RemoteService(),
|
|
600
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_0__.convertCase)(svc, case_conversion),
|
|
601
|
+
);
|
|
602
|
+
else return Object.assign(new RemoteService(), svc);
|
|
589
603
|
} catch (e) {
|
|
590
604
|
console.warn("Failed to get remote service: " + service_uri, e);
|
|
591
605
|
throw e;
|
|
@@ -728,11 +742,16 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
728
742
|
return _get_schema(service, null, skipContext);
|
|
729
743
|
}
|
|
730
744
|
|
|
731
|
-
async register_service(api,
|
|
745
|
+
async register_service(api, config) {
|
|
746
|
+
let { check_type, notify, overwrite } = config || {};
|
|
747
|
+
notify = notify === undefined ? true : notify;
|
|
732
748
|
let manager;
|
|
733
749
|
if (check_type && api.type) {
|
|
734
750
|
try {
|
|
735
|
-
manager = await this.get_manager_service(
|
|
751
|
+
manager = await this.get_manager_service({
|
|
752
|
+
timeout: 10,
|
|
753
|
+
case_conversion: "camel",
|
|
754
|
+
});
|
|
736
755
|
const type_info = await manager.get_service_type(api.type);
|
|
737
756
|
api = _annotate_service(api, type_info);
|
|
738
757
|
} catch (e) {
|
|
@@ -744,7 +763,12 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
744
763
|
const serviceInfo = this._extract_service_info(service);
|
|
745
764
|
if (notify) {
|
|
746
765
|
try {
|
|
747
|
-
manager =
|
|
766
|
+
manager =
|
|
767
|
+
manager ||
|
|
768
|
+
(await this.get_manager_service({
|
|
769
|
+
timeout: 10,
|
|
770
|
+
case_conversion: "camel",
|
|
771
|
+
}));
|
|
748
772
|
await manager.registerService(serviceInfo);
|
|
749
773
|
} catch (e) {
|
|
750
774
|
throw new Error(`Failed to notify workspace manager: ${e}`);
|
|
@@ -763,7 +787,10 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
763
787
|
const api = this._services[service];
|
|
764
788
|
delete this._services[service];
|
|
765
789
|
if (notify) {
|
|
766
|
-
const manager = await this.get_manager_service(
|
|
790
|
+
const manager = await this.get_manager_service({
|
|
791
|
+
timeout: 10,
|
|
792
|
+
case_conversion: "camel",
|
|
793
|
+
});
|
|
767
794
|
await manager.registerService(api.id);
|
|
768
795
|
}
|
|
769
796
|
}
|
|
@@ -2379,7 +2406,7 @@ async function getRTCService(server, service_id, config) {
|
|
|
2379
2406
|
setTimeout(async () => {
|
|
2380
2407
|
const rpc = await _setupRPC(config);
|
|
2381
2408
|
pc.rpc = rpc;
|
|
2382
|
-
async function get_service(name) {
|
|
2409
|
+
async function get_service(name, ...args) {
|
|
2383
2410
|
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.assert)(
|
|
2384
2411
|
!name.includes(":"),
|
|
2385
2412
|
"WebRTC service name should not contain ':'",
|
|
@@ -2390,6 +2417,7 @@ async function getRTCService(server, service_id, config) {
|
|
|
2390
2417
|
);
|
|
2391
2418
|
return await rpc.get_remote_service(
|
|
2392
2419
|
config.workspace + "/" + config.peer_id + ":" + name,
|
|
2420
|
+
...args,
|
|
2393
2421
|
);
|
|
2394
2422
|
}
|
|
2395
2423
|
async function disconnect() {
|
|
@@ -2397,13 +2425,22 @@ async function getRTCService(server, service_id, config) {
|
|
|
2397
2425
|
pc.close();
|
|
2398
2426
|
}
|
|
2399
2427
|
pc.getService = (0,_utils_schema_js__WEBPACK_IMPORTED_MODULE_2__.schemaFunction)(get_service, {
|
|
2400
|
-
name: "
|
|
2428
|
+
name: "getService",
|
|
2401
2429
|
description: "Get a remote service via webrtc",
|
|
2402
2430
|
parameters: {
|
|
2403
2431
|
type: "object",
|
|
2404
2432
|
properties: {
|
|
2405
|
-
|
|
2433
|
+
service_id: {
|
|
2434
|
+
type: "string",
|
|
2435
|
+
description:
|
|
2436
|
+
"Service ID. This should be a service id in the format: 'workspace/service_id', 'workspace/client_id:service_id' or 'workspace/client_id:service_id@app_id'",
|
|
2437
|
+
},
|
|
2438
|
+
config: {
|
|
2439
|
+
type: "object",
|
|
2440
|
+
description: "Options for the service",
|
|
2441
|
+
},
|
|
2406
2442
|
},
|
|
2443
|
+
required: ["id"],
|
|
2407
2444
|
},
|
|
2408
2445
|
});
|
|
2409
2446
|
pc.disconnect = (0,_utils_schema_js__WEBPACK_IMPORTED_MODULE_2__.schemaFunction)(disconnect, {
|
|
@@ -4772,26 +4809,25 @@ async function login(config) {
|
|
|
4772
4809
|
}
|
|
4773
4810
|
}
|
|
4774
4811
|
|
|
4775
|
-
async function webrtcGetService(
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
)
|
|
4812
|
+
async function webrtcGetService(wm, rtc_service_id, query, config) {
|
|
4813
|
+
config = config || {};
|
|
4814
|
+
config.case_conversion = config.case_conversion || "camel";
|
|
4815
|
+
const webrtc = config.webrtc;
|
|
4816
|
+
const webrtc_config = config.webrtc_config;
|
|
4817
|
+
if (config.webrtc !== undefined) delete config.webrtc;
|
|
4818
|
+
if (config.webrtc_config !== undefined) delete config.webrtc_config;
|
|
4782
4819
|
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.assert)(
|
|
4783
4820
|
[undefined, true, false, "auto"].includes(webrtc),
|
|
4784
4821
|
"webrtc must be true, false or 'auto'",
|
|
4785
4822
|
);
|
|
4786
|
-
|
|
4787
|
-
const
|
|
4788
|
-
const svc = await wm.getService(query, ...otherArgs);
|
|
4823
|
+
|
|
4824
|
+
const svc = await wm.getService(query, config);
|
|
4789
4825
|
if (webrtc === true || webrtc === "auto") {
|
|
4790
4826
|
if (svc.id.includes(":") && svc.id.includes("/")) {
|
|
4791
4827
|
try {
|
|
4792
4828
|
// Assuming that the client registered a webrtc service with the client_id + "-rtc"
|
|
4793
4829
|
const peer = await (0,_webrtc_client_js__WEBPACK_IMPORTED_MODULE_3__.getRTCService)(wm, rtc_service_id, webrtc_config);
|
|
4794
|
-
const rtcSvc = await peer.
|
|
4830
|
+
const rtcSvc = await peer.getService(svc.id.split(":")[1], config);
|
|
4795
4831
|
rtcSvc._webrtc = true;
|
|
4796
4832
|
rtcSvc._peer = peer;
|
|
4797
4833
|
rtcSvc._service = svc;
|
|
@@ -4852,14 +4888,17 @@ async function connectToServer(config) {
|
|
|
4852
4888
|
method_timeout: config.method_timeout,
|
|
4853
4889
|
app_id: config.app_id,
|
|
4854
4890
|
});
|
|
4855
|
-
const wm = await rpc.get_manager_service(
|
|
4891
|
+
const wm = await rpc.get_manager_service({
|
|
4892
|
+
timeout: config.method_timeout,
|
|
4893
|
+
case_conversion: "camel",
|
|
4894
|
+
});
|
|
4856
4895
|
wm.rpc = rpc;
|
|
4857
4896
|
|
|
4858
4897
|
async function _export(api) {
|
|
4859
4898
|
api.id = "default";
|
|
4860
4899
|
api.name = api.name || config.name || api.id;
|
|
4861
4900
|
api.description = api.description || config.description;
|
|
4862
|
-
await rpc.register_service(api, true);
|
|
4901
|
+
await rpc.register_service(api, { overwrite: true });
|
|
4863
4902
|
}
|
|
4864
4903
|
|
|
4865
4904
|
async function getApp(clientId) {
|
|
@@ -5023,37 +5062,44 @@ async function connectToServer(config) {
|
|
|
5023
5062
|
});
|
|
5024
5063
|
}
|
|
5025
5064
|
if (config.webrtc) {
|
|
5026
|
-
await (0,_webrtc_client_js__WEBPACK_IMPORTED_MODULE_3__.registerRTCService)(wm, clientId
|
|
5065
|
+
await (0,_webrtc_client_js__WEBPACK_IMPORTED_MODULE_3__.registerRTCService)(wm, `${clientId}-rtc`, config.webrtc_config);
|
|
5027
5066
|
// make a copy of wm, so webrtc can use the original wm.getService
|
|
5028
5067
|
const _wm = Object.assign({}, wm);
|
|
5068
|
+
const description = _wm.getService.__schema__.description;
|
|
5069
|
+
// TODO: Fix the schema for adding options for webrtc
|
|
5070
|
+
const parameters = _wm.getService.__schema__.parameters;
|
|
5029
5071
|
wm.getService = (0,_utils_schema_js__WEBPACK_IMPORTED_MODULE_2__.schemaFunction)(
|
|
5030
|
-
webrtcGetService.bind(null, _wm, clientId
|
|
5072
|
+
webrtcGetService.bind(null, _wm, `${workspace}/${clientId}-rtc`),
|
|
5031
5073
|
{
|
|
5032
5074
|
name: "getService",
|
|
5033
|
-
description
|
|
5034
|
-
parameters
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
description: "The webrtc configuration",
|
|
5047
|
-
type: "object",
|
|
5048
|
-
},
|
|
5075
|
+
description,
|
|
5076
|
+
parameters,
|
|
5077
|
+
},
|
|
5078
|
+
);
|
|
5079
|
+
|
|
5080
|
+
wm.getRTCService = (0,_utils_schema_js__WEBPACK_IMPORTED_MODULE_2__.schemaFunction)(_webrtc_client_js__WEBPACK_IMPORTED_MODULE_3__.getRTCService.bind(null, wm), {
|
|
5081
|
+
name: "getRTCService",
|
|
5082
|
+
description: "Get the webrtc connection, returns a peer connection.",
|
|
5083
|
+
parameters: {
|
|
5084
|
+
properties: {
|
|
5085
|
+
config: {
|
|
5086
|
+
description: "The config for the webrtc service",
|
|
5087
|
+
type: "object",
|
|
5049
5088
|
},
|
|
5050
|
-
required: ["query"],
|
|
5051
|
-
type: "object",
|
|
5052
5089
|
},
|
|
5090
|
+
required: ["config"],
|
|
5091
|
+
type: "object",
|
|
5053
5092
|
},
|
|
5054
|
-
);
|
|
5093
|
+
});
|
|
5094
|
+
} else {
|
|
5095
|
+
const _getService = wm.getService;
|
|
5096
|
+
wm.getService = (query, config) => {
|
|
5097
|
+
config = config || {};
|
|
5098
|
+
config.case_conversion = config.case_conversion || "camel";
|
|
5099
|
+
return _getService(query, config);
|
|
5100
|
+
};
|
|
5101
|
+
wm.getService.__schema__ = _getService.__schema__;
|
|
5055
5102
|
}
|
|
5056
|
-
|
|
5057
5103
|
return wm;
|
|
5058
5104
|
}
|
|
5059
5105
|
|