@dnotifier-realtime/dnotifier 1.0.5 → 1.0.7
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/package.json
CHANGED
|
@@ -77,6 +77,11 @@ export class WebsocketTransport extends EventEmitter {
|
|
|
77
77
|
return new Promise((resolve, reject) => {
|
|
78
78
|
this.socket = new this.WebSocketImpl(url);
|
|
79
79
|
|
|
80
|
+
// Browser: binary messages as ArrayBuffer
|
|
81
|
+
if (typeof window !== "undefined") {
|
|
82
|
+
this.socket.binaryType = "arrayBuffer";
|
|
83
|
+
}
|
|
84
|
+
|
|
80
85
|
// ✅ OPEN
|
|
81
86
|
this._on("open", () => resolve(true));
|
|
82
87
|
|
|
@@ -94,9 +99,15 @@ export class WebsocketTransport extends EventEmitter {
|
|
|
94
99
|
});
|
|
95
100
|
|
|
96
101
|
// 📩 MESSAGE
|
|
97
|
-
this._on("message", (event, isBinary) => {
|
|
102
|
+
this._on("message", async (event, isBinary) => {
|
|
98
103
|
console.log('event', event)
|
|
99
104
|
const data = event?.data ?? event;
|
|
105
|
+
|
|
106
|
+
// Convert Blob -> ArrayBuffer in browser
|
|
107
|
+
if (typeof Blob !== "undefined" && data instanceof Blob) {
|
|
108
|
+
data = await data.arrayBuffer();
|
|
109
|
+
}
|
|
110
|
+
|
|
100
111
|
const chunk = decodePacket(data);
|
|
101
112
|
if (chunk) {
|
|
102
113
|
this.emit("message", chunk, isBinary);
|