Skip to content

Commit

Permalink
Fix: Ensure outgoing (host) connection is open before sending message
Browse files Browse the repository at this point in the history
  • Loading branch information
therealPaulPlay committed Jan 28, 2025
1 parent 23ede83 commit 1a26c6e
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,13 @@ export default class PlayPeer {
this.#broadcastMessage("storage_sync", { storage: this.#storage });
} else {
try {
this.#outgoingConnection?.send({
type: 'storage_update',
key,
value
});
if (this.#outgoingConnection?.open) {
this.#outgoingConnection?.send({
type: 'storage_update',
key,
value
});
}
} catch (error) {
console.error(ERROR_PREFIX + "Error sending storage update to host:", error);
this.#triggerEvent("error", "Error sending storage update to host: " + error);
Expand Down Expand Up @@ -481,13 +483,15 @@ export default class PlayPeer {
} else {
try {
// Request the host to perform the operation
this.#outgoingConnection?.send({
type: 'array_update',
key,
operation,
value,
updateValue
});
if (this.#outgoingConnection?.open) {
this.#outgoingConnection?.send({
type: 'array_update',
key,
operation,
value,
updateValue
});
}
this.#handleArrayUpdate(key, operation, value, updateValue); // Optimistic update
} catch (error) {
console.error(ERROR_PREFIX + `Failed to send array update to host:`, error);
Expand Down

0 comments on commit 1a26c6e

Please sign in to comment.