@holochain/client 0.12.3 → 0.12.4
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/lib/api/app-agent/websocket.js +1 -3
- package/lib/api/client.d.ts +1 -1
- package/lib/api/client.js +24 -14
- package/package.json +1 -1
|
@@ -93,9 +93,7 @@ export class AppAgentWebsocket {
|
|
|
93
93
|
*/
|
|
94
94
|
async callZome(request, timeout) {
|
|
95
95
|
if ("provenance" in request) {
|
|
96
|
-
if (request
|
|
97
|
-
"role_name" in request &&
|
|
98
|
-
request.role_name) {
|
|
96
|
+
if ("role_name" in request && request.role_name) {
|
|
99
97
|
throw new Error("Cannot find other agent's cells based on role name. Use cell id when providing a provenance.");
|
|
100
98
|
}
|
|
101
99
|
}
|
package/lib/api/client.d.ts
CHANGED
package/lib/api/client.js
CHANGED
|
@@ -48,7 +48,7 @@ export class WsClient extends Emittery {
|
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
50
|
const encodedAppSignal = deserializedSignal[SignalType.App];
|
|
51
|
-
// In order to return
|
|
51
|
+
// In order to return readable content to the UI, the signal payload must also be deserialized.
|
|
52
52
|
const payload = decode(encodedAppSignal.signal);
|
|
53
53
|
const signal = {
|
|
54
54
|
cell_id: encodedAppSignal.cell_id,
|
|
@@ -64,6 +64,16 @@ export class WsClient extends Emittery {
|
|
|
64
64
|
console.error(`Got unrecognized Websocket message type: ${message.type}`);
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
|
+
socket.on("close", (event) => {
|
|
68
|
+
const pendingRequestIds = Object.keys(this.pendingRequests).map((id) => parseInt(id));
|
|
69
|
+
if (pendingRequestIds.length) {
|
|
70
|
+
pendingRequestIds.forEach((id) => {
|
|
71
|
+
const error = new Error(`Websocket closed with pending requests. Close event: ${event}, request id: ${id}`);
|
|
72
|
+
this.pendingRequests[id].reject(error);
|
|
73
|
+
delete this.pendingRequests[id];
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
67
77
|
}
|
|
68
78
|
/**
|
|
69
79
|
* Instance factory for creating WsClients.
|
|
@@ -105,23 +115,23 @@ export class WsClient extends Emittery {
|
|
|
105
115
|
* @returns
|
|
106
116
|
*/
|
|
107
117
|
request(request) {
|
|
108
|
-
const id = this.index;
|
|
109
|
-
this.index += 1;
|
|
110
|
-
const encodedMsg = encode({
|
|
111
|
-
id,
|
|
112
|
-
type: "request",
|
|
113
|
-
data: encode(request),
|
|
114
|
-
});
|
|
115
|
-
const promise = new Promise((resolve, reject) => {
|
|
116
|
-
this.pendingRequests[id] = { resolve, reject };
|
|
117
|
-
});
|
|
118
118
|
if (this.socket.readyState === this.socket.OPEN) {
|
|
119
|
+
const id = this.index;
|
|
120
|
+
const encodedMsg = encode({
|
|
121
|
+
id,
|
|
122
|
+
type: "request",
|
|
123
|
+
data: encode(request),
|
|
124
|
+
});
|
|
125
|
+
const promise = new Promise((resolve, reject) => {
|
|
126
|
+
this.pendingRequests[id] = { resolve, reject };
|
|
127
|
+
});
|
|
119
128
|
this.socket.send(encodedMsg);
|
|
129
|
+
this.index += 1;
|
|
130
|
+
return promise;
|
|
120
131
|
}
|
|
121
132
|
else {
|
|
122
133
|
return Promise.reject(new Error("Socket is not open"));
|
|
123
134
|
}
|
|
124
|
-
return promise;
|
|
125
135
|
}
|
|
126
136
|
handleResponse(msg) {
|
|
127
137
|
const id = msg.id;
|
|
@@ -141,9 +151,9 @@ export class WsClient extends Emittery {
|
|
|
141
151
|
/**
|
|
142
152
|
* Close the websocket connection.
|
|
143
153
|
*/
|
|
144
|
-
close() {
|
|
154
|
+
close(code) {
|
|
145
155
|
const closedPromise = new Promise((resolve) => this.socket.on("close", resolve));
|
|
146
|
-
this.socket.close();
|
|
156
|
+
this.socket.close(code);
|
|
147
157
|
return closedPromise;
|
|
148
158
|
}
|
|
149
159
|
}
|
package/package.json
CHANGED