@automerge/automerge-repo-network-messagechannel
Advanced tools
Comparing version 1.0.19 to 1.1.0-alpha.1
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
import { type RepoMessage, NetworkAdapter, type PeerId } from "@automerge/automerge-repo"; | ||
import { type RepoMessage, NetworkAdapter, type PeerId, type StorageId } from "@automerge/automerge-repo"; | ||
import { MessagePortRef } from "./MessagePortRef.js"; | ||
@@ -17,5 +17,5 @@ export declare class MessageChannelNetworkAdapter extends NetworkAdapter { | ||
constructor(messagePort: MessagePort, config?: MessageChannelNetworkAdapterConfig); | ||
connect(peerId: PeerId): void; | ||
connect(peerId: PeerId, storageId: StorageId | undefined, isEphemeral: boolean): void; | ||
send(message: RepoMessage): void; | ||
announceConnection(peerId: PeerId): void; | ||
announceConnection(peerId: PeerId, storageId: StorageId | undefined, isEphemeral: boolean): void; | ||
disconnect(): void; | ||
@@ -22,0 +22,0 @@ } |
@@ -25,5 +25,7 @@ /** | ||
} | ||
connect(peerId) { | ||
connect(peerId, storageId, isEphemeral) { | ||
log("messageport connecting"); | ||
this.peerId = peerId; | ||
this.storageId = storageId; | ||
this.isEphemeral = isEphemeral; | ||
this.messagePortRef.start(); | ||
@@ -39,11 +41,19 @@ this.messagePortRef.addListener("message", (e) => { | ||
case "arrive": | ||
this.messagePortRef.postMessage({ | ||
senderId: this.peerId, | ||
targetId: senderId, | ||
type: "welcome", | ||
}); | ||
this.announceConnection(senderId); | ||
{ | ||
const { storageId, isEphemeral } = message; | ||
this.messagePortRef.postMessage({ | ||
senderId: this.peerId, | ||
storageId: this.storageId, | ||
isEphemeral: this.isEphemeral, | ||
targetId: senderId, | ||
type: "welcome", | ||
}); | ||
this.announceConnection(senderId, storageId, isEphemeral); | ||
} | ||
break; | ||
case "welcome": | ||
this.announceConnection(senderId); | ||
{ | ||
const { storageId, isEphemeral } = message; | ||
this.announceConnection(senderId, storageId, isEphemeral); | ||
} | ||
break; | ||
@@ -92,3 +102,3 @@ default: | ||
} | ||
announceConnection(peerId) { | ||
announceConnection(peerId, storageId, isEphemeral) { | ||
if (!this.#startupComplete) { | ||
@@ -98,3 +108,3 @@ this.#startupComplete = true; | ||
} | ||
this.emit("peer-candidate", { peerId }); | ||
this.emit("peer-candidate", { peerId, storageId, isEphemeral }); | ||
} | ||
@@ -101,0 +111,0 @@ disconnect() { |
{ | ||
"name": "@automerge/automerge-repo-network-messagechannel", | ||
"version": "1.0.19", | ||
"version": "1.1.0-alpha.1", | ||
"description": "MessageChannel network adapter for Automerge Repo", | ||
@@ -16,3 +16,3 @@ "repository": "https://github.com/automerge/automerge-repo/tree/master/packages/automerge-repo-network-messagechannel", | ||
"dependencies": { | ||
"@automerge/automerge-repo": "^1.0.19" | ||
"@automerge/automerge-repo": "^1.1.0-alpha.1" | ||
}, | ||
@@ -30,3 +30,3 @@ "watch": { | ||
}, | ||
"gitHead": "7d28ca50dfa437ac6f7b1722b89b3f6844b90de7" | ||
"gitHead": "11805d698f860bd6ffb3ca028d3b57e718690b5a" | ||
} |
@@ -13,2 +13,3 @@ /** | ||
type Message, | ||
type StorageId, | ||
} from "@automerge/automerge-repo" | ||
@@ -41,5 +42,11 @@ import { MessagePortRef } from "./MessagePortRef.js" | ||
connect(peerId: PeerId) { | ||
connect( | ||
peerId: PeerId, | ||
storageId: StorageId | undefined, | ||
isEphemeral: boolean | ||
) { | ||
log("messageport connecting") | ||
this.peerId = peerId | ||
this.storageId = storageId | ||
this.isEphemeral = isEphemeral | ||
this.messagePortRef.start() | ||
@@ -62,11 +69,19 @@ this.messagePortRef.addListener( | ||
case "arrive": | ||
this.messagePortRef.postMessage({ | ||
senderId: this.peerId, | ||
targetId: senderId, | ||
type: "welcome", | ||
}) | ||
this.announceConnection(senderId) | ||
{ | ||
const { storageId, isEphemeral } = message | ||
this.messagePortRef.postMessage({ | ||
senderId: this.peerId, | ||
storageId: this.storageId, | ||
isEphemeral: this.isEphemeral, | ||
targetId: senderId, | ||
type: "welcome", | ||
}) | ||
this.announceConnection(senderId, storageId, isEphemeral) | ||
} | ||
break | ||
case "welcome": | ||
this.announceConnection(senderId) | ||
{ | ||
const { storageId, isEphemeral } = message | ||
this.announceConnection(senderId, storageId, isEphemeral) | ||
} | ||
break | ||
@@ -126,3 +141,7 @@ default: | ||
announceConnection(peerId: PeerId) { | ||
announceConnection( | ||
peerId: PeerId, | ||
storageId: StorageId | undefined, | ||
isEphemeral: boolean | ||
) { | ||
if (!this.#startupComplete) { | ||
@@ -132,3 +151,3 @@ this.#startupComplete = true | ||
} | ||
this.emit("peer-candidate", { peerId }) | ||
this.emit("peer-candidate", { peerId, storageId, isEphemeral }) | ||
} | ||
@@ -161,2 +180,9 @@ | ||
/** Unique ID of the storage that the sender peer is using, is persistent across sessions */ | ||
storageId?: StorageId | ||
/** Indicates whether other peers should persist the sync state of the sender peer. | ||
* Sync state is only persisted for non-ephemeral peers */ | ||
isEphemeral: boolean | ||
/** Arrive messages don't have a targetId */ | ||
@@ -173,2 +199,9 @@ targetId: never | ||
/** Unique ID of the storage that the sender peer is using, is persistent across sessions */ | ||
storageId?: StorageId | ||
/** Indicates whether other peers should persist the sync state of the sender peer. | ||
* Sync state is only persisted for non-ephemeral peers */ | ||
isEphemeral: boolean | ||
/** The peer ID of the recipient of this message */ | ||
@@ -175,0 +208,0 @@ targetId: PeerId |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
23645
576
2
+ Added@types/node@22.13.1(transitive)
- Removed@types/node@22.13.0(transitive)