Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/react-declarative/appwrite-webhook-restreamer
Appwrite Server SDK does not support realtime through WebSocket. Due to the limitations of automatic SDK generator, looks like It would not ever support It. I am solved that problem by using SockJS
https://github.com/react-declarative/appwrite-webhook-restreamer
appwrite realtime restream sockjs webhook
Last synced: 3 months ago
JSON representation
Appwrite Server SDK does not support realtime through WebSocket. Due to the limitations of automatic SDK generator, looks like It would not ever support It. I am solved that problem by using SockJS
- Host: GitHub
- URL: https://github.com/react-declarative/appwrite-webhook-restreamer
- Owner: react-declarative
- License: mit
- Created: 2024-07-07T13:19:00.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-07-07T17:11:59.000Z (6 months ago)
- Last Synced: 2024-09-26T06:41:19.547Z (3 months ago)
- Topics: appwrite, realtime, restream, sockjs, webhook
- Language: JavaScript
- Homepage: https://github.com/react-declarative/react-declarative
- Size: 102 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# appwrite-webhook-restreamer
> Appwrite Server SDK does not support realtime through WebSocket. Due to the limitations of automatic SDK generator, [looks like It would not ever support It](https://appwrite.io/threads/1180136902481952838). I am solved that problem by using [SockJS](https://github.com/sockjs/sockjs-client)
## Contribute
> [!IMPORTANT]
> There is another project named [react-declarative](https://github.com/react-declarative/react-declarative) build especially for AppWrite Realtime development. **⭐Star** and **💻Fork** It on github will be appreciated# Setup
1. Start this microservice by using the next command
```bash
npx -y appwrite-webhook-restreamer
```or
```bash
npm install -g appwrite-webhook-restreamer
appwrite-webhook-restreamer
```2. Setup [webhook](https://appwrite.io/docs/advanced/platform/webhooks) in the Appwrite instance settings. Use the next POST URL: `http://127.0.0.1:9999/emit`
![appwrite-webhook-settings](./assets/appwrite-webhook-settings.png)
3. Listen for events by using [any SockJS Client](https://github.com/sypbiz/SockJS.NET) with the next url: `http://127.0.0.1:9999/listen`. The following code might be useful
```tsx
import Socket from "sockjs-client";import { Subject, singleshot } from "react-declarative";
...
export class RealtimeService {
private readonly _sockjsSubject = new Subject();
private _init = singleshot(() => {
new Socket("http://127.0.0.1:9999/listen").onmessage = (msg) => {
const chunk = JSON.parse(msg.data);
const data = {
payload: chunk.payload,
channels: [],
events: chunk.events.split(","),
timestamp: chusnk.timestamp,
};
this._sockjsSubject.next(data);
};
});subscribe = (
channel: string,
callback: (payload: RealtimeResponseEvent) => void,
) => {
this._init();
return this._sockjsSubject.subscribe((payload) => {
if (payload.events.some((event: string) => event.includes(channel))) {
callback(payload);
}
});
};
}
```# CLI
The first command line argument is always a port. The second is the `disallowWs` flag (optional)
```bash
appwrite-webhook-restream 9999 [--disallowWs]
```