wirejs-resources 0.1.75-realtime → 0.1.77-realtime

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.
@@ -55,6 +55,18 @@ async function callApi(INTERNAL_API_URL, method, ...args) {
55
55
  if (typeof value === 'object' && value.__wjstype === 'realtime') {
56
56
  const subscribers = [];
57
57
  const ws = new WebSocket(value.url, value.protocol);
58
+ ws.onopen = () => {
59
+ for (const subscriber of subscribers) {
60
+ if (subscriber.onopen) {
61
+ try {
62
+ subscriber.onopen();
63
+ }
64
+ catch (error) {
65
+ console.error('Error in subscriber onopen:', error);
66
+ }
67
+ }
68
+ }
69
+ };
58
70
  ws.onmessage = (event) => {
59
71
  const data = JSON.parse(event.data);
60
72
  if (data.data) {
@@ -3,10 +3,12 @@ export type MessageStream<T = any> = {
3
3
  /**
4
4
  * Returns a function to close the subscription.
5
5
  */
6
- subscribe(subscriber: {
7
- onmessage: (data: T) => void;
8
- onclose?: () => void;
9
- }): () => void;
6
+ subscribe(subscriber: MessageStreamSubscriber<T>): () => void;
7
+ };
8
+ export type MessageStreamSubscriber<T = any> = {
9
+ onopen?: () => void;
10
+ onmessage: (data: T) => void;
11
+ onclose?: () => void;
10
12
  };
11
13
  export declare class RealtimeService<T = any> extends Resource {
12
14
  #private;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirejs-resources",
3
- "version": "0.1.75-realtime",
3
+ "version": "0.1.77-realtime",
4
4
  "description": "Basic services and server-side resources for wirejs apps",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",