@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.
Files changed (51) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +381 -0
  3. package/dist/MessageBus.d.ts +20 -0
  4. package/dist/SharedSocket.d.ts +37 -0
  5. package/dist/SharedWebSocket.d.ts +45 -0
  6. package/dist/SubscriptionManager.d.ts +14 -0
  7. package/dist/TabCoordinator.d.ts +36 -0
  8. package/dist/WorkerSocket.d.ts +42 -0
  9. package/dist/adapters/index.d.ts +0 -0
  10. package/dist/adapters/react.d.ts +79 -0
  11. package/dist/adapters/vue.d.ts +53 -0
  12. package/dist/chunk-SMH3X34N.cjs +737 -0
  13. package/dist/chunk-SMH3X34N.cjs.map +1 -0
  14. package/dist/chunk-TNEMKPGP.js +737 -0
  15. package/dist/chunk-TNEMKPGP.js.map +1 -0
  16. package/dist/index.cjs +46 -0
  17. package/dist/index.cjs.map +1 -0
  18. package/dist/index.d.ts +8 -0
  19. package/dist/index.js +46 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/react.cjs +100 -0
  22. package/dist/react.cjs.map +1 -0
  23. package/dist/react.js +100 -0
  24. package/dist/react.js.map +1 -0
  25. package/dist/types.d.ts +27 -0
  26. package/dist/utils/backoff.d.ts +2 -0
  27. package/dist/utils/disposable.d.ts +0 -0
  28. package/dist/utils/id.d.ts +1 -0
  29. package/dist/vue.cjs +93 -0
  30. package/dist/vue.cjs.map +1 -0
  31. package/dist/vue.js +93 -0
  32. package/dist/vue.js.map +1 -0
  33. package/dist/withSocket.d.ts +51 -0
  34. package/dist/worker/socket.worker.d.ts +51 -0
  35. package/package.json +74 -0
  36. package/src/MessageBus.ts +112 -0
  37. package/src/SharedSocket.ts +183 -0
  38. package/src/SharedWebSocket.ts +225 -0
  39. package/src/SubscriptionManager.ts +86 -0
  40. package/src/TabCoordinator.ts +162 -0
  41. package/src/WorkerSocket.ts +149 -0
  42. package/src/adapters/index.ts +3 -0
  43. package/src/adapters/react.ts +189 -0
  44. package/src/adapters/vue.ts +149 -0
  45. package/src/index.ts +8 -0
  46. package/src/types.ts +29 -0
  47. package/src/utils/backoff.ts +9 -0
  48. package/src/utils/disposable.ts +4 -0
  49. package/src/utils/id.ts +6 -0
  50. package/src/withSocket.ts +89 -0
  51. 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
+ };