hypha-rpc 0.20.16 → 0.20.18
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 +96 -30
- 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 +2 -0
- package/dist/hypha-rpc-websocket.min.mjs.map +1 -0
- package/dist/{hypha-rpc-websocket.esm.js → hypha-rpc-websocket.mjs} +97 -31
- package/dist/hypha-rpc-websocket.mjs.map +1 -0
- package/index.d.ts +2 -2
- package/package.json +2 -2
- package/src/rpc.js +35 -10
- package/src/webrtc-client.js +2 -1
- package/src/websocket-client.js +59 -19
- package/tests/websocket_client_test.js +6 -1
- package/webpack.config.js +20 -23
- package/dist/hypha-rpc-websocket.esm.js.map +0 -1
- package/dist/hypha-rpc-websocket.esm.min.js +0 -2
- package/dist/hypha-rpc-websocket.esm.min.js.map +0 -1
|
@@ -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;
|
|
@@ -732,7 +746,10 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
732
746
|
let manager;
|
|
733
747
|
if (check_type && api.type) {
|
|
734
748
|
try {
|
|
735
|
-
manager = await this.get_manager_service(
|
|
749
|
+
manager = await this.get_manager_service({
|
|
750
|
+
timeout: 10,
|
|
751
|
+
case_conversion: "camel",
|
|
752
|
+
});
|
|
736
753
|
const type_info = await manager.get_service_type(api.type);
|
|
737
754
|
api = _annotate_service(api, type_info);
|
|
738
755
|
} catch (e) {
|
|
@@ -744,7 +761,12 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
744
761
|
const serviceInfo = this._extract_service_info(service);
|
|
745
762
|
if (notify) {
|
|
746
763
|
try {
|
|
747
|
-
manager =
|
|
764
|
+
manager =
|
|
765
|
+
manager ||
|
|
766
|
+
(await this.get_manager_service({
|
|
767
|
+
timeout: 10,
|
|
768
|
+
case_conversion: "camel",
|
|
769
|
+
}));
|
|
748
770
|
await manager.registerService(serviceInfo);
|
|
749
771
|
} catch (e) {
|
|
750
772
|
throw new Error(`Failed to notify workspace manager: ${e}`);
|
|
@@ -763,7 +785,10 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
763
785
|
const api = this._services[service];
|
|
764
786
|
delete this._services[service];
|
|
765
787
|
if (notify) {
|
|
766
|
-
const manager = await this.get_manager_service(
|
|
788
|
+
const manager = await this.get_manager_service({
|
|
789
|
+
timeout: 10,
|
|
790
|
+
case_conversion: "camel",
|
|
791
|
+
});
|
|
767
792
|
await manager.registerService(api.id);
|
|
768
793
|
}
|
|
769
794
|
}
|
|
@@ -2379,7 +2404,7 @@ async function getRTCService(server, service_id, config) {
|
|
|
2379
2404
|
setTimeout(async () => {
|
|
2380
2405
|
const rpc = await _setupRPC(config);
|
|
2381
2406
|
pc.rpc = rpc;
|
|
2382
|
-
async function get_service(name) {
|
|
2407
|
+
async function get_service(name, ...args) {
|
|
2383
2408
|
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.assert)(
|
|
2384
2409
|
!name.includes(":"),
|
|
2385
2410
|
"WebRTC service name should not contain ':'",
|
|
@@ -2390,6 +2415,7 @@ async function getRTCService(server, service_id, config) {
|
|
|
2390
2415
|
);
|
|
2391
2416
|
return await rpc.get_remote_service(
|
|
2392
2417
|
config.workspace + "/" + config.peer_id + ":" + name,
|
|
2418
|
+
...args,
|
|
2393
2419
|
);
|
|
2394
2420
|
}
|
|
2395
2421
|
async function disconnect() {
|
|
@@ -4772,26 +4798,25 @@ async function login(config) {
|
|
|
4772
4798
|
}
|
|
4773
4799
|
}
|
|
4774
4800
|
|
|
4775
|
-
async function webrtcGetService(
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
)
|
|
4801
|
+
async function webrtcGetService(wm, rtc_service_id, query, config) {
|
|
4802
|
+
config = config || {};
|
|
4803
|
+
config.case_conversion = config.case_conversion || "camel";
|
|
4804
|
+
const webrtc = config.webrtc;
|
|
4805
|
+
const webrtc_config = config.webrtc_config;
|
|
4806
|
+
if (config.webrtc !== undefined) delete config.webrtc;
|
|
4807
|
+
if (config.webrtc_config !== undefined) delete config.webrtc_config;
|
|
4782
4808
|
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.assert)(
|
|
4783
4809
|
[undefined, true, false, "auto"].includes(webrtc),
|
|
4784
4810
|
"webrtc must be true, false or 'auto'",
|
|
4785
4811
|
);
|
|
4786
|
-
|
|
4787
|
-
const
|
|
4788
|
-
const svc = await wm.getService(query, ...otherArgs);
|
|
4812
|
+
|
|
4813
|
+
const svc = await wm.getService(query, config);
|
|
4789
4814
|
if (webrtc === true || webrtc === "auto") {
|
|
4790
4815
|
if (svc.id.includes(":") && svc.id.includes("/")) {
|
|
4791
4816
|
try {
|
|
4792
4817
|
// Assuming that the client registered a webrtc service with the client_id + "-rtc"
|
|
4793
4818
|
const peer = await (0,_webrtc_client_js__WEBPACK_IMPORTED_MODULE_3__.getRTCService)(wm, rtc_service_id, webrtc_config);
|
|
4794
|
-
const rtcSvc = await peer.get_service(svc.id.split(":")[1]);
|
|
4819
|
+
const rtcSvc = await peer.get_service(svc.id.split(":")[1], config);
|
|
4795
4820
|
rtcSvc._webrtc = true;
|
|
4796
4821
|
rtcSvc._peer = peer;
|
|
4797
4822
|
rtcSvc._service = svc;
|
|
@@ -4852,7 +4877,10 @@ async function connectToServer(config) {
|
|
|
4852
4877
|
method_timeout: config.method_timeout,
|
|
4853
4878
|
app_id: config.app_id,
|
|
4854
4879
|
});
|
|
4855
|
-
const wm = await rpc.get_manager_service(
|
|
4880
|
+
const wm = await rpc.get_manager_service({
|
|
4881
|
+
timeout: config.method_timeout,
|
|
4882
|
+
case_conversion: "camel",
|
|
4883
|
+
});
|
|
4856
4884
|
wm.rpc = rpc;
|
|
4857
4885
|
|
|
4858
4886
|
async function _export(api) {
|
|
@@ -5037,13 +5065,52 @@ async function connectToServer(config) {
|
|
|
5037
5065
|
description: "The query to get the service",
|
|
5038
5066
|
type: "object",
|
|
5039
5067
|
},
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
type:
|
|
5068
|
+
config: {
|
|
5069
|
+
description:
|
|
5070
|
+
"The config for the service, including `webrtc`, `webrtc_config` and other get_service options",
|
|
5071
|
+
type: "object",
|
|
5044
5072
|
},
|
|
5045
|
-
|
|
5046
|
-
|
|
5073
|
+
},
|
|
5074
|
+
required: ["query"],
|
|
5075
|
+
type: "object",
|
|
5076
|
+
},
|
|
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",
|
|
5088
|
+
},
|
|
5089
|
+
},
|
|
5090
|
+
required: ["config"],
|
|
5091
|
+
type: "object",
|
|
5092
|
+
},
|
|
5093
|
+
});
|
|
5094
|
+
} else {
|
|
5095
|
+
const _getService = wm.getService;
|
|
5096
|
+
wm.getService = (0,_utils_schema_js__WEBPACK_IMPORTED_MODULE_2__.schemaFunction)(
|
|
5097
|
+
(query, config) => {
|
|
5098
|
+
config = config || {};
|
|
5099
|
+
config.case_conversion = config.case_conversion || "camel";
|
|
5100
|
+
return _getService(query, config);
|
|
5101
|
+
},
|
|
5102
|
+
{
|
|
5103
|
+
name: "getService",
|
|
5104
|
+
description: "Get a service.",
|
|
5105
|
+
parameters: {
|
|
5106
|
+
properties: {
|
|
5107
|
+
query: {
|
|
5108
|
+
description: "The query to get the service",
|
|
5109
|
+
type: "object",
|
|
5110
|
+
},
|
|
5111
|
+
config: {
|
|
5112
|
+
description:
|
|
5113
|
+
"The config for the service, including `webrtc`, `webrtc_config` and other get_service options",
|
|
5047
5114
|
type: "object",
|
|
5048
5115
|
},
|
|
5049
5116
|
},
|
|
@@ -5053,7 +5120,6 @@ async function connectToServer(config) {
|
|
|
5053
5120
|
},
|
|
5054
5121
|
);
|
|
5055
5122
|
}
|
|
5056
|
-
|
|
5057
5123
|
return wm;
|
|
5058
5124
|
}
|
|
5059
5125
|
|