Skip to content

Commit 00fa346

Browse files
Merge pull request #38 from appwrite/dev
feat: realtime heartbeat
2 parents 18bd0ca + bd5bb16 commit 00fa346

File tree

8 files changed

+50
-19
lines changed

8 files changed

+50
-19
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-native-appwrite",
33
"homepage": "https://appwrite.io/support",
44
"description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
5-
"version": "0.5.0",
5+
"version": "0.6.0",
66
"license": "BSD-3-Clause",
77
"main": "dist/cjs/sdk.js",
88
"exports": {

src/client.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,17 @@ type RealtimeRequestAuthenticate = {
4949

5050
type Realtime = {
5151
socket?: WebSocket;
52+
53+
/**
54+
* Timeout for reconnect operations.
55+
*/
5256
timeout?: number;
57+
58+
/**
59+
* Heartbeat interval for the realtime connection.
60+
*/
61+
heartbeat?: number;
62+
5363
url?: string;
5464
lastMessage?: RealtimeResponse;
5565
channels: Set<string>;
@@ -63,6 +73,7 @@ type Realtime = {
6373
getTimeout: () => number;
6474
connect: () => void;
6575
createSocket: () => void;
76+
createHeartbeat: () => void;
6677
cleanUp: (channels: string[]) => void;
6778
onMessage: (event: MessageEvent) => void;
6879
}
@@ -103,7 +114,7 @@ class Client {
103114
'x-sdk-name': 'React Native',
104115
'x-sdk-platform': 'client',
105116
'x-sdk-language': 'reactnative',
106-
'x-sdk-version': '0.5.0',
117+
'x-sdk-version': '0.6.0',
107118
'X-Appwrite-Response-Format': '1.6.0',
108119
};
109120

@@ -212,6 +223,7 @@ class Client {
212223
private realtime: Realtime = {
213224
socket: undefined,
214225
timeout: undefined,
226+
heartbeat: undefined,
215227
url: '',
216228
channels: new Set(),
217229
subscriptions: new Map(),
@@ -237,6 +249,17 @@ class Client {
237249
return 60_000;
238250
}
239251
},
252+
createHeartbeat: () => {
253+
if (this.realtime.heartbeat) {
254+
clearTimeout(this.realtime.heartbeat);
255+
}
256+
257+
this.realtime.heartbeat = window?.setInterval(() => {
258+
this.realtime.socket?.send(JSON.stringify({
259+
type: 'ping'
260+
}));
261+
}, 20_000);
262+
},
240263
createSocket: () => {
241264
if (this.realtime.channels.size < 1) {
242265
this.realtime.reconnect = false;
@@ -275,6 +298,7 @@ class Client {
275298
this.realtime.socket.addEventListener('message', this.realtime.onMessage);
276299
this.realtime.socket.addEventListener('open', _event => {
277300
this.realtime.reconnectAttempts = 0;
301+
this.realtime.createHeartbeat();
278302
});
279303
this.realtime.socket.addEventListener('close', event => {
280304
if (

src/enums/image-format.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export enum ImageFormat {
44
Gif = 'gif',
55
Png = 'png',
66
Webp = 'webp',
7+
Avif = 'avif',
78
}

src/models.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -839,11 +839,11 @@ export namespace Models {
839839
*/
840840
userId: string;
841841
/**
842-
* User name.
842+
* User name. Hide this attribute by toggling membership privacy in the Console.
843843
*/
844844
userName: string;
845845
/**
846-
* User email address.
846+
* User email address. Hide this attribute by toggling membership privacy in the Console.
847847
*/
848848
userEmail: string;
849849
/**
@@ -867,7 +867,7 @@ export namespace Models {
867867
*/
868868
confirm: boolean;
869869
/**
870-
* Multi factor authentication status, true if the user has MFA enabled or false otherwise.
870+
* Multi factor authentication status, true if the user has MFA enabled or false otherwise. Hide this attribute by toggling membership privacy in the Console.
871871
*/
872872
mfa: boolean;
873873
/**
@@ -1195,5 +1195,9 @@ export namespace Models {
11951195
* The target identifier.
11961196
*/
11971197
identifier: string;
1198+
/**
1199+
* Is the target expired.
1200+
*/
1201+
expired: boolean;
11981202
}
11991203
}

src/services/account.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class Account extends Service {
134134
}
135135

136136
/**
137-
* List Identities
137+
* List identities
138138
*
139139
* Get the list of identities for the currently logged in user.
140140
*
@@ -253,7 +253,7 @@ export class Account extends Service {
253253
}
254254

255255
/**
256-
* Create Authenticator
256+
* Create authenticator
257257
*
258258
* Add an authenticator app to be used as an MFA factor. Verify the
259259
* authenticator using the [verify
@@ -279,7 +279,7 @@ export class Account extends Service {
279279
}
280280

281281
/**
282-
* Verify Authenticator
282+
* Verify authenticator
283283
*
284284
* Verify an authenticator app after adding it using the [add
285285
* authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator)
@@ -313,7 +313,7 @@ export class Account extends Service {
313313
}
314314

315315
/**
316-
* Delete Authenticator
316+
* Delete authenticator
317317
*
318318
* Delete an authenticator for a user by ID.
319319
*
@@ -336,7 +336,7 @@ export class Account extends Service {
336336
}
337337

338338
/**
339-
* Create MFA Challenge
339+
* Create MFA challenge
340340
*
341341
* Begin the process of MFA verification after sign-in. Finish the flow with
342342
* [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge)
@@ -365,7 +365,7 @@ export class Account extends Service {
365365
}
366366

367367
/**
368-
* Create MFA Challenge (confirmation)
368+
* Create MFA challenge (confirmation)
369369
*
370370
* Complete the MFA challenge by providing the one-time password. Finish the
371371
* process of MFA verification by providing the one-time password. To begin
@@ -405,7 +405,7 @@ export class Account extends Service {
405405
}
406406

407407
/**
408-
* List Factors
408+
* List factors
409409
*
410410
* List the factors available on the account to be used as a MFA challange.
411411
*
@@ -423,7 +423,7 @@ export class Account extends Service {
423423
}
424424

425425
/**
426-
* Get MFA Recovery Codes
426+
* Get MFA recovery codes
427427
*
428428
* Get recovery codes that can be used as backup for MFA flow. Before getting
429429
* codes, they must be generated using
@@ -444,7 +444,7 @@ export class Account extends Service {
444444
}
445445

446446
/**
447-
* Create MFA Recovery Codes
447+
* Create MFA recovery codes
448448
*
449449
* Generate recovery codes as backup for MFA flow. It's recommended to
450450
* generate and show then immediately after user successfully adds their
@@ -466,7 +466,7 @@ export class Account extends Service {
466466
}
467467

468468
/**
469-
* Regenerate MFA Recovery Codes
469+
* Regenerate MFA recovery codes
470470
*
471471
* Regenerate recovery codes that can be used as backup for MFA flow. Before
472472
* regenerating codes, they must be first generated using

src/services/locale.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class Locale extends Service {
3737
}
3838

3939
/**
40-
* List Locale Codes
40+
* List locale codes
4141
*
4242
* List of all locale codes in [ISO
4343
* 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).

src/services/storage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export class Storage extends Service {
237237
}
238238

239239
/**
240-
* Delete File
240+
* Delete file
241241
*
242242
* Delete a file by its unique ID. Only users with write permissions have
243243
* access to delete this resource.

src/services/teams.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ export class Teams extends Service {
168168
* List team memberships
169169
*
170170
* Use this endpoint to list a team's members using the team's ID. All team
171-
* members have read access to this endpoint.
171+
* members have read access to this endpoint. Hide sensitive attributes from
172+
* the response by toggling membership privacy in the Console.
172173
*
173174
* @param {string} teamId
174175
* @param {string[]} queries
@@ -279,7 +280,8 @@ export class Teams extends Service {
279280
* Get team membership
280281
*
281282
* Get a team member by the membership unique id. All team members have read
282-
* access for this resource.
283+
* access for this resource. Hide sensitive attributes from the response by
284+
* toggling membership privacy in the Console.
283285
*
284286
* @param {string} teamId
285287
* @param {string} membershipId

0 commit comments

Comments
 (0)