Skip to content

Commit 0fa902a

Browse files
Merge pull request #93 from appwrite/dev
fix: close realtime sockets
2 parents e907a87 + 6cf9e0b commit 0fa902a

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ node_js:
55
jobs:
66
include:
77
- stage: NPM RC Release
8-
if: tag == *-rc*
8+
if: tag =~ /-(rc|RC)/
99
node_js: "14.16"
1010
script:
1111
- npm install
@@ -17,7 +17,7 @@ jobs:
1717
api_key: $NPM_API_KEY
1818
tag: next
1919
- stage: NPM Release
20-
if: tag != *-rc*
20+
if: not tag =~ /-(rc|RC)/
2121
node_js: "14.16"
2222
script:
2323
- npm install

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/[email protected].0"></script>
36+
<script src="https://cdn.jsdelivr.net/npm/[email protected].1"></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": "14.0.0",
5+
"version": "14.0.1",
66
"license": "BSD-3-Clause",
77
"main": "dist/cjs/sdk.js",
88
"exports": {

src/client.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class Client {
103103
'x-sdk-name': 'Web',
104104
'x-sdk-platform': 'client',
105105
'x-sdk-language': 'web',
106-
'x-sdk-version': '14.0.0',
106+
'x-sdk-version': '14.0.1',
107107
'X-Appwrite-Response-Format': '1.5.0',
108108
};
109109

@@ -224,7 +224,11 @@ class Client {
224224
}
225225
},
226226
createSocket: () => {
227-
if (this.realtime.channels.size < 1) return;
227+
if (this.realtime.channels.size < 1) {
228+
this.realtime.reconnect = false;
229+
this.realtime.socket?.close();
230+
return;
231+
}
228232

229233
const channels = new URLSearchParams();
230234
channels.set('project', this.config.project);

src/id.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
export class ID {
2+
// Generate an hex ID based on timestamp
3+
// Recreated from https://www.php.net/manual/en/function.uniqid.php
4+
static #hexTimestamp(): string {
5+
const now = new Date();
6+
const sec = Math.floor(now.getTime() / 1000);
7+
const msec = now.getMilliseconds();
8+
9+
// Convert to hexadecimal
10+
const hexTimestamp = sec.toString(16) + msec.toString(16).padStart(5, '0');
11+
return hexTimestamp;
12+
}
13+
214
public static custom(id: string): string {
315
return id
416
}
5-
6-
public static unique(): string {
7-
return 'unique()'
17+
18+
public static unique(padding: number = 7): string {
19+
// Generate a unique ID with padding to have a longer ID
20+
const baseId = ID.#hexTimestamp();
21+
let randomPadding = '';
22+
for (let i = 0; i < padding; i++) {
23+
const randomHexDigit = Math.floor(Math.random() * 16).toString(16);
24+
randomPadding += randomHexDigit;
25+
}
26+
return baseId + randomPadding;
827
}
9-
}
28+
}

0 commit comments

Comments
 (0)