@signalapp/libsignal-client 0.53.0 → 0.54.0

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/net.d.ts CHANGED
@@ -80,25 +80,13 @@ export interface ChatServiceListener {
80
80
  onConnectionInterrupted(): void;
81
81
  }
82
82
  /**
83
- * Provides API methods to connect and communicate with the Chat Service over an authenticated channel.
83
+ * Provides API methods to connect and communicate with the Chat Service.
84
84
  * Before sending/receiving requests, a {@link #connect()} method must be called.
85
85
  * It's also important to call {@link #disconnect()} method when the instance is no longer needed.
86
86
  */
87
- export declare class AuthenticatedChatService {
88
- private readonly asyncContext;
89
- readonly chatService: Wrapper<Native.Chat>;
90
- constructor(asyncContext: TokioAsyncContext, connectionManager: ConnectionManager, username: string, password: string, listener: ChatServiceListener);
91
- /**
92
- * Initiates termination of the underlying connection to the Chat Service. After the service is
93
- * disconnected, it will not attempt to automatically reconnect until you call
94
- * {@link #connect()}.
95
- *
96
- * Note: the same instance of `AuthenticatedChatService` can be reused after {@link #disconnect()} was
97
- * called.
98
- */
99
- disconnect(): Promise<void>;
87
+ export type ChatService = {
100
88
  /**
101
- * Initiates establishing of the underlying authenticated connection to the Chat Service. Once the
89
+ * Initiates establishing of the underlying connection to the Chat Service. Once the
102
90
  * service is connected, all the requests will be using the established connection. Also, if the
103
91
  * connection is lost for any reason other than the call to {@link #disconnect()}, an automatic
104
92
  * reconnect attempt will be made.
@@ -113,7 +101,16 @@ export declare class AuthenticatedChatService {
113
101
  abortSignal?: AbortSignal;
114
102
  }): Promise<Native.ChatServiceDebugInfo>;
115
103
  /**
116
- * Sends request to the Chat Service over an authenticated channel.
104
+ * Initiates termination of the underlying connection to the Chat Service. After the service is
105
+ * disconnected, it will not attempt to automatically reconnect until you call
106
+ * {@link #connect()}.
107
+ *
108
+ * Note: the same instance of `ChatService` can be reused after {@link #disconnect()} was
109
+ * called.
110
+ */
111
+ disconnect(): Promise<void>;
112
+ /**
113
+ * Sends request to the Chat Service.
117
114
  *
118
115
  * In addition to the response, an object containing debug information about the request flow is
119
116
  * returned.
@@ -125,7 +122,7 @@ export declare class AuthenticatedChatService {
125
122
  abortSignal?: AbortSignal;
126
123
  }): Promise<Native.ResponseAndDebugInfo>;
127
124
  /**
128
- * Sends request to the Chat Service over an authenticated channel.
125
+ * Sends request to the Chat Service.
129
126
  *
130
127
  * @throws {ChatServiceInactive} if you haven't called {@link #connect()} (as a
131
128
  * rejection of the promise).
@@ -133,55 +130,39 @@ export declare class AuthenticatedChatService {
133
130
  fetch(chatRequest: ChatRequest, options?: {
134
131
  abortSignal?: AbortSignal;
135
132
  }): Promise<Native.ChatResponse>;
133
+ };
134
+ /**
135
+ * Provides API methods to connect and communicate with the Chat Service over an authenticated channel.
136
+ */
137
+ export declare class AuthenticatedChatService implements ChatService {
138
+ private readonly asyncContext;
139
+ readonly chatService: Wrapper<Native.Chat>;
140
+ constructor(asyncContext: TokioAsyncContext, connectionManager: ConnectionManager, username: string, password: string, receiveStories: boolean, listener: ChatServiceListener);
141
+ disconnect(): Promise<void>;
142
+ connect(options?: {
143
+ abortSignal?: AbortSignal;
144
+ }): Promise<Native.ChatServiceDebugInfo>;
145
+ fetchAndDebug(chatRequest: ChatRequest, options?: {
146
+ abortSignal?: AbortSignal;
147
+ }): Promise<Native.ResponseAndDebugInfo>;
148
+ fetch(chatRequest: ChatRequest, options?: {
149
+ abortSignal?: AbortSignal;
150
+ }): Promise<Native.ChatResponse>;
136
151
  }
137
152
  /**
138
153
  * Provides API methods to connect and communicate with the Chat Service over an unauthenticated channel.
139
- * Before sending requests, a {@link #connect()} method must be called.
140
- * It's also important to call {@link #disconnect()} method when the instance is no longer needed.
141
154
  */
142
- export declare class UnauthenticatedChatService {
155
+ export declare class UnauthenticatedChatService implements ChatService {
143
156
  private readonly asyncContext;
144
157
  readonly chatService: Wrapper<Native.Chat>;
145
158
  constructor(asyncContext: TokioAsyncContext, connectionManager: ConnectionManager);
146
- /**
147
- * Initiates termination of the underlying connection to the Chat Service. After the service is
148
- * disconnected, it will not attempt to automatically reconnect until you call
149
- * {@link #connect()}.
150
- *
151
- * Note: the same instance of `UnauthenticatedChatService` can be reused after {@link #disconnect()} was
152
- * called.
153
- */
154
159
  disconnect(): Promise<void>;
155
- /**
156
- * Initiates establishing of the underlying unauthenticated connection to the Chat Service. Once
157
- * the service is connected, all the requests will be using the established connection. Also, if
158
- * the connection is lost for any reason other than the call to {@link #disconnect()}, an
159
- * automatic reconnect attempt will be made.
160
- *
161
- * @throws {AppExpiredError} if the current app version is too old (as judged by the server).
162
- * @throws {LibSignalError} with other codes for other failures.
163
- */
164
160
  connect(options?: {
165
161
  abortSignal?: AbortSignal;
166
162
  }): Promise<Native.ChatServiceDebugInfo>;
167
- /**
168
- * Sends request to the Chat Service over an unauthenticated channel.
169
- *
170
- * In addition to the response, an object containing debug information about the request flow is
171
- * returned.
172
- *
173
- * @throws {ChatServiceInactive} if you haven't called {@link #connectUnauthenticated()} (as a
174
- * rejection of the promise).
175
- */
176
163
  fetchAndDebug(chatRequest: ChatRequest, options?: {
177
164
  abortSignal?: AbortSignal;
178
165
  }): Promise<Native.ResponseAndDebugInfo>;
179
- /**
180
- * Sends request to the Chat Service over an unauthenticated channel.
181
- *
182
- * @throws {ChatServiceInactive} if you haven't called {@link #connect()} (as a
183
- * rejection of the promise).
184
- */
185
166
  fetch(chatRequest: ChatRequest, options?: {
186
167
  abortSignal?: AbortSignal;
187
168
  }): Promise<Native.ChatResponse>;
@@ -197,8 +178,13 @@ export declare class Net {
197
178
  constructor(env: Environment, userAgent: string);
198
179
  /**
199
180
  * Creates a new instance of {@link AuthenticatedChatService}.
181
+ *
182
+ * Note that created `AuthenticatedChatService` will hold a **non-garbage-collectable** reference to `listener`.
183
+ * If `listener` contains a strong reference to this ChatService (directly or indirectly), both objects will be kept
184
+ * alive even with no other references. If such reference cycle is created, it's the responsibility of the caller
185
+ * to eventually break it (either using a weak reference or by assigning over the strong reference).
200
186
  */
201
- newAuthenticatedChatService(username: string, password: string, listener: ChatServiceListener): AuthenticatedChatService;
187
+ newAuthenticatedChatService(username: string, password: string, receiveStories: boolean, listener: ChatServiceListener): AuthenticatedChatService;
202
188
  /**
203
189
  * Creates a new instance of {@link UnauthenticatedChatService}.
204
190
  */
package/dist/net.js CHANGED
@@ -61,13 +61,11 @@ class ChatServerMessageAck {
61
61
  exports.ChatServerMessageAck = ChatServerMessageAck;
62
62
  /**
63
63
  * Provides API methods to connect and communicate with the Chat Service over an authenticated channel.
64
- * Before sending/receiving requests, a {@link #connect()} method must be called.
65
- * It's also important to call {@link #disconnect()} method when the instance is no longer needed.
66
64
  */
67
65
  class AuthenticatedChatService {
68
- constructor(asyncContext, connectionManager, username, password, listener) {
66
+ constructor(asyncContext, connectionManager, username, password, receiveStories, listener) {
69
67
  this.asyncContext = asyncContext;
70
- this.chatService = newNativeHandle(Native.ChatService_new(connectionManager, username, password));
68
+ this.chatService = newNativeHandle(Native.ChatService_new(connectionManager, username, password, receiveStories));
71
69
  const nativeChatListener = {
72
70
  _incoming_message(envelope, timestamp, ack) {
73
71
  listener.onIncomingMessage(envelope, timestamp, new ChatServerMessageAck(asyncContext, ack));
@@ -81,50 +79,15 @@ class AuthenticatedChatService {
81
79
  };
82
80
  Native.ChatServer_SetListener(asyncContext, this.chatService, nativeChatListener);
83
81
  }
84
- /**
85
- * Initiates termination of the underlying connection to the Chat Service. After the service is
86
- * disconnected, it will not attempt to automatically reconnect until you call
87
- * {@link #connect()}.
88
- *
89
- * Note: the same instance of `AuthenticatedChatService` can be reused after {@link #disconnect()} was
90
- * called.
91
- */
92
82
  disconnect() {
93
83
  return Native.ChatService_disconnect(this.asyncContext, this.chatService);
94
84
  }
95
- /**
96
- * Initiates establishing of the underlying authenticated connection to the Chat Service. Once the
97
- * service is connected, all the requests will be using the established connection. Also, if the
98
- * connection is lost for any reason other than the call to {@link #disconnect()}, an automatic
99
- * reconnect attempt will be made.
100
- *
101
- * Calling this method will result in starting to accept incoming requests from the Chat Service.
102
- *
103
- * @throws {AppExpiredError} if the current app version is too old (as judged by the server).
104
- * @throws {DeviceDelinkedError} if the current device has been delinked.
105
- * @throws {LibSignalError} with other codes for other failures.
106
- */
107
85
  connect(options) {
108
86
  return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_connect_auth(this.asyncContext, this.chatService));
109
87
  }
110
- /**
111
- * Sends request to the Chat Service over an authenticated channel.
112
- *
113
- * In addition to the response, an object containing debug information about the request flow is
114
- * returned.
115
- *
116
- * @throws {ChatServiceInactive} if you haven't called {@link #connect()} (as a
117
- * rejection of the promise).
118
- */
119
88
  fetchAndDebug(chatRequest, options) {
120
89
  return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_auth_send_and_debug(this.asyncContext, this.chatService, buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
121
90
  }
122
- /**
123
- * Sends request to the Chat Service over an authenticated channel.
124
- *
125
- * @throws {ChatServiceInactive} if you haven't called {@link #connect()} (as a
126
- * rejection of the promise).
127
- */
128
91
  fetch(chatRequest, options) {
129
92
  return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_auth_send(this.asyncContext, this.chatService, buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
130
93
  }
@@ -132,55 +95,21 @@ class AuthenticatedChatService {
132
95
  exports.AuthenticatedChatService = AuthenticatedChatService;
133
96
  /**
134
97
  * Provides API methods to connect and communicate with the Chat Service over an unauthenticated channel.
135
- * Before sending requests, a {@link #connect()} method must be called.
136
- * It's also important to call {@link #disconnect()} method when the instance is no longer needed.
137
98
  */
138
99
  class UnauthenticatedChatService {
139
100
  constructor(asyncContext, connectionManager) {
140
101
  this.asyncContext = asyncContext;
141
- this.chatService = newNativeHandle(Native.ChatService_new(connectionManager, '', ''));
102
+ this.chatService = newNativeHandle(Native.ChatService_new(connectionManager, '', '', false));
142
103
  }
143
- /**
144
- * Initiates termination of the underlying connection to the Chat Service. After the service is
145
- * disconnected, it will not attempt to automatically reconnect until you call
146
- * {@link #connect()}.
147
- *
148
- * Note: the same instance of `UnauthenticatedChatService` can be reused after {@link #disconnect()} was
149
- * called.
150
- */
151
104
  disconnect() {
152
105
  return Native.ChatService_disconnect(this.asyncContext, this.chatService);
153
106
  }
154
- /**
155
- * Initiates establishing of the underlying unauthenticated connection to the Chat Service. Once
156
- * the service is connected, all the requests will be using the established connection. Also, if
157
- * the connection is lost for any reason other than the call to {@link #disconnect()}, an
158
- * automatic reconnect attempt will be made.
159
- *
160
- * @throws {AppExpiredError} if the current app version is too old (as judged by the server).
161
- * @throws {LibSignalError} with other codes for other failures.
162
- */
163
107
  connect(options) {
164
108
  return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_connect_unauth(this.asyncContext, this.chatService));
165
109
  }
166
- /**
167
- * Sends request to the Chat Service over an unauthenticated channel.
168
- *
169
- * In addition to the response, an object containing debug information about the request flow is
170
- * returned.
171
- *
172
- * @throws {ChatServiceInactive} if you haven't called {@link #connectUnauthenticated()} (as a
173
- * rejection of the promise).
174
- */
175
110
  fetchAndDebug(chatRequest, options) {
176
111
  return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_unauth_send_and_debug(this.asyncContext, this.chatService, buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
177
112
  }
178
- /**
179
- * Sends request to the Chat Service over an unauthenticated channel.
180
- *
181
- * @throws {ChatServiceInactive} if you haven't called {@link #connect()} (as a
182
- * rejection of the promise).
183
- */
184
113
  fetch(chatRequest, options) {
185
114
  return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_unauth_send(this.asyncContext, this.chatService, buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
186
115
  }
@@ -207,9 +136,14 @@ class Net {
207
136
  }
208
137
  /**
209
138
  * Creates a new instance of {@link AuthenticatedChatService}.
139
+ *
140
+ * Note that created `AuthenticatedChatService` will hold a **non-garbage-collectable** reference to `listener`.
141
+ * If `listener` contains a strong reference to this ChatService (directly or indirectly), both objects will be kept
142
+ * alive even with no other references. If such reference cycle is created, it's the responsibility of the caller
143
+ * to eventually break it (either using a weak reference or by assigning over the strong reference).
210
144
  */
211
- newAuthenticatedChatService(username, password, listener) {
212
- return new AuthenticatedChatService(this.asyncContext, this.connectionManager, username, password, listener);
145
+ newAuthenticatedChatService(username, password, receiveStories, listener) {
146
+ return new AuthenticatedChatService(this.asyncContext, this.connectionManager, username, password, receiveStories, listener);
213
147
  }
214
148
  /**
215
149
  * Creates a new instance of {@link UnauthenticatedChatService}.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalapp/libsignal-client",
3
- "version": "0.53.0",
3
+ "version": "0.54.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",