@droponair/sdk-js 0.27.0 → 0.28.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.28.0
4
+
5
+ ### Fixed
6
+
7
+ - **A push token offered before the client connected was thrown away.** The push
8
+ service hands an app its device token at launch, always before a connection
9
+ exists, so `registerPushToken` refusing it there lost the token exactly when
10
+ every app first offers it, and push simply never arrived. The token is now held
11
+ and registered as soon as a connection exists. It is also re-registered on every
12
+ connect, because the relay ties a token to a session: after a reconnect or a
13
+ relay restart the device would otherwise be silently unreachable.
14
+
15
+ ### Notes
16
+
17
+ - `registerPushToken` no longer rejects a call made before connecting. Existing
18
+ code that catches that error still compiles and simply stops seeing it.
19
+ - `unregisterPushToken` drops the held token, so it is not re-registered later.
20
+
3
21
  ## 0.27.0
4
22
 
5
23
  ### Added
package/README.md CHANGED
@@ -207,6 +207,10 @@ client.onEvent(e => {
207
207
 
208
208
  Available since SDK `0.9.0`. Customers configure their own APNs / FCM / VAPID credentials in the dashboard. The platform delivers a push only when the sender attaches a `pushPayload` to a message and the recipient device has no live WebSocket session. See the per-product availability and limits on your dashboard's Subscription page.
209
209
 
210
+
211
+ Register the token as soon as you have it. The SDK holds it until a connection
212
+ exists and registers it then, and re-registers on every connect, so there is no
213
+ need to wait for the client to connect or to retry yourself.
210
214
  ```typescript
211
215
  // iOS, after didRegisterForRemoteNotificationsWithDeviceToken
212
216
  await client.registerPushToken({ platform: 'APNS', token: deviceTokenHex });
@@ -22,6 +22,11 @@ export declare class MessagingClient implements DropOnAirClient {
22
22
  private dropOnAirJwt;
23
23
  private currentUserId;
24
24
  private deviceId;
25
+ /**
26
+ * The push token this device last offered, held until a connection exists and
27
+ * re-sent on every connect. Cleared by `unregisterPushToken`.
28
+ */
29
+ private pendingPushRegistration;
25
30
  private rateLimited;
26
31
  private reconnectAttempt;
27
32
  private connectGeneration;
@@ -169,6 +174,8 @@ export declare class MessagingClient implements DropOnAirClient {
169
174
  token: string;
170
175
  voipToken?: string;
171
176
  }): Promise<void>;
177
+ /** Registers the held token, if there is one. Called on every connect. */
178
+ private sendPushRegistration;
172
179
  /**
173
180
  * Unregister this device's push notification token (e.g. on logout). Future
174
181
  * push fan-out for this (appId, userId, deviceId, platform) tuple is dropped.
@@ -246,6 +246,11 @@ class MessagingClient {
246
246
  this.dropOnAirJwt = null;
247
247
  this.currentUserId = null;
248
248
  this.deviceId = null;
249
+ /**
250
+ * The push token this device last offered, held until a connection exists and
251
+ * re-sent on every connect. Cleared by `unregisterPushToken`.
252
+ */
253
+ this.pendingPushRegistration = null;
249
254
  this.rateLimited = false;
250
255
  this.reconnectAttempt = 0;
251
256
  // Monotonic id for each connect attempt. Transport callbacks (onOpen/onError/
@@ -650,18 +655,36 @@ class MessagingClient {
650
655
  * stored token and refreshes its lastSeenAt timestamp.
651
656
  */
652
657
  async registerPushToken(opts) {
653
- if (!this.transport?.isOpen()) {
654
- throw new Error('DropOnAir websocket is not connected');
655
- }
656
658
  if (!opts.token || opts.token.trim().length === 0) {
657
659
  throw new Error('Push token must not be empty');
658
660
  }
659
- const deviceId = this.deviceId ?? await this.getOrCreateDeviceId();
660
- const frame = {
661
- type: 'PUSH_REGISTER',
661
+ // The push service hands an app its token at startup, usually before a
662
+ // connection exists, so refusing the registration here would lose it exactly
663
+ // when every app first offers it. Hold it instead and send it on connect, and
664
+ // keep holding it: the relay ties a token to a session, so a reconnect or a
665
+ // relay restart has to re-register or the device goes quiet.
666
+ this.pendingPushRegistration = {
662
667
  platform: opts.platform,
663
668
  token: opts.token,
664
669
  voipToken: opts.voipToken ?? '',
670
+ };
671
+ if (!this.transport?.isOpen()) {
672
+ return;
673
+ }
674
+ await this.sendPushRegistration();
675
+ }
676
+ /** Registers the held token, if there is one. Called on every connect. */
677
+ async sendPushRegistration() {
678
+ const pending = this.pendingPushRegistration;
679
+ if (!pending || !this.transport?.isOpen()) {
680
+ return;
681
+ }
682
+ const deviceId = this.deviceId ?? await this.getOrCreateDeviceId();
683
+ const frame = {
684
+ type: 'PUSH_REGISTER',
685
+ platform: pending.platform,
686
+ token: pending.token,
687
+ voipToken: pending.voipToken,
665
688
  deviceId,
666
689
  };
667
690
  this.transport.send(this.codec.encodePushRegistrationFrame(frame));
@@ -671,6 +694,7 @@ class MessagingClient {
671
694
  * push fan-out for this (appId, userId, deviceId, platform) tuple is dropped.
672
695
  */
673
696
  async unregisterPushToken(opts) {
697
+ this.pendingPushRegistration = null;
674
698
  if (!this.transport?.isOpen()) {
675
699
  throw new Error('DropOnAir websocket is not connected');
676
700
  }
@@ -1779,6 +1803,9 @@ class MessagingClient {
1779
1803
  if (this.dropOnAirJwt) {
1780
1804
  this.scheduleProactiveTokenRefresh(this.dropOnAirJwt);
1781
1805
  }
1806
+ this.sendPushRegistration().catch((err) => {
1807
+ this.logError('push_registration_failed', { error: String(err) });
1808
+ });
1782
1809
  this.fetchAndProcessOfflineGroupMessages().catch((err) => {
1783
1810
  this.logError('group_offline_fetch_failed', { error: String(err) });
1784
1811
  });
package/dist/version.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * MINOR, additive feature (e.g. multi-device payloads, new call event type)
8
8
  * PATCH, bug-fix / perf improvement with no wire or API change
9
9
  */
10
- export declare const SDK_VERSION = "0.27.0";
10
+ export declare const SDK_VERSION = "0.28.0";
11
11
  /**
12
12
  * Binary encrypted-payload format version.
13
13
  * Included as the first byte of every encrypted payload so receivers can
package/dist/version.js CHANGED
@@ -10,7 +10,7 @@ exports.PROTOCOL_VERSION = exports.PAYLOAD_FORMAT_VERSION = exports.SDK_VERSION
10
10
  * MINOR, additive feature (e.g. multi-device payloads, new call event type)
11
11
  * PATCH, bug-fix / perf improvement with no wire or API change
12
12
  */
13
- exports.SDK_VERSION = '0.27.0';
13
+ exports.SDK_VERSION = '0.28.0';
14
14
  /**
15
15
  * Binary encrypted-payload format version.
16
16
  * Included as the first byte of every encrypted payload so receivers can
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@droponair/sdk-js",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "description": "End-to-end encrypted messaging, voice and video calling SDK. The relay never sees your keys or message content.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",