@blinkdotnew/sdk 0.10.5 → 0.10.6
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/dist/index.d.mts +738 -3
- package/dist/index.d.ts +738 -3
- package/dist/index.js +37 -14
- package/dist/index.mjs +37 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2531,6 +2531,7 @@ var BlinkRealtimeChannel = class {
|
|
|
2531
2531
|
this.startHeartbeat();
|
|
2532
2532
|
}
|
|
2533
2533
|
} catch (error) {
|
|
2534
|
+
console.error("WebSocket subscription error:", error);
|
|
2534
2535
|
throw new BlinkRealtimeError(
|
|
2535
2536
|
`Failed to subscribe to channel ${this.channelName}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2536
2537
|
);
|
|
@@ -2552,20 +2553,39 @@ var BlinkRealtimeChannel = class {
|
|
|
2552
2553
|
this.cleanup();
|
|
2553
2554
|
}
|
|
2554
2555
|
async publish(type, data, options = {}) {
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
channel: this.channelName,
|
|
2558
|
-
type,
|
|
2559
|
-
data,
|
|
2560
|
-
userId: options.userId,
|
|
2561
|
-
metadata: options.metadata
|
|
2562
|
-
});
|
|
2563
|
-
return response.data.messageId;
|
|
2564
|
-
} catch (error) {
|
|
2565
|
-
throw new BlinkRealtimeError(
|
|
2566
|
-
`Failed to publish message to channel ${this.channelName}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2567
|
-
);
|
|
2556
|
+
if (!this.websocket || this.websocket.readyState !== 1) {
|
|
2557
|
+
throw new BlinkRealtimeError("Not connected to realtime channel. Call subscribe() first.");
|
|
2568
2558
|
}
|
|
2559
|
+
return new Promise((resolve, reject) => {
|
|
2560
|
+
const timeout = setTimeout(() => {
|
|
2561
|
+
reject(new BlinkRealtimeError("Publish timeout - no response from server"));
|
|
2562
|
+
}, 5e3);
|
|
2563
|
+
const handleResponse = (event) => {
|
|
2564
|
+
try {
|
|
2565
|
+
const message = JSON.parse(event.data);
|
|
2566
|
+
if (message.type === "published" && message.payload.channel === this.channelName) {
|
|
2567
|
+
clearTimeout(timeout);
|
|
2568
|
+
resolve(message.payload.messageId);
|
|
2569
|
+
} else if (message.type === "error") {
|
|
2570
|
+
clearTimeout(timeout);
|
|
2571
|
+
reject(new BlinkRealtimeError(`Server error: ${message.payload.error}`));
|
|
2572
|
+
}
|
|
2573
|
+
} catch (err) {
|
|
2574
|
+
}
|
|
2575
|
+
};
|
|
2576
|
+
this.websocket.addEventListener("message", handleResponse, { once: true });
|
|
2577
|
+
const publishMessage = {
|
|
2578
|
+
type: "publish",
|
|
2579
|
+
payload: {
|
|
2580
|
+
channel: this.channelName,
|
|
2581
|
+
type,
|
|
2582
|
+
data,
|
|
2583
|
+
userId: options.userId,
|
|
2584
|
+
metadata: options.metadata
|
|
2585
|
+
}
|
|
2586
|
+
};
|
|
2587
|
+
this.websocket.send(JSON.stringify(publishMessage));
|
|
2588
|
+
});
|
|
2569
2589
|
}
|
|
2570
2590
|
onMessage(callback) {
|
|
2571
2591
|
this.messageCallbacks.push(callback);
|
|
@@ -2622,6 +2642,7 @@ var BlinkRealtimeChannel = class {
|
|
|
2622
2642
|
const coreUrl = httpClient.coreUrl || "https://core.blink.new";
|
|
2623
2643
|
const baseUrl = coreUrl.replace("https://", "wss://").replace("http://", "ws://");
|
|
2624
2644
|
const wsUrl = `${baseUrl}?project_id=${this.projectId}`;
|
|
2645
|
+
console.log(`\u{1F517} Attempting WebSocket connection to: ${wsUrl}`);
|
|
2625
2646
|
const WSClass = getWebSocketClass();
|
|
2626
2647
|
this.websocket = new WSClass(wsUrl);
|
|
2627
2648
|
if (!this.websocket) {
|
|
@@ -2648,7 +2669,9 @@ var BlinkRealtimeChannel = class {
|
|
|
2648
2669
|
};
|
|
2649
2670
|
this.websocket.onerror = (error) => {
|
|
2650
2671
|
console.error("WebSocket error:", error);
|
|
2651
|
-
|
|
2672
|
+
console.error("WebSocket URL was:", wsUrl);
|
|
2673
|
+
console.error("WebSocket readyState:", this.websocket?.readyState);
|
|
2674
|
+
reject(new BlinkRealtimeError(`WebSocket connection failed to ${wsUrl}`));
|
|
2652
2675
|
};
|
|
2653
2676
|
setTimeout(() => {
|
|
2654
2677
|
if (this.websocket?.readyState !== 1) {
|
package/dist/index.mjs
CHANGED
|
@@ -2529,6 +2529,7 @@ var BlinkRealtimeChannel = class {
|
|
|
2529
2529
|
this.startHeartbeat();
|
|
2530
2530
|
}
|
|
2531
2531
|
} catch (error) {
|
|
2532
|
+
console.error("WebSocket subscription error:", error);
|
|
2532
2533
|
throw new BlinkRealtimeError(
|
|
2533
2534
|
`Failed to subscribe to channel ${this.channelName}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2534
2535
|
);
|
|
@@ -2550,20 +2551,39 @@ var BlinkRealtimeChannel = class {
|
|
|
2550
2551
|
this.cleanup();
|
|
2551
2552
|
}
|
|
2552
2553
|
async publish(type, data, options = {}) {
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
channel: this.channelName,
|
|
2556
|
-
type,
|
|
2557
|
-
data,
|
|
2558
|
-
userId: options.userId,
|
|
2559
|
-
metadata: options.metadata
|
|
2560
|
-
});
|
|
2561
|
-
return response.data.messageId;
|
|
2562
|
-
} catch (error) {
|
|
2563
|
-
throw new BlinkRealtimeError(
|
|
2564
|
-
`Failed to publish message to channel ${this.channelName}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2565
|
-
);
|
|
2554
|
+
if (!this.websocket || this.websocket.readyState !== 1) {
|
|
2555
|
+
throw new BlinkRealtimeError("Not connected to realtime channel. Call subscribe() first.");
|
|
2566
2556
|
}
|
|
2557
|
+
return new Promise((resolve, reject) => {
|
|
2558
|
+
const timeout = setTimeout(() => {
|
|
2559
|
+
reject(new BlinkRealtimeError("Publish timeout - no response from server"));
|
|
2560
|
+
}, 5e3);
|
|
2561
|
+
const handleResponse = (event) => {
|
|
2562
|
+
try {
|
|
2563
|
+
const message = JSON.parse(event.data);
|
|
2564
|
+
if (message.type === "published" && message.payload.channel === this.channelName) {
|
|
2565
|
+
clearTimeout(timeout);
|
|
2566
|
+
resolve(message.payload.messageId);
|
|
2567
|
+
} else if (message.type === "error") {
|
|
2568
|
+
clearTimeout(timeout);
|
|
2569
|
+
reject(new BlinkRealtimeError(`Server error: ${message.payload.error}`));
|
|
2570
|
+
}
|
|
2571
|
+
} catch (err) {
|
|
2572
|
+
}
|
|
2573
|
+
};
|
|
2574
|
+
this.websocket.addEventListener("message", handleResponse, { once: true });
|
|
2575
|
+
const publishMessage = {
|
|
2576
|
+
type: "publish",
|
|
2577
|
+
payload: {
|
|
2578
|
+
channel: this.channelName,
|
|
2579
|
+
type,
|
|
2580
|
+
data,
|
|
2581
|
+
userId: options.userId,
|
|
2582
|
+
metadata: options.metadata
|
|
2583
|
+
}
|
|
2584
|
+
};
|
|
2585
|
+
this.websocket.send(JSON.stringify(publishMessage));
|
|
2586
|
+
});
|
|
2567
2587
|
}
|
|
2568
2588
|
onMessage(callback) {
|
|
2569
2589
|
this.messageCallbacks.push(callback);
|
|
@@ -2620,6 +2640,7 @@ var BlinkRealtimeChannel = class {
|
|
|
2620
2640
|
const coreUrl = httpClient.coreUrl || "https://core.blink.new";
|
|
2621
2641
|
const baseUrl = coreUrl.replace("https://", "wss://").replace("http://", "ws://");
|
|
2622
2642
|
const wsUrl = `${baseUrl}?project_id=${this.projectId}`;
|
|
2643
|
+
console.log(`\u{1F517} Attempting WebSocket connection to: ${wsUrl}`);
|
|
2623
2644
|
const WSClass = getWebSocketClass();
|
|
2624
2645
|
this.websocket = new WSClass(wsUrl);
|
|
2625
2646
|
if (!this.websocket) {
|
|
@@ -2646,7 +2667,9 @@ var BlinkRealtimeChannel = class {
|
|
|
2646
2667
|
};
|
|
2647
2668
|
this.websocket.onerror = (error) => {
|
|
2648
2669
|
console.error("WebSocket error:", error);
|
|
2649
|
-
|
|
2670
|
+
console.error("WebSocket URL was:", wsUrl);
|
|
2671
|
+
console.error("WebSocket readyState:", this.websocket?.readyState);
|
|
2672
|
+
reject(new BlinkRealtimeError(`WebSocket connection failed to ${wsUrl}`));
|
|
2650
2673
|
};
|
|
2651
2674
|
setTimeout(() => {
|
|
2652
2675
|
if (this.websocket?.readyState !== 1) {
|
package/package.json
CHANGED