Skip to content

Commit ef1e00b

Browse files
Merge pull request #146 from appwrite/dev
feat: Web SDK update for version 21.3.0
2 parents 1181a97 + 3e15fb5 commit ef1e00b

File tree

6 files changed

+466
-8
lines changed

6 files changed

+466
-8
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Change Log
22

3+
## 21.3.0
4+
5+
* Add new `Realtime` service with methods for subscribing to channels and receiving messages
6+
* Fix `client.setSession` not working when using realtime
7+
* Deprecate `client.subscribe` method in favor of `Realtime` service
8+
9+
> Note: Deprecated methods are still available for backwards compatibility, but might be removed in future versions.
10+
311
## 21.2.1
412

513
* Add transaction support for Databases and TablesDB

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { Client, Account } from "appwrite";
3333
To install with a CDN (content delivery network) add the following scripts to the bottom of your <body> tag, but before you use any Appwrite services:
3434

3535
```html
36-
<script src="https://cdn.jsdelivr.net/npm/appwrite@21.2.1"></script>
36+
<script src="https://cdn.jsdelivr.net/npm/appwrite@21.3.0"></script>
3737
```
3838

3939

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "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": "21.2.1",
5+
"version": "21.3.0",
66
"license": "BSD-3-Clause",
77
"main": "dist/cjs/sdk.js",
88
"exports": {

src/client.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,11 @@ class Client {
300300
/**
301301
* Holds configuration such as project.
302302
*/
303-
config = {
303+
config: {
304+
endpoint: string;
305+
endpointRealtime: string;
306+
[key: string]: string | undefined;
307+
} = {
304308
endpoint: 'https://cloud.appwrite.io/v1',
305309
endpointRealtime: '',
306310
project: '',
@@ -316,7 +320,7 @@ class Client {
316320
'x-sdk-name': 'Web',
317321
'x-sdk-platform': 'client',
318322
'x-sdk-language': 'web',
319-
'x-sdk-version': '21.2.1',
323+
'x-sdk-version': '21.3.0',
320324
'X-Appwrite-Response-Format': '1.8.0',
321325
};
322326

@@ -473,7 +477,9 @@ class Client {
473477
}
474478

475479
const channels = new URLSearchParams();
476-
channels.set('project', this.config.project);
480+
if (this.config.project) {
481+
channels.set('project', this.config.project);
482+
}
477483
this.realtime.channels.forEach(channel => {
478484
channels.append('channels[]', channel);
479485
});
@@ -528,10 +534,13 @@ class Client {
528534
this.realtime.lastMessage = message;
529535
switch (message.type) {
530536
case 'connected':
531-
const cookie = JSON.parse(window.localStorage.getItem('cookieFallback') ?? '{}');
532-
const session = cookie?.[`a_session_${this.config.project}`];
533-
const messageData = <RealtimeResponseConnected>message.data;
537+
let session = this.config.session;
538+
if (!session) {
539+
const cookie = JSON.parse(window.localStorage.getItem('cookieFallback') ?? '{}');
540+
session = cookie?.[`a_session_${this.config.project}`];
541+
}
534542

543+
const messageData = <RealtimeResponseConnected>message.data;
535544
if (session && !messageData.user) {
536545
this.realtime.socket?.send(JSON.stringify(<RealtimeRequest>{
537546
type: 'authentication',
@@ -582,6 +591,9 @@ class Client {
582591
/**
583592
* Subscribes to Appwrite events and passes you the payload in realtime.
584593
*
594+
* @deprecated Use the Realtime service instead.
595+
* @see Realtime
596+
*
585597
* @param {string|string[]} channels
586598
* Channel to subscribe - pass a single channel as a string or multiple with an array of strings.
587599
*

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export { Messaging } from './services/messaging';
1616
export { Storage } from './services/storage';
1717
export { TablesDB } from './services/tables-db';
1818
export { Teams } from './services/teams';
19+
export { Realtime } from './services/realtime';
1920
export type { Models, Payload, RealtimeResponseEvent, UploadProgress } from './client';
2021
export type { QueryTypes, QueryTypesList } from './query';
2122
export { Permission } from './permission';

0 commit comments

Comments
 (0)