@gwakko/shared-websocket 0.1.0
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/LICENSE +9 -0
- package/README.md +381 -0
- package/dist/MessageBus.d.ts +20 -0
- package/dist/SharedSocket.d.ts +37 -0
- package/dist/SharedWebSocket.d.ts +45 -0
- package/dist/SubscriptionManager.d.ts +14 -0
- package/dist/TabCoordinator.d.ts +36 -0
- package/dist/WorkerSocket.d.ts +42 -0
- package/dist/adapters/index.d.ts +0 -0
- package/dist/adapters/react.d.ts +79 -0
- package/dist/adapters/vue.d.ts +53 -0
- package/dist/chunk-SMH3X34N.cjs +737 -0
- package/dist/chunk-SMH3X34N.cjs.map +1 -0
- package/dist/chunk-TNEMKPGP.js +737 -0
- package/dist/chunk-TNEMKPGP.js.map +1 -0
- package/dist/index.cjs +46 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +100 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.js +100 -0
- package/dist/react.js.map +1 -0
- package/dist/types.d.ts +27 -0
- package/dist/utils/backoff.d.ts +2 -0
- package/dist/utils/disposable.d.ts +0 -0
- package/dist/utils/id.d.ts +1 -0
- package/dist/vue.cjs +93 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.js +93 -0
- package/dist/vue.js.map +1 -0
- package/dist/withSocket.d.ts +51 -0
- package/dist/worker/socket.worker.d.ts +51 -0
- package/package.json +74 -0
- package/src/MessageBus.ts +112 -0
- package/src/SharedSocket.ts +183 -0
- package/src/SharedWebSocket.ts +225 -0
- package/src/SubscriptionManager.ts +86 -0
- package/src/TabCoordinator.ts +162 -0
- package/src/WorkerSocket.ts +149 -0
- package/src/adapters/index.ts +3 -0
- package/src/adapters/react.ts +189 -0
- package/src/adapters/vue.ts +149 -0
- package/src/index.ts +8 -0
- package/src/types.ts +29 -0
- package/src/utils/backoff.ts +9 -0
- package/src/utils/disposable.ts +4 -0
- package/src/utils/id.ts +6 -0
- package/src/withSocket.ts +89 -0
- package/src/worker/socket.worker.ts +205 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type Ref, type InjectionKey, type App } from 'vue';
|
|
2
|
+
import { SharedWebSocket } from '../SharedWebSocket';
|
|
3
|
+
import type { SharedWebSocketOptions, TabRole } from '../types';
|
|
4
|
+
export declare const SharedWebSocketKey: InjectionKey<SharedWebSocket>;
|
|
5
|
+
/**
|
|
6
|
+
* Vue 3 plugin for SharedWebSocket.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const app = createApp(App);
|
|
10
|
+
* app.use(createSharedWebSocketPlugin('wss://api.example.com/ws'));
|
|
11
|
+
*/
|
|
12
|
+
export declare function createSharedWebSocketPlugin(url: string, options?: SharedWebSocketOptions): {
|
|
13
|
+
install(app: App): void;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Access the SharedWebSocket instance from provided context.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const ws = useSharedWebSocket();
|
|
20
|
+
*/
|
|
21
|
+
export declare function useSharedWebSocket(): SharedWebSocket;
|
|
22
|
+
/**
|
|
23
|
+
* Subscribe to a WebSocket event. Returns reactive ref with latest value.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const order = useSocketEvent<Order>('order.created');
|
|
27
|
+
*/
|
|
28
|
+
export declare function useSocketEvent<T>(event: string): Ref<T | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Accumulate WebSocket events into reactive array.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const messages = useSocketStream<ChatMessage>('chat.message');
|
|
34
|
+
*/
|
|
35
|
+
export declare function useSocketStream<T>(event: string): Ref<T[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Two-way state sync across browser tabs via reactive ref.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const cart = useSocketSync<Cart>('cart', { items: [] });
|
|
41
|
+
* cart.value = { items: [1, 2, 3] }; // syncs to all tabs
|
|
42
|
+
*/
|
|
43
|
+
export declare function useSocketSync<T>(key: string, initialValue: T): Ref<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Reactive connection status.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const { connected, tabRole } = useSocketStatus();
|
|
49
|
+
*/
|
|
50
|
+
export declare function useSocketStatus(): {
|
|
51
|
+
connected: Ref<boolean>;
|
|
52
|
+
tabRole: Ref<TabRole>;
|
|
53
|
+
};
|