Skip to content

Commit

Permalink
fix: close realtime sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
loks0n committed Apr 17, 2024
1 parent 6dacbc2 commit 6cf9e0b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ node_js:
jobs:
include:
- stage: NPM RC Release
if: tag == *-rc*
if: tag =~ /-(rc|RC)/
node_js: "14.16"
script:
- npm install
Expand All @@ -17,7 +17,7 @@ jobs:
api_key: $NPM_API_KEY
tag: next
- stage: NPM Release
if: tag != *-rc*
if: not tag =~ /-(rc|RC)/
node_js: "14.16"
script:
- npm install
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@14.0.0"></script>
<script src="https://cdn.jsdelivr.net/npm/appwrite@14.0.1"></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": "14.0.0",
"version": "14.0.1",
"license": "BSD-3-Clause",
"main": "dist/cjs/sdk.js",
"exports": {
Expand Down
8 changes: 6 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Client {
'x-sdk-name': 'Web',
'x-sdk-platform': 'client',
'x-sdk-language': 'web',
'x-sdk-version': '14.0.0',
'x-sdk-version': '14.0.1',
'X-Appwrite-Response-Format': '1.5.0',
};

Expand Down Expand Up @@ -224,7 +224,11 @@ class Client {
}
},
createSocket: () => {
if (this.realtime.channels.size < 1) return;
if (this.realtime.channels.size < 1) {
this.realtime.reconnect = false;
this.realtime.socket?.close();
return;
}

const channels = new URLSearchParams();
channels.set('project', this.config.project);
Expand Down
27 changes: 23 additions & 4 deletions src/id.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
export class ID {
// Generate an hex ID based on timestamp
// Recreated from https://www.php.net/manual/en/function.uniqid.php
static #hexTimestamp(): string {
const now = new Date();
const sec = Math.floor(now.getTime() / 1000);
const msec = now.getMilliseconds();

// Convert to hexadecimal
const hexTimestamp = sec.toString(16) + msec.toString(16).padStart(5, '0');
return hexTimestamp;
}

public static custom(id: string): string {
return id
}

public static unique(): string {
return 'unique()'

public static unique(padding: number = 7): string {
// Generate a unique ID with padding to have a longer ID
const baseId = ID.#hexTimestamp();
let randomPadding = '';
for (let i = 0; i < padding; i++) {
const randomHexDigit = Math.floor(Math.random() * 16).toString(16);
randomPadding += randomHexDigit;
}
return baseId + randomPadding;
}
}
}

0 comments on commit 6cf9e0b

Please sign in to comment.