hypha-rpc 0.20.59 → 0.20.61
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 +152 -111
- 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 +152 -111
- package/dist/hypha-rpc-websocket.mjs.map +1 -1
- package/package.json +1 -1
- package/src/rpc.js +80 -39
- package/src/utils/schema.js +1 -1
- package/src/webrtc-client.js +1 -1
- package/src/websocket-client.js +1 -1
- package/tests/websocket_client_test.js +212 -0
|
@@ -23,8 +23,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
23
23
|
/* harmony export */ API_VERSION: () => (/* binding */ API_VERSION),
|
|
24
24
|
/* harmony export */ RPC: () => (/* binding */ RPC)
|
|
25
25
|
/* harmony export */ });
|
|
26
|
-
/* harmony import */ var
|
|
27
|
-
/* harmony import */ var
|
|
26
|
+
/* harmony import */ var _utils_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils/index.js */ "./src/utils/index.js");
|
|
27
|
+
/* harmony import */ var _utils_schema_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils/schema.js */ "./src/utils/schema.js");
|
|
28
28
|
/* harmony import */ var _msgpack_msgpack__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @msgpack/msgpack */ "./node_modules/@msgpack/msgpack/dist.es5+esm/decode.mjs");
|
|
29
29
|
/* harmony import */ var _msgpack_msgpack__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @msgpack/msgpack */ "./node_modules/@msgpack/msgpack/dist.es5+esm/encode.mjs");
|
|
30
30
|
/**
|
|
@@ -123,7 +123,7 @@ function _annotate_service(service, serviceTypeInfo) {
|
|
|
123
123
|
annotateRecursive(v, schemaInfo[k], newPath);
|
|
124
124
|
} else if (typeof v === "function") {
|
|
125
125
|
if (schemaInfo.hasOwnProperty(k)) {
|
|
126
|
-
newService[k] = (0,
|
|
126
|
+
newService[k] = (0,_utils_schema_js__WEBPACK_IMPORTED_MODULE_1__.schemaFunction)(v, {
|
|
127
127
|
name: schemaInfo[k]["name"],
|
|
128
128
|
description: schemaInfo[k].description || "",
|
|
129
129
|
parameters: schemaInfo[k]["parameters"],
|
|
@@ -145,7 +145,7 @@ function _annotate_service(service, serviceTypeInfo) {
|
|
|
145
145
|
annotateRecursive(v, schemaInfo[i], newPath);
|
|
146
146
|
} else if (typeof v === "function") {
|
|
147
147
|
if (schemaInfo.hasOwnProperty(i)) {
|
|
148
|
-
newService[i] = (0,
|
|
148
|
+
newService[i] = (0,_utils_schema_js__WEBPACK_IMPORTED_MODULE_1__.schemaFunction)(v, {
|
|
149
149
|
name: schemaInfo[i]["name"],
|
|
150
150
|
description: schemaInfo[i].description || "",
|
|
151
151
|
parameters: schemaInfo[i]["parameters"],
|
|
@@ -280,7 +280,7 @@ class RemoteService extends Object {}
|
|
|
280
280
|
* and receive messages from the opposite site (basically it
|
|
281
281
|
* should only provide send() and onMessage() methods)
|
|
282
282
|
*/
|
|
283
|
-
class RPC extends
|
|
283
|
+
class RPC extends _utils_index_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
284
284
|
constructor(
|
|
285
285
|
connection,
|
|
286
286
|
{
|
|
@@ -300,8 +300,8 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
300
300
|
) {
|
|
301
301
|
super(debug);
|
|
302
302
|
this._codecs = codecs || {};
|
|
303
|
-
(0,
|
|
304
|
-
(0,
|
|
303
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(client_id && typeof client_id === "string");
|
|
304
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(client_id, "client_id is required");
|
|
305
305
|
this._client_id = client_id;
|
|
306
306
|
this._name = name;
|
|
307
307
|
this._app_id = app_id || "*";
|
|
@@ -344,8 +344,8 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
344
344
|
this.on("method", this._handle_method.bind(this));
|
|
345
345
|
this.on("error", console.error);
|
|
346
346
|
|
|
347
|
-
(0,
|
|
348
|
-
(0,
|
|
347
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(connection.emit_message && connection.on_message);
|
|
348
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
349
349
|
connection.manager_id !== undefined,
|
|
350
350
|
"Connection must have manager_id",
|
|
351
351
|
);
|
|
@@ -428,7 +428,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
428
428
|
}
|
|
429
429
|
|
|
430
430
|
async _ping(msg, context) {
|
|
431
|
-
(0,
|
|
431
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(msg == "ping");
|
|
432
432
|
return "pong";
|
|
433
433
|
}
|
|
434
434
|
|
|
@@ -440,7 +440,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
440
440
|
_rpromise: true,
|
|
441
441
|
_rdoc: "Ping a remote client",
|
|
442
442
|
});
|
|
443
|
-
(0,
|
|
443
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)((await method("ping", timeout)) == "pong");
|
|
444
444
|
}
|
|
445
445
|
|
|
446
446
|
_create_message(key, heartbeat, overwrite, context) {
|
|
@@ -473,7 +473,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
473
473
|
if (!cache[key]) {
|
|
474
474
|
throw new Error(`Message with key ${key} does not exists.`);
|
|
475
475
|
}
|
|
476
|
-
(0,
|
|
476
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(data instanceof ArrayBufferView);
|
|
477
477
|
cache[key].push(data);
|
|
478
478
|
}
|
|
479
479
|
|
|
@@ -488,7 +488,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
488
488
|
if (!cache[key]) {
|
|
489
489
|
throw new Error(`Message with key ${key} does not exists.`);
|
|
490
490
|
}
|
|
491
|
-
(0,
|
|
491
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(data instanceof ArrayBufferView);
|
|
492
492
|
cache[key][index] = data;
|
|
493
493
|
}
|
|
494
494
|
|
|
@@ -508,7 +508,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
508
508
|
this._object_store[key]["timer"].reset();
|
|
509
509
|
}
|
|
510
510
|
const cache = this._object_store["message_cache"];
|
|
511
|
-
(0,
|
|
511
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(!!context, "Context is required");
|
|
512
512
|
if (!cache[key]) {
|
|
513
513
|
throw new Error(`Message with key ${key} does not exists.`);
|
|
514
514
|
}
|
|
@@ -566,8 +566,24 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
566
566
|
this._services = {};
|
|
567
567
|
}
|
|
568
568
|
|
|
569
|
-
|
|
569
|
+
close() {
|
|
570
|
+
// Clear all heartbeat intervals
|
|
571
|
+
for (const session_id in this._object_store) {
|
|
572
|
+
if (this._object_store.hasOwnProperty(session_id)) {
|
|
573
|
+
const session = this._object_store[session_id];
|
|
574
|
+
if (session && session.heartbeat_task) {
|
|
575
|
+
clearInterval(session.heartbeat_task);
|
|
576
|
+
}
|
|
577
|
+
if (session && session.timer) {
|
|
578
|
+
session.timer.clear();
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
570
582
|
this._fire("disconnected");
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
async disconnect() {
|
|
586
|
+
this.close();
|
|
571
587
|
await this._connection.disconnect();
|
|
572
588
|
}
|
|
573
589
|
|
|
@@ -614,9 +630,9 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
614
630
|
return this._services;
|
|
615
631
|
}
|
|
616
632
|
get_local_service(service_id, context) {
|
|
617
|
-
(0,
|
|
633
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(service_id);
|
|
618
634
|
const [ws, client_id] = context["to"].split("/");
|
|
619
|
-
(0,
|
|
635
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
620
636
|
client_id === this._client_id,
|
|
621
637
|
"Services can only be accessed locally",
|
|
622
638
|
);
|
|
@@ -655,12 +671,12 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
655
671
|
service_id = service_id.split("@")[0];
|
|
656
672
|
const app_id = service_uri.split("@")[1];
|
|
657
673
|
if (this._app_id && this._app_id !== "*")
|
|
658
|
-
(0,
|
|
674
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
659
675
|
app_id === this._app_id,
|
|
660
676
|
`Invalid app id: ${app_id} != ${this._app_id}`,
|
|
661
677
|
);
|
|
662
678
|
}
|
|
663
|
-
(0,
|
|
679
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(provider, `Invalid service uri: ${service_uri}`);
|
|
664
680
|
|
|
665
681
|
try {
|
|
666
682
|
const method = this._generate_remote_method({
|
|
@@ -670,19 +686,19 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
670
686
|
_rpromise: true,
|
|
671
687
|
_rdoc: "Get a remote service",
|
|
672
688
|
});
|
|
673
|
-
let svc = await (0,
|
|
689
|
+
let svc = await (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.waitFor)(
|
|
674
690
|
method(service_id),
|
|
675
691
|
timeout,
|
|
676
692
|
"Timeout Error: Failed to get remote service: " + service_uri,
|
|
677
693
|
);
|
|
678
694
|
svc.id = `${provider}:${service_id}`;
|
|
679
695
|
if (kwargs_expansion) {
|
|
680
|
-
svc = (0,
|
|
696
|
+
svc = (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.expandKwargs)(svc);
|
|
681
697
|
}
|
|
682
698
|
if (case_conversion)
|
|
683
699
|
return Object.assign(
|
|
684
700
|
new RemoteService(),
|
|
685
|
-
(0,
|
|
701
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.convertCase)(svc, case_conversion),
|
|
686
702
|
);
|
|
687
703
|
else return Object.assign(new RemoteService(), svc);
|
|
688
704
|
} catch (e) {
|
|
@@ -761,7 +777,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
761
777
|
api.id = api.id || "default";
|
|
762
778
|
api = normApi;
|
|
763
779
|
}
|
|
764
|
-
(0,
|
|
780
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
765
781
|
api.id && typeof api.id === "string",
|
|
766
782
|
`Service id not found: ${api}`,
|
|
767
783
|
);
|
|
@@ -781,7 +797,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
781
797
|
require_context = api.config.require_context;
|
|
782
798
|
if (api.config.run_in_executor) run_in_executor = true;
|
|
783
799
|
const visibility = api.config.visibility || "protected";
|
|
784
|
-
(0,
|
|
800
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(["protected", "public"].includes(visibility));
|
|
785
801
|
this._annotate_service_methods(
|
|
786
802
|
api,
|
|
787
803
|
api["id"],
|
|
@@ -870,7 +886,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
870
886
|
} else {
|
|
871
887
|
service_id = service.id;
|
|
872
888
|
}
|
|
873
|
-
(0,
|
|
889
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
874
890
|
service_id && typeof service_id === "string",
|
|
875
891
|
`Invalid service id: ${service_id}`,
|
|
876
892
|
);
|
|
@@ -894,7 +910,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
894
910
|
}
|
|
895
911
|
|
|
896
912
|
_ndarray(typedArray, shape, dtype) {
|
|
897
|
-
const _dtype = (0,
|
|
913
|
+
const _dtype = (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.typedArrayToDtype)(typedArray);
|
|
898
914
|
if (dtype && dtype !== _dtype) {
|
|
899
915
|
throw (
|
|
900
916
|
"dtype doesn't match the type of the array: " + _dtype + " != " + dtype
|
|
@@ -937,12 +953,20 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
937
953
|
`Error in callback(${method_id}, ${description}): ${error}`,
|
|
938
954
|
);
|
|
939
955
|
} finally {
|
|
956
|
+
// Clear the timer first if it exists
|
|
940
957
|
if (timer && timer.started) {
|
|
941
958
|
timer.clear();
|
|
942
959
|
}
|
|
960
|
+
|
|
961
|
+
// Clean up the entire session when resolve/reject is called
|
|
943
962
|
if (clear_after_called && self._object_store[session_id]) {
|
|
944
|
-
//
|
|
945
|
-
|
|
963
|
+
// For promise callbacks (resolve/reject), clean up the entire session
|
|
964
|
+
if (name === "resolve" || name === "reject") {
|
|
965
|
+
delete self._object_store[session_id];
|
|
966
|
+
} else {
|
|
967
|
+
// For other callbacks, just clean up this specific callback
|
|
968
|
+
self._cleanup_session_if_needed(session_id, name);
|
|
969
|
+
}
|
|
946
970
|
}
|
|
947
971
|
}
|
|
948
972
|
};
|
|
@@ -952,31 +976,22 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
952
976
|
|
|
953
977
|
// Clean session management - all logic in one place
|
|
954
978
|
_cleanup_session_if_needed(session_id, callback_name) {
|
|
955
|
-
|
|
956
|
-
if (
|
|
957
|
-
|
|
958
|
-
// Promise sessions: let the promise manager decide cleanup
|
|
959
|
-
if (store._promise_manager) {
|
|
960
|
-
if (store._promise_manager.should_cleanup_on_callback(callback_name)) {
|
|
961
|
-
store._promise_manager.settle();
|
|
962
|
-
delete this._object_store[session_id];
|
|
963
|
-
}
|
|
964
|
-
return;
|
|
979
|
+
// Python-style immediate cleanup - no complex logic needed
|
|
980
|
+
if (this._object_store[session_id]) {
|
|
981
|
+
delete this._object_store[session_id];
|
|
965
982
|
}
|
|
966
|
-
|
|
967
|
-
// Regular sessions: cleanup immediately
|
|
968
|
-
delete this._object_store[session_id];
|
|
969
983
|
}
|
|
970
984
|
|
|
971
985
|
// Clean helper to identify promise method calls by session type
|
|
972
986
|
_is_promise_method_call(method_path) {
|
|
973
987
|
const session_id = method_path.split(".")[0];
|
|
974
|
-
|
|
975
|
-
return
|
|
988
|
+
// Simply check if session exists - no complex promise manager needed
|
|
989
|
+
return this._object_store[session_id] !== undefined;
|
|
976
990
|
}
|
|
977
991
|
|
|
978
|
-
//
|
|
992
|
+
// Simplified Promise Manager - no complex lifecycle needed
|
|
979
993
|
_create_promise_manager() {
|
|
994
|
+
// Return minimal manager - Python doesn't need complex promise tracking
|
|
980
995
|
return {
|
|
981
996
|
settled: false,
|
|
982
997
|
settle() {
|
|
@@ -986,6 +1001,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
986
1001
|
return this.settled;
|
|
987
1002
|
},
|
|
988
1003
|
should_cleanup_on_callback(callback_name) {
|
|
1004
|
+
// Always cleanup on resolve/reject like Python
|
|
989
1005
|
return callback_name === "resolve" || callback_name === "reject";
|
|
990
1006
|
},
|
|
991
1007
|
};
|
|
@@ -1009,9 +1025,8 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1009
1025
|
}
|
|
1010
1026
|
let encoded = {};
|
|
1011
1027
|
|
|
1012
|
-
//
|
|
1013
|
-
store
|
|
1014
|
-
|
|
1028
|
+
// Simplified promise lifecycle - no complex manager needed
|
|
1029
|
+
// Just store the timer if needed
|
|
1015
1030
|
if (timer && reject && this._method_timeout) {
|
|
1016
1031
|
[encoded.heartbeat, store.heartbeat] = this._encode_callback(
|
|
1017
1032
|
"heartbeat",
|
|
@@ -1025,11 +1040,12 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1025
1040
|
encoded.interval = this._method_timeout / 2;
|
|
1026
1041
|
}
|
|
1027
1042
|
|
|
1043
|
+
// Always use immediate cleanup like Python
|
|
1028
1044
|
[encoded.resolve, store.resolve] = this._encode_callback(
|
|
1029
1045
|
"resolve",
|
|
1030
1046
|
resolve,
|
|
1031
1047
|
session_id,
|
|
1032
|
-
|
|
1048
|
+
true, // Always cleanup immediately
|
|
1033
1049
|
timer,
|
|
1034
1050
|
local_workspace,
|
|
1035
1051
|
`resolve (${description})`,
|
|
@@ -1038,7 +1054,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1038
1054
|
"reject",
|
|
1039
1055
|
reject,
|
|
1040
1056
|
session_id,
|
|
1041
|
-
|
|
1057
|
+
true, // Always cleanup immediately
|
|
1042
1058
|
timer,
|
|
1043
1059
|
local_workspace,
|
|
1044
1060
|
`reject (${description})`,
|
|
@@ -1058,13 +1074,13 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1058
1074
|
}
|
|
1059
1075
|
|
|
1060
1076
|
const message_cache = remote_services.message_cache;
|
|
1061
|
-
const message_id = session_id || (0,
|
|
1077
|
+
const message_id = session_id || (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.randId)();
|
|
1062
1078
|
const total_size = data.length;
|
|
1063
1079
|
const start_time = Date.now(); // measure time
|
|
1064
1080
|
const chunk_num = Math.ceil(total_size / this._long_message_chunk_size);
|
|
1065
1081
|
if (remote_services.config.api_version >= 3) {
|
|
1066
1082
|
await message_cache.create(message_id, !!session_id);
|
|
1067
|
-
const semaphore = new
|
|
1083
|
+
const semaphore = new _utils_index_js__WEBPACK_IMPORTED_MODULE_0__.Semaphore(CONCURRENCY_LIMIT);
|
|
1068
1084
|
|
|
1069
1085
|
const tasks = [];
|
|
1070
1086
|
for (let idx = 0; idx < chunk_num; idx++) {
|
|
@@ -1120,7 +1136,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1120
1136
|
}
|
|
1121
1137
|
|
|
1122
1138
|
emit(main_message, extra_data) {
|
|
1123
|
-
(0,
|
|
1139
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
1124
1140
|
typeof main_message === "object" && main_message.type,
|
|
1125
1141
|
"Invalid message, must be an object with a `type` fields.",
|
|
1126
1142
|
);
|
|
@@ -1162,7 +1178,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1162
1178
|
|
|
1163
1179
|
function remote_method() {
|
|
1164
1180
|
return new Promise(async (resolve, reject) => {
|
|
1165
|
-
let local_session_id = (0,
|
|
1181
|
+
let local_session_id = (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.randId)();
|
|
1166
1182
|
if (local_parent) {
|
|
1167
1183
|
// Store the children session under the parent
|
|
1168
1184
|
local_session_id = local_parent + "." + local_session_id;
|
|
@@ -1353,7 +1369,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1353
1369
|
let reject = null;
|
|
1354
1370
|
let heartbeat_task = null;
|
|
1355
1371
|
try {
|
|
1356
|
-
(0,
|
|
1372
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(data.method && data.ctx && data.from);
|
|
1357
1373
|
const method_name = data.from + ":" + data.method;
|
|
1358
1374
|
const remote_workspace = data.from.split("/")[0];
|
|
1359
1375
|
const remote_client_id = data.from.split("/")[1];
|
|
@@ -1367,7 +1383,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1367
1383
|
local_workspace = data["to"].split("/")[0];
|
|
1368
1384
|
} else {
|
|
1369
1385
|
if (this._local_workspace && this._local_workspace !== "*") {
|
|
1370
|
-
(0,
|
|
1386
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
1371
1387
|
data["to"].split("/")[0] === this._local_workspace,
|
|
1372
1388
|
"Workspace mismatch: " +
|
|
1373
1389
|
data["to"].split("/")[0] +
|
|
@@ -1402,6 +1418,13 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1402
1418
|
}
|
|
1403
1419
|
}
|
|
1404
1420
|
heartbeat_task = setInterval(heartbeat, promise.interval * 1000);
|
|
1421
|
+
// Store the heartbeat task in the session store for cleanup
|
|
1422
|
+
if (data.session) {
|
|
1423
|
+
const session_store = this._get_session_store(data.session, false);
|
|
1424
|
+
if (session_store) {
|
|
1425
|
+
session_store.heartbeat_task = heartbeat_task;
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1405
1428
|
}
|
|
1406
1429
|
}
|
|
1407
1430
|
|
|
@@ -1410,10 +1433,10 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1410
1433
|
try {
|
|
1411
1434
|
method = indexObject(this._object_store, data["method"]);
|
|
1412
1435
|
} catch (e) {
|
|
1413
|
-
//
|
|
1414
|
-
if (this.
|
|
1436
|
+
// Simplified error handling like Python - just check if method exists
|
|
1437
|
+
if (!this._object_store[data["method"].split(".")[0]]) {
|
|
1415
1438
|
console.debug(
|
|
1416
|
-
`
|
|
1439
|
+
`Method ${data["method"]} not available (session cleaned up), ignoring: ${method_name}`,
|
|
1417
1440
|
);
|
|
1418
1441
|
return;
|
|
1419
1442
|
}
|
|
@@ -1423,7 +1446,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1423
1446
|
);
|
|
1424
1447
|
}
|
|
1425
1448
|
|
|
1426
|
-
(0,
|
|
1449
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
1427
1450
|
method && typeof method === "function",
|
|
1428
1451
|
"Invalid method: " + method_name,
|
|
1429
1452
|
);
|
|
@@ -1473,7 +1496,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1473
1496
|
// Make sure the parent session is still open
|
|
1474
1497
|
if (local_parent) {
|
|
1475
1498
|
// The parent session should be a session that generate the current method call
|
|
1476
|
-
(0,
|
|
1499
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
1477
1500
|
this._get_session_store(local_parent, true) !== null,
|
|
1478
1501
|
"Parent session was closed: " + local_parent,
|
|
1479
1502
|
);
|
|
@@ -1494,18 +1517,30 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1494
1517
|
this._method_annotations.has(method) &&
|
|
1495
1518
|
this._method_annotations.get(method).require_context
|
|
1496
1519
|
) {
|
|
1497
|
-
// if
|
|
1498
|
-
//
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1520
|
+
// Check if this is a remote service (from external clients)
|
|
1521
|
+
// Remote services start with a session ID or client ID, not "services."
|
|
1522
|
+
const isRemoteService = !data.method.startsWith("services.");
|
|
1523
|
+
|
|
1524
|
+
if (isRemoteService) {
|
|
1525
|
+
// For remote services (external client services), the method.length reflects
|
|
1526
|
+
// the original signature and cannot be modified. We inject context as the last argument
|
|
1527
|
+
// and skip the strict argument validation that fails for external services.
|
|
1528
|
+
args.push(data.ctx);
|
|
1529
|
+
} else {
|
|
1530
|
+
// For local services, use the existing logic with padding and validation
|
|
1531
|
+
// if args.length + 1 is less than the required number of arguments we will pad with undefined
|
|
1532
|
+
// so we make sure the last argument is the context
|
|
1533
|
+
if (args.length + 1 < method.length) {
|
|
1534
|
+
for (let i = args.length; i < method.length - 1; i++) {
|
|
1535
|
+
args.push(undefined);
|
|
1536
|
+
}
|
|
1502
1537
|
}
|
|
1538
|
+
args.push(data.ctx);
|
|
1539
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
1540
|
+
args.length === method.length,
|
|
1541
|
+
`Runtime Error: Invalid number of arguments for method ${method_name}, expected ${method.length} but got ${args.length}`,
|
|
1542
|
+
);
|
|
1503
1543
|
}
|
|
1504
|
-
args.push(data.ctx);
|
|
1505
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
1506
|
-
args.length === method.length,
|
|
1507
|
-
`Runtime Error: Invalid number of arguments for method ${method_name}, expected ${method.length} but got ${args.length}`,
|
|
1508
|
-
);
|
|
1509
1544
|
}
|
|
1510
1545
|
// console.debug(`Executing method: ${method_name} (${data.method})`);
|
|
1511
1546
|
if (data.promise) {
|
|
@@ -1528,6 +1563,12 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1528
1563
|
method.apply(null, args);
|
|
1529
1564
|
clearInterval(heartbeat_task);
|
|
1530
1565
|
}
|
|
1566
|
+
if (data.session) {
|
|
1567
|
+
const session_store = this._get_session_store(data.session, false);
|
|
1568
|
+
if (session_store) {
|
|
1569
|
+
delete session_store.heartbeat_task;
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1531
1572
|
} catch (err) {
|
|
1532
1573
|
if (reject) {
|
|
1533
1574
|
reject(err);
|
|
@@ -1623,23 +1664,23 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1623
1664
|
return bObject;
|
|
1624
1665
|
}
|
|
1625
1666
|
|
|
1626
|
-
if ((0,
|
|
1667
|
+
if ((0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.isGenerator)(aObject) || (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.isAsyncGenerator)(aObject)) {
|
|
1627
1668
|
// Handle generator functions and generator objects
|
|
1628
|
-
(0,
|
|
1669
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
1629
1670
|
session_id && typeof session_id === "string",
|
|
1630
1671
|
"Session ID is required for generator encoding",
|
|
1631
1672
|
);
|
|
1632
|
-
const object_id = (0,
|
|
1673
|
+
const object_id = (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.randId)();
|
|
1633
1674
|
|
|
1634
1675
|
// Get the session store
|
|
1635
1676
|
const store = this._get_session_store(session_id, true);
|
|
1636
|
-
(0,
|
|
1677
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
1637
1678
|
store !== null,
|
|
1638
1679
|
`Failed to create session store ${session_id} due to invalid parent`,
|
|
1639
1680
|
);
|
|
1640
1681
|
|
|
1641
1682
|
// Check if it's an async generator
|
|
1642
|
-
const isAsync = (0,
|
|
1683
|
+
const isAsync = (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.isAsyncGenerator)(aObject);
|
|
1643
1684
|
|
|
1644
1685
|
// Define method to get next item from the generator
|
|
1645
1686
|
const nextItemMethod = async () => {
|
|
@@ -1687,12 +1728,12 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1687
1728
|
_rname: aObject.name,
|
|
1688
1729
|
};
|
|
1689
1730
|
} else {
|
|
1690
|
-
(0,
|
|
1731
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(typeof session_id === "string");
|
|
1691
1732
|
let object_id;
|
|
1692
1733
|
if (aObject.__name__) {
|
|
1693
|
-
object_id = `${(0,
|
|
1734
|
+
object_id = `${(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.randId)()}#${aObject.__name__}`;
|
|
1694
1735
|
} else {
|
|
1695
|
-
object_id = (0,
|
|
1736
|
+
object_id = (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.randId)();
|
|
1696
1737
|
}
|
|
1697
1738
|
bObject = {
|
|
1698
1739
|
_rtype: "method",
|
|
@@ -1703,7 +1744,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1703
1744
|
_rname: aObject.name,
|
|
1704
1745
|
};
|
|
1705
1746
|
let store = this._get_session_store(session_id, true);
|
|
1706
|
-
(0,
|
|
1747
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
1707
1748
|
store !== null,
|
|
1708
1749
|
`Failed to create session store ${session_id} due to invalid parent`,
|
|
1709
1750
|
);
|
|
@@ -1769,7 +1810,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1769
1810
|
if (!aObject.selection || !aObject.selection.data) {
|
|
1770
1811
|
throw new Error("Invalid NumJS array: missing selection or data");
|
|
1771
1812
|
}
|
|
1772
|
-
const dtype = (0,
|
|
1813
|
+
const dtype = (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.typedArrayToDtype)(aObject.selection.data);
|
|
1773
1814
|
bObject = {
|
|
1774
1815
|
_rtype: "ndarray",
|
|
1775
1816
|
_rvalue: new Uint8Array(aObject.selection.data.buffer),
|
|
@@ -1832,7 +1873,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1832
1873
|
seek: await this._encode(seek, session_id, local_workspace),
|
|
1833
1874
|
};
|
|
1834
1875
|
} else if (aObject instanceof ArrayBufferView) {
|
|
1835
|
-
const dtype = (0,
|
|
1876
|
+
const dtype = (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.typedArrayToDtype)(aObject);
|
|
1836
1877
|
bObject = {
|
|
1837
1878
|
_rtype: "typedarray",
|
|
1838
1879
|
_rvalue: new Uint8Array(aObject.buffer),
|
|
@@ -1964,7 +2005,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1964
2005
|
if (Array.isArray(aObject._rvalue)) {
|
|
1965
2006
|
aObject._rvalue = aObject._rvalue.reduce(_appendBuffer);
|
|
1966
2007
|
}
|
|
1967
|
-
const arraytype =
|
|
2008
|
+
const arraytype = _utils_index_js__WEBPACK_IMPORTED_MODULE_0__.dtypeToTypedArray[aObject._rdtype];
|
|
1968
2009
|
bObject = tf.tensor(
|
|
1969
2010
|
new arraytype(aObject._rvalue),
|
|
1970
2011
|
aObject._rshape,
|
|
@@ -1979,7 +2020,7 @@ class RPC extends _utils__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
|
|
|
1979
2020
|
"RemoteError: " + aObject._rvalue + "\n" + (aObject._rtrace || ""),
|
|
1980
2021
|
);
|
|
1981
2022
|
} else if (aObject._rtype === "typedarray") {
|
|
1982
|
-
const arraytype =
|
|
2023
|
+
const arraytype = _utils_index_js__WEBPACK_IMPORTED_MODULE_0__.dtypeToTypedArray[aObject._rdtype];
|
|
1983
2024
|
if (!arraytype)
|
|
1984
2025
|
throw new Error("unsupported dtype: " + aObject._rdtype);
|
|
1985
2026
|
const buffer = aObject._rvalue.buffer.slice(
|
|
@@ -2690,7 +2731,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2690
2731
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
2691
2732
|
/* harmony export */ schemaFunction: () => (/* binding */ schemaFunction)
|
|
2692
2733
|
/* harmony export */ });
|
|
2693
|
-
/* harmony import */ var
|
|
2734
|
+
/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./index.js */ "./src/utils/index.js");
|
|
2694
2735
|
|
|
2695
2736
|
|
|
2696
2737
|
function schemaFunction(
|
|
@@ -2700,9 +2741,9 @@ function schemaFunction(
|
|
|
2700
2741
|
if (!func || typeof func !== "function") {
|
|
2701
2742
|
throw Error("func should be a function");
|
|
2702
2743
|
}
|
|
2703
|
-
(0,
|
|
2704
|
-
(0,
|
|
2705
|
-
(0,
|
|
2744
|
+
(0,_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(schema_type === "auto", "schema_type should be auto");
|
|
2745
|
+
(0,_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(name, "name should not be null");
|
|
2746
|
+
(0,_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
|
|
2706
2747
|
parameters && parameters.type === "object",
|
|
2707
2748
|
"parameters should be an object",
|
|
2708
2749
|
);
|
|
@@ -2729,7 +2770,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2729
2770
|
/* harmony export */ registerRTCService: () => (/* binding */ registerRTCService)
|
|
2730
2771
|
/* harmony export */ });
|
|
2731
2772
|
/* harmony import */ var _rpc_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./rpc.js */ "./src/rpc.js");
|
|
2732
|
-
/* harmony import */ var
|
|
2773
|
+
/* harmony import */ var _utils_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils/index.js */ "./src/utils/index.js");
|
|
2733
2774
|
/* harmony import */ var _utils_schema_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils/schema.js */ "./src/utils/schema.js");
|
|
2734
2775
|
|
|
2735
2776
|
|
|
@@ -2777,12 +2818,12 @@ class WebRTCConnection {
|
|
|
2777
2818
|
}
|
|
2778
2819
|
|
|
2779
2820
|
on_message(handler) {
|
|
2780
|
-
(0,
|
|
2821
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(handler, "handler is required");
|
|
2781
2822
|
this._handle_message = handler;
|
|
2782
2823
|
}
|
|
2783
2824
|
|
|
2784
2825
|
async emit_message(data) {
|
|
2785
|
-
(0,
|
|
2826
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(this._handle_message, "No handler for message");
|
|
2786
2827
|
try {
|
|
2787
2828
|
this._last_message = data;
|
|
2788
2829
|
this._data_channel.send(data);
|
|
@@ -2801,10 +2842,10 @@ class WebRTCConnection {
|
|
|
2801
2842
|
}
|
|
2802
2843
|
|
|
2803
2844
|
async function _setupRPC(config) {
|
|
2804
|
-
(0,
|
|
2805
|
-
(0,
|
|
2845
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(config.channel, "No channel provided");
|
|
2846
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(config.workspace, "No workspace provided");
|
|
2806
2847
|
const channel = config.channel;
|
|
2807
|
-
const clientId = config.client_id || (0,
|
|
2848
|
+
const clientId = config.client_id || (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.randId)();
|
|
2808
2849
|
const connection = new WebRTCConnection(channel);
|
|
2809
2850
|
config.context = config.context || {};
|
|
2810
2851
|
config.context.connection_type = "webrtc";
|
|
@@ -2884,7 +2925,7 @@ async function _createOffer(params, server, config, onInit, context) {
|
|
|
2884
2925
|
|
|
2885
2926
|
async function getRTCService(server, service_id, config) {
|
|
2886
2927
|
config = config || {};
|
|
2887
|
-
config.peer_id = config.peer_id || (0,
|
|
2928
|
+
config.peer_id = config.peer_id || (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.randId)();
|
|
2888
2929
|
|
|
2889
2930
|
const pc = new RTCPeerConnection({
|
|
2890
2931
|
iceServers: config.ice_servers || [
|
|
@@ -2984,11 +3025,11 @@ async function getRTCService(server, service_id, config) {
|
|
|
2984
3025
|
const rpc = await _setupRPC(config);
|
|
2985
3026
|
pc.rpc = rpc;
|
|
2986
3027
|
async function get_service(name, ...args) {
|
|
2987
|
-
(0,
|
|
3028
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(
|
|
2988
3029
|
!name.includes(":"),
|
|
2989
3030
|
"WebRTC service name should not contain ':'",
|
|
2990
3031
|
);
|
|
2991
|
-
(0,
|
|
3032
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(
|
|
2992
3033
|
!name.includes("/"),
|
|
2993
3034
|
"WebRTC service name should not contain '/'",
|
|
2994
3035
|
);
|
|
@@ -5073,14 +5114,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
5073
5114
|
/* harmony export */ connectToServer: () => (/* binding */ connectToServer),
|
|
5074
5115
|
/* harmony export */ getRTCService: () => (/* reexport safe */ _webrtc_client_js__WEBPACK_IMPORTED_MODULE_3__.getRTCService),
|
|
5075
5116
|
/* harmony export */ getRemoteService: () => (/* binding */ getRemoteService),
|
|
5076
|
-
/* harmony export */ loadRequirements: () => (/* reexport safe */
|
|
5117
|
+
/* harmony export */ loadRequirements: () => (/* reexport safe */ _utils_index_js__WEBPACK_IMPORTED_MODULE_1__.loadRequirements),
|
|
5077
5118
|
/* harmony export */ login: () => (/* binding */ login),
|
|
5078
5119
|
/* harmony export */ registerRTCService: () => (/* reexport safe */ _webrtc_client_js__WEBPACK_IMPORTED_MODULE_3__.registerRTCService),
|
|
5079
5120
|
/* harmony export */ schemaFunction: () => (/* reexport safe */ _utils_schema_js__WEBPACK_IMPORTED_MODULE_2__.schemaFunction),
|
|
5080
5121
|
/* harmony export */ setupLocalClient: () => (/* binding */ setupLocalClient)
|
|
5081
5122
|
/* harmony export */ });
|
|
5082
5123
|
/* harmony import */ var _rpc_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./rpc.js */ "./src/rpc.js");
|
|
5083
|
-
/* harmony import */ var
|
|
5124
|
+
/* harmony import */ var _utils_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils/index.js */ "./src/utils/index.js");
|
|
5084
5125
|
/* harmony import */ var _utils_schema_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils/schema.js */ "./src/utils/schema.js");
|
|
5085
5126
|
/* harmony import */ var _webrtc_client_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./webrtc-client.js */ "./src/webrtc-client.js");
|
|
5086
5127
|
|
|
@@ -5105,7 +5146,7 @@ class WebsocketRPCConnection {
|
|
|
5105
5146
|
WebSocketClass = null,
|
|
5106
5147
|
token_refresh_interval = 2 * 60 * 60,
|
|
5107
5148
|
) {
|
|
5108
|
-
(0,
|
|
5149
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(server_url && client_id, "server_url and client_id are required");
|
|
5109
5150
|
this._server_url = server_url;
|
|
5110
5151
|
this._client_id = client_id;
|
|
5111
5152
|
this._workspace = workspace;
|
|
@@ -5146,7 +5187,7 @@ class WebsocketRPCConnection {
|
|
|
5146
5187
|
}
|
|
5147
5188
|
|
|
5148
5189
|
on_message(handler) {
|
|
5149
|
-
(0,
|
|
5190
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(handler, "handler is required");
|
|
5150
5191
|
this._handle_message = handler;
|
|
5151
5192
|
}
|
|
5152
5193
|
|
|
@@ -5224,7 +5265,7 @@ class WebsocketRPCConnection {
|
|
|
5224
5265
|
if (first_message.type == "connection_info") {
|
|
5225
5266
|
this.connection_info = first_message;
|
|
5226
5267
|
if (this._workspace) {
|
|
5227
|
-
(0,
|
|
5268
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(
|
|
5228
5269
|
this.connection_info.workspace === this._workspace,
|
|
5229
5270
|
`Connected to the wrong workspace: ${this.connection_info.workspace}, expected: ${this._workspace}`,
|
|
5230
5271
|
);
|
|
@@ -5295,7 +5336,7 @@ class WebsocketRPCConnection {
|
|
|
5295
5336
|
});
|
|
5296
5337
|
this._websocket.send(authInfo);
|
|
5297
5338
|
// Wait for the first message from the server
|
|
5298
|
-
await (0,
|
|
5339
|
+
await (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.waitFor)(
|
|
5299
5340
|
this._establish_connection(),
|
|
5300
5341
|
this._timeout,
|
|
5301
5342
|
"Failed to receive the first message from the server",
|
|
@@ -5508,7 +5549,7 @@ async function login(config) {
|
|
|
5508
5549
|
});
|
|
5509
5550
|
try {
|
|
5510
5551
|
const svc = await server.getService(service_id);
|
|
5511
|
-
(0,
|
|
5552
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(svc, `Failed to get the login service: ${service_id}`);
|
|
5512
5553
|
let context;
|
|
5513
5554
|
if (workspace) {
|
|
5514
5555
|
context = await svc.start({ workspace, expires_in, _rkwargs: true });
|
|
@@ -5534,7 +5575,7 @@ async function webrtcGetService(wm, rtc_service_id, query, config) {
|
|
|
5534
5575
|
const webrtc_config = config.webrtc_config;
|
|
5535
5576
|
if (config.webrtc !== undefined) delete config.webrtc;
|
|
5536
5577
|
if (config.webrtc_config !== undefined) delete config.webrtc_config;
|
|
5537
|
-
(0,
|
|
5578
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(
|
|
5538
5579
|
[undefined, true, false, "auto"].includes(webrtc),
|
|
5539
5580
|
"webrtc must be true, false or 'auto'",
|
|
5540
5581
|
);
|
|
@@ -5572,7 +5613,7 @@ async function connectToServer(config) {
|
|
|
5572
5613
|
}
|
|
5573
5614
|
let clientId = config.client_id;
|
|
5574
5615
|
if (!clientId) {
|
|
5575
|
-
clientId = (0,
|
|
5616
|
+
clientId = (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.randId)();
|
|
5576
5617
|
config.client_id = clientId;
|
|
5577
5618
|
}
|
|
5578
5619
|
|
|
@@ -5588,7 +5629,7 @@ async function connectToServer(config) {
|
|
|
5588
5629
|
config.WebSocketClass,
|
|
5589
5630
|
);
|
|
5590
5631
|
const connection_info = await connection.open();
|
|
5591
|
-
(0,
|
|
5632
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(
|
|
5592
5633
|
connection_info,
|
|
5593
5634
|
"Failed to connect to the server, no connection info obtained. This issue is most likely due to an outdated Hypha server version. Please use `imjoy-rpc` for compatibility, or upgrade the Hypha server to the latest version.",
|
|
5594
5635
|
);
|
|
@@ -5647,11 +5688,11 @@ async function connectToServer(config) {
|
|
|
5647
5688
|
|
|
5648
5689
|
async function getApp(clientId) {
|
|
5649
5690
|
clientId = clientId || "*";
|
|
5650
|
-
(0,
|
|
5691
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(!clientId.includes(":"), "clientId should not contain ':'");
|
|
5651
5692
|
if (!clientId.includes("/")) {
|
|
5652
5693
|
clientId = connection_info.workspace + "/" + clientId;
|
|
5653
5694
|
}
|
|
5654
|
-
(0,
|
|
5695
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(
|
|
5655
5696
|
clientId.split("/").length === 2,
|
|
5656
5697
|
"clientId should match pattern workspace/clientId",
|
|
5657
5698
|
);
|
|
@@ -5660,8 +5701,8 @@ async function connectToServer(config) {
|
|
|
5660
5701
|
|
|
5661
5702
|
async function listApps(ws) {
|
|
5662
5703
|
ws = ws || workspace;
|
|
5663
|
-
(0,
|
|
5664
|
-
(0,
|
|
5704
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(!ws.includes(":"), "workspace should not contain ':'");
|
|
5705
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(!ws.includes("/"), "workspace should not contain '/'");
|
|
5665
5706
|
const query = { workspace: ws, service_id: "default" };
|
|
5666
5707
|
return await wm.listServices(query);
|
|
5667
5708
|
}
|
|
@@ -5903,7 +5944,7 @@ async function connectToServer(config) {
|
|
|
5903
5944
|
|
|
5904
5945
|
async function getRemoteService(serviceUri, config = {}) {
|
|
5905
5946
|
const { serverUrl, workspace, clientId, serviceId, appId } =
|
|
5906
|
-
(0,
|
|
5947
|
+
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.parseServiceUrl)(serviceUri);
|
|
5907
5948
|
const fullServiceId = `${workspace}/${clientId}:${serviceId}@${appId}`;
|
|
5908
5949
|
|
|
5909
5950
|
if (config.serverUrl) {
|