mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-18 23:07:02 +08:00
feat(nbstore): improve nbstore (#9512)
This commit is contained in:
@@ -22,13 +22,27 @@ type ChannelMessage =
|
||||
collectId: string;
|
||||
};
|
||||
|
||||
interface BroadcastChannelAwarenessStorageOptions {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export class BroadcastChannelAwarenessStorage extends AwarenessStorageBase {
|
||||
static readonly identifier = 'BroadcastChannelAwarenessStorage';
|
||||
|
||||
override readonly storageType = 'awareness';
|
||||
override readonly connection = new BroadcastChannelConnection(this.options);
|
||||
override readonly connection = new BroadcastChannelConnection({
|
||||
id: this.options.id,
|
||||
});
|
||||
get channel() {
|
||||
return this.connection.inner;
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly options: BroadcastChannelAwarenessStorageOptions
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
private readonly subscriptions = new Map<
|
||||
string,
|
||||
Set<{
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { AutoReconnectConnection } from '../../connection';
|
||||
import type { StorageOptions } from '../../storage';
|
||||
|
||||
export interface BroadcastChannelConnectionOptions {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export class BroadcastChannelConnection extends AutoReconnectConnection<BroadcastChannel> {
|
||||
readonly channelName = `channel:${this.opts.peer}:${this.opts.type}:${this.opts.id}`;
|
||||
readonly channelName = `channel:${this.opts.id}`;
|
||||
|
||||
constructor(private readonly opts: StorageOptions) {
|
||||
constructor(private readonly opts: BroadcastChannelConnectionOptions) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { StorageConstructor } from '..';
|
||||
import { BroadcastChannelAwarenessStorage } from './awareness';
|
||||
|
||||
export const broadcastChannelStorages = [
|
||||
BroadcastChannelAwarenessStorage,
|
||||
] satisfies StorageConstructor[];
|
||||
Reference in New Issue
Block a user