@holochain/client 0.12.3 → 0.12.5

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.
@@ -93,9 +93,7 @@ export class AppAgentWebsocket {
93
93
  */
94
94
  async callZome(request, timeout) {
95
95
  if ("provenance" in request) {
96
- if (request.provenance !== this.myPubKey &&
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
  }
@@ -42,5 +42,5 @@ export declare class WsClient extends Emittery {
42
42
  /**
43
43
  * Close the websocket connection.
44
44
  */
45
- close(): Promise<void>;
45
+ close(code?: number): Promise<void>;
46
46
  }
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 readible content to the UI, the signal payload must also be deserialized.
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.onclose = (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 code: ${event.code}, 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holochain/client",
3
- "version": "0.12.3",
3
+ "version": "0.12.5",
4
4
  "description": "A JavaScript client for the Holochain Conductor API",
5
5
  "author": "Holochain Foundation <info@holochain.org> (http://holochain.org)",
6
6
  "license": "CAL-1.0",