diff --git a/.eslintignore b/.eslintignore index a6115c3..8187446 100644 --- a/.eslintignore +++ b/.eslintignore @@ -7,3 +7,5 @@ rollup.config.js src/lib/test src/lib/src/cli main.js +src/lib/apps/webpeer/dist +src/lib/apps/webpeer/svelte.config.js \ No newline at end of file diff --git a/README.md b/README.md index 60e633e..1ac96a4 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,10 @@ Note: This plugin cannot synchronise with the official "Obsidian Sync". - Supporting End-to-end encryption. - Synchronisation of settings, snippets, themes, and plug-ins, via [Customization sync(Beta)](#customization-sync) or [Hidden File Sync](#hiddenfilesync) - WebClip from [obsidian-livesync-webclip](https://chrome.google.com/webstore/detail/obsidian-livesync-webclip/jfpaflmpckblieefkegjncjoceapakdf) +- WebRTC peer-to-peer synchronisation without the need any `host` is now possible. (Experimental) + - This feature is still in the experimental stage. Please be careful when using it. + - Instead of using server, you can use [webpeer](https://github.com/vrtmrz/livesync-commonlib/tree/main/apps/webpeer) the pseudo client for receiving and sending between devices. + This plug-in might be useful for researchers, engineers, and developers with a need to keep their notes fully self-hosted for security reasons. Or just anyone who would like the peace of mind of knowing that their notes are fully private. diff --git a/src/features/P2PSync/CmdP2PSync.ts b/src/features/P2PSync/CmdP2PSync.ts index 4b11c2a..78b2ccf 100644 --- a/src/features/P2PSync/CmdP2PSync.ts +++ b/src/features/P2PSync/CmdP2PSync.ts @@ -20,6 +20,7 @@ import { EVENT_DATABASE_REBUILT, EVENT_PLUGIN_UNLOADED, EVENT_REQUEST_OPEN_P2P, + EVENT_SETTING_SAVED, eventHub, } from "../../common/events.ts"; import { @@ -31,8 +32,9 @@ import { import type { LiveSyncAbstractReplicator } from "../../lib/src/replication/LiveSyncAbstractReplicator.ts"; import { Logger } from "octagonal-wheels/common/logger"; import { $msg } from "../../lib/src/common/i18n.ts"; +import type { CommandShim } from "./P2PReplicator/P2PReplicatorPaneCommon.ts"; -export class P2PReplicator extends LiveSyncCommands implements IObsidianModule { +export class P2PReplicator extends LiveSyncCommands implements IObsidianModule, CommandShim { $anyNewReplicator(settingOverride: Partial = {}): Promise { const settings = { ...this.settings, ...settingOverride }; if (settings.remoteType == REMOTE_P2P) { @@ -66,6 +68,9 @@ export class P2PReplicator extends LiveSyncCommands implements IObsidianModule { eventHub.onEvent(EVENT_PLUGIN_UNLOADED, () => { void this.close(); }); + eventHub.onEvent(EVENT_SETTING_SAVED, async () => { + await this.initialiseP2PReplicator(); + }); // throw new Error("Method not implemented."); } async $everyOnInitializeDatabase(): Promise { @@ -154,8 +159,13 @@ export class P2PReplicator extends LiveSyncCommands implements IObsidianModule { if (!this._replicatorInstance) { await this.initialiseP2PReplicator(); + if (!this.settings.P2P_AutoStart) { + // While auto start is enabled, we don't need to open the connection (Literally, it's already opened automatically) + await this._replicatorInstance!.open(); + } + } else { + await this._replicatorInstance?.open(); } - await this._replicatorInstance?.open(); } async close() { await this._replicatorInstance?.close(); @@ -208,7 +218,9 @@ export class P2PReplicator extends LiveSyncCommands implements IObsidianModule { simpleStore: getPlugin().$$getSimpleStore("p2p-sync"), }; this._replicatorInstance = new TrysteroReplicator(env); - // p2p_replicator.set(this.p2pReplicator); + if (this.settings.P2P_AutoStart && this.settings.P2P_Enabled) { + await this.open(); + } return this._replicatorInstance; } catch (e) { this._log( @@ -219,4 +231,10 @@ export class P2PReplicator extends LiveSyncCommands implements IObsidianModule { throw e; } } + enableBroadcastCastings() { + return this?._replicatorInstance?.enableBroadcastChanges(); + } + disableBroadcastCastings() { + return this?._replicatorInstance?.disableBroadcastChanges(); + } } diff --git a/src/features/P2PSync/P2PReplicator/P2PReplicatorPane.svelte b/src/features/P2PSync/P2PReplicator/P2PReplicatorPane.svelte index 9d06545..26b00c4 100644 --- a/src/features/P2PSync/P2PReplicator/P2PReplicatorPane.svelte +++ b/src/features/P2PSync/P2PReplicator/P2PReplicatorPane.svelte @@ -1,16 +1,15 @@ diff --git a/src/lib b/src/lib index b8b05a2..9f71ed1 160000 --- a/src/lib +++ b/src/lib @@ -1 +1 @@ -Subproject commit b8b05a21461ee4d46f43fb16f22cfe8000b8713f +Subproject commit 9f71ed12ada9b9725eb25f1272849b539593002a diff --git a/src/modules/main/ModuleLiveSyncMain.ts b/src/modules/main/ModuleLiveSyncMain.ts index f040813..07dcf5f 100644 --- a/src/modules/main/ModuleLiveSyncMain.ts +++ b/src/modules/main/ModuleLiveSyncMain.ts @@ -14,7 +14,7 @@ import { cancelAllPeriodicTask, cancelAllTasks } from "octagonal-wheels/concurre import { stopAllRunningProcessors } from "octagonal-wheels/concurrency/processor"; import { AbstractModule } from "../AbstractModule.ts"; import type { ICoreModule } from "../ModuleTypes.ts"; -import { EVENT_PLATFORM_UNLOADED } from "../../lib/src/PlatformAPIs/APIBase.ts"; +import { EVENT_PLATFORM_UNLOADED } from "../../lib/src/PlatformAPIs/base/APIBase.ts"; export class ModuleLiveSyncMain extends AbstractModule implements ICoreModule { async $$onLiveSyncReady() {