Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## 21.3.0

* Add new `Realtime` service with methods for subscribing to channels and receiving messages
* Fix `client.setSession` not working when using realtime
* Deprecate `client.subscribe` method in favor of `Realtime` service

> Note: Deprecated methods are still available for backwards compatibility, but might be removed in future versions.

## 21.2.1

* Add transaction support for Databases and TablesDB
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { Client, Account } from "appwrite";
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:

```html
<script src="https://cdn.jsdelivr.net/npm/appwrite@21.2.1"></script>
<script src="https://cdn.jsdelivr.net/npm/appwrite@21.3.0"></script>
```


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "appwrite",
"homepage": "https://appwrite.io/support",
"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",
"version": "21.2.1",
"version": "21.3.0",
"license": "BSD-3-Clause",
"main": "dist/cjs/sdk.js",
"exports": {
Expand Down
24 changes: 18 additions & 6 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ class Client {
/**
* Holds configuration such as project.
*/
config = {
config: {
endpoint: string;
endpointRealtime: string;
[key: string]: string | undefined;
} = {
endpoint: 'https://cloud.appwrite.io/v1',
endpointRealtime: '',
project: '',
Expand All @@ -316,7 +320,7 @@ class Client {
'x-sdk-name': 'Web',
'x-sdk-platform': 'client',
'x-sdk-language': 'web',
'x-sdk-version': '21.2.1',
'x-sdk-version': '21.3.0',
'X-Appwrite-Response-Format': '1.8.0',
};

Expand Down Expand Up @@ -473,7 +477,9 @@ class Client {
}

const channels = new URLSearchParams();
channels.set('project', this.config.project);
if (this.config.project) {
channels.set('project', this.config.project);
}
this.realtime.channels.forEach(channel => {
channels.append('channels[]', channel);
});
Expand Down Expand Up @@ -528,10 +534,13 @@ class Client {
this.realtime.lastMessage = message;
switch (message.type) {
case 'connected':
const cookie = JSON.parse(window.localStorage.getItem('cookieFallback') ?? '{}');
const session = cookie?.[`a_session_${this.config.project}`];
const messageData = <RealtimeResponseConnected>message.data;
let session = this.config.session;
if (!session) {
const cookie = JSON.parse(window.localStorage.getItem('cookieFallback') ?? '{}');
session = cookie?.[`a_session_${this.config.project}`];
}

const messageData = <RealtimeResponseConnected>message.data;
if (session && !messageData.user) {
this.realtime.socket?.send(JSON.stringify(<RealtimeRequest>{
type: 'authentication',
Expand Down Expand Up @@ -582,6 +591,9 @@ class Client {
/**
* Subscribes to Appwrite events and passes you the payload in realtime.
*
* @deprecated Use the Realtime service instead.
* @see Realtime
*
* @param {string|string[]} channels
* Channel to subscribe - pass a single channel as a string or multiple with an array of strings.
*
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { Messaging } from './services/messaging';
export { Storage } from './services/storage';
export { TablesDB } from './services/tables-db';
export { Teams } from './services/teams';
export { Realtime } from './services/realtime';
export type { Models, Payload, RealtimeResponseEvent, UploadProgress } from './client';
export type { QueryTypes, QueryTypesList } from './query';
export { Permission } from './permission';
Expand Down
Loading