@flightdev/realtime 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -13
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @flightdev/realtime
|
|
2
2
|
|
|
3
3
|
Real-time communication for Flight Framework. Unified API for WebSocket and Server-Sent Events (SSE).
|
|
4
4
|
|
|
@@ -34,7 +34,7 @@ Real-time communication for Flight Framework. Unified API for WebSocket and Serv
|
|
|
34
34
|
## Installation
|
|
35
35
|
|
|
36
36
|
```bash
|
|
37
|
-
npm install @
|
|
37
|
+
npm install @flightdev/realtime
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
---
|
|
@@ -44,8 +44,8 @@ npm install @flight-framework/realtime
|
|
|
44
44
|
### Client
|
|
45
45
|
|
|
46
46
|
```typescript
|
|
47
|
-
import { createRealtime } from '@
|
|
48
|
-
import { websocket } from '@
|
|
47
|
+
import { createRealtime } from '@flightdev/realtime';
|
|
48
|
+
import { websocket } from '@flightdev/realtime/websocket';
|
|
49
49
|
|
|
50
50
|
const realtime = createRealtime(websocket({
|
|
51
51
|
url: 'wss://api.example.com/ws',
|
|
@@ -68,7 +68,7 @@ chat.send('message', { text: 'Hello everyone!' });
|
|
|
68
68
|
### Server
|
|
69
69
|
|
|
70
70
|
```typescript
|
|
71
|
-
import { createServer } from '@
|
|
71
|
+
import { createServer } from '@flightdev/realtime/server';
|
|
72
72
|
|
|
73
73
|
const server = createServer({ port: 3001 });
|
|
74
74
|
|
|
@@ -91,7 +91,7 @@ server.on('connection', (socket) => {
|
|
|
91
91
|
Bidirectional communication for real-time apps.
|
|
92
92
|
|
|
93
93
|
```typescript
|
|
94
|
-
import { websocket } from '@
|
|
94
|
+
import { websocket } from '@flightdev/realtime/websocket';
|
|
95
95
|
|
|
96
96
|
const adapter = websocket({
|
|
97
97
|
url: 'wss://api.example.com/ws',
|
|
@@ -108,7 +108,7 @@ const adapter = websocket({
|
|
|
108
108
|
One-way server-to-client, edge-compatible.
|
|
109
109
|
|
|
110
110
|
```typescript
|
|
111
|
-
import { sse } from '@
|
|
111
|
+
import { sse } from '@flightdev/realtime/sse';
|
|
112
112
|
|
|
113
113
|
const adapter = sse({
|
|
114
114
|
url: '/api/events',
|
|
@@ -202,7 +202,7 @@ channel.presence.leave();
|
|
|
202
202
|
### RealtimeProvider
|
|
203
203
|
|
|
204
204
|
```tsx
|
|
205
|
-
import { RealtimeProvider } from '@
|
|
205
|
+
import { RealtimeProvider } from '@flightdev/realtime/react';
|
|
206
206
|
|
|
207
207
|
function App() {
|
|
208
208
|
return (
|
|
@@ -216,7 +216,7 @@ function App() {
|
|
|
216
216
|
### useRealtime Hook
|
|
217
217
|
|
|
218
218
|
```tsx
|
|
219
|
-
import { useRealtime } from '@
|
|
219
|
+
import { useRealtime } from '@flightdev/realtime/react';
|
|
220
220
|
|
|
221
221
|
function ConnectionStatus() {
|
|
222
222
|
const { state, connect, disconnect } = useRealtime();
|
|
@@ -235,7 +235,7 @@ function ConnectionStatus() {
|
|
|
235
235
|
### useChannel Hook
|
|
236
236
|
|
|
237
237
|
```tsx
|
|
238
|
-
import { useChannel } from '@
|
|
238
|
+
import { useChannel } from '@flightdev/realtime/react';
|
|
239
239
|
|
|
240
240
|
function ChatRoom({ roomId }) {
|
|
241
241
|
const [messages, setMessages] = useState([]);
|
|
@@ -264,7 +264,7 @@ function ChatRoom({ roomId }) {
|
|
|
264
264
|
### usePresence Hook
|
|
265
265
|
|
|
266
266
|
```tsx
|
|
267
|
-
import { usePresence } from '@
|
|
267
|
+
import { usePresence } from '@flightdev/realtime/react';
|
|
268
268
|
|
|
269
269
|
function OnlineUsers({ roomId }) {
|
|
270
270
|
const { members, enter, leave } = usePresence(`room:${roomId}`);
|
|
@@ -292,7 +292,7 @@ function OnlineUsers({ roomId }) {
|
|
|
292
292
|
|
|
293
293
|
```vue
|
|
294
294
|
<script setup>
|
|
295
|
-
import { useRealtime, useChannel, usePresence } from '@
|
|
295
|
+
import { useRealtime, useChannel, usePresence } from '@flightdev/realtime/vue';
|
|
296
296
|
|
|
297
297
|
const { state } = useRealtime();
|
|
298
298
|
const { messages, send } = useChannel('chat:general');
|
|
@@ -326,7 +326,7 @@ const sendMessage = (text) => {
|
|
|
326
326
|
|
|
327
327
|
```typescript
|
|
328
328
|
// src/routes/api/events.get.ts
|
|
329
|
-
import { createSSEResponse } from '@
|
|
329
|
+
import { createSSEResponse } from '@flightdev/realtime/sse';
|
|
330
330
|
|
|
331
331
|
export async function GET(request: Request) {
|
|
332
332
|
const userId = getUserId(request);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flightdev/realtime",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Agnostic real-time communication for Flight Framework. Choose your transport: WebSocket, SSE, Pusher, or custom.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -56,6 +56,12 @@
|
|
|
56
56
|
"pubsub"
|
|
57
57
|
],
|
|
58
58
|
"license": "MIT",
|
|
59
|
+
"homepage": "https://github.com/EliosLT/FlightDev",
|
|
60
|
+
"repository": {
|
|
61
|
+
"url": "https://github.com/EliosLT/FlightDev.git",
|
|
62
|
+
"directory": "packages/realtime",
|
|
63
|
+
"type": "git"
|
|
64
|
+
},
|
|
59
65
|
"scripts": {
|
|
60
66
|
"build": "tsup",
|
|
61
67
|
"dev": "tsup --watch",
|