Share LocalDeltaConnectionServer between documents (#23146)
In SessionStorageModelLoader
This commit is contained in:
Родитель
948fc52e8d
Коммит
8e4df0d886
|
@ -17,10 +17,7 @@ import {
|
|||
LocalResolver,
|
||||
LocalSessionStorageDbFactory,
|
||||
} from "@fluidframework/local-driver/internal";
|
||||
import {
|
||||
ILocalDeltaConnectionServer,
|
||||
LocalDeltaConnectionServer,
|
||||
} from "@fluidframework/server-local-server";
|
||||
import { LocalDeltaConnectionServer } from "@fluidframework/server-local-server";
|
||||
import type { IFluidContainer, ContainerSchema } from "fluid-framework";
|
||||
import { SharedMap } from "fluid-framework/legacy";
|
||||
|
||||
|
@ -28,7 +25,7 @@ import { DiceRollerController } from "../src/controller.js";
|
|||
import { makeAppView } from "../src/view.js";
|
||||
|
||||
// The local server needs to be shared across the Loader instances for collaboration to happen
|
||||
const localServerMap = new Map<string, ILocalDeltaConnectionServer>();
|
||||
const localServer = LocalDeltaConnectionServer.create(new LocalSessionStorageDbFactory());
|
||||
|
||||
const urlResolver = new LocalResolver();
|
||||
|
||||
|
@ -43,12 +40,6 @@ export async function getSessionStorageContainer(
|
|||
containerRuntimeFactory: IRuntimeFactory,
|
||||
createNew: boolean,
|
||||
): Promise<{ container: IContainer; attach: (() => Promise<void>) | undefined }> {
|
||||
let localServer = localServerMap.get(containerId);
|
||||
if (localServer === undefined) {
|
||||
localServer = LocalDeltaConnectionServer.create(new LocalSessionStorageDbFactory());
|
||||
localServerMap.set(containerId, localServer);
|
||||
}
|
||||
|
||||
const documentServiceFactory = new LocalDocumentServiceFactory(localServer);
|
||||
const url = `${window.location.origin}/${containerId}`;
|
||||
|
||||
|
|
|
@ -11,10 +11,7 @@ import {
|
|||
LocalSessionStorageDbFactory,
|
||||
createLocalResolverCreateNewRequest,
|
||||
} from "@fluidframework/local-driver/internal";
|
||||
import {
|
||||
ILocalDeltaConnectionServer,
|
||||
LocalDeltaConnectionServer,
|
||||
} from "@fluidframework/server-local-server";
|
||||
import { LocalDeltaConnectionServer } from "@fluidframework/server-local-server";
|
||||
import { v4 as uuid } from "uuid";
|
||||
|
||||
import { IDetachedModel, IModelLoader } from "./interfaces.js";
|
||||
|
@ -22,16 +19,7 @@ import { ModelLoader } from "./modelLoader.js";
|
|||
|
||||
const urlResolver = new LocalResolver();
|
||||
|
||||
const deltaConnectionServerMap = new Map<string, ILocalDeltaConnectionServer>();
|
||||
const getDocumentServiceFactory = (documentId: string) => {
|
||||
let deltaConnection = deltaConnectionServerMap.get(documentId);
|
||||
if (deltaConnection === undefined) {
|
||||
deltaConnection = LocalDeltaConnectionServer.create(new LocalSessionStorageDbFactory());
|
||||
deltaConnectionServerMap.set(documentId, deltaConnection);
|
||||
}
|
||||
|
||||
return new LocalDocumentServiceFactory(deltaConnection);
|
||||
};
|
||||
const localServer = LocalDeltaConnectionServer.create(new LocalSessionStorageDbFactory());
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
@ -50,7 +38,7 @@ export class SessionStorageModelLoader<ModelType> implements IModelLoader<ModelT
|
|||
const documentId = uuid();
|
||||
const modelLoader = new ModelLoader<ModelType>({
|
||||
urlResolver,
|
||||
documentServiceFactory: getDocumentServiceFactory(documentId),
|
||||
documentServiceFactory: new LocalDocumentServiceFactory(localServer),
|
||||
codeLoader: this.codeLoader,
|
||||
logger: this.logger,
|
||||
generateCreateNewRequest: () => createLocalResolverCreateNewRequest(documentId),
|
||||
|
@ -61,7 +49,7 @@ export class SessionStorageModelLoader<ModelType> implements IModelLoader<ModelT
|
|||
const documentId = id;
|
||||
const modelLoader = new ModelLoader<ModelType>({
|
||||
urlResolver,
|
||||
documentServiceFactory: getDocumentServiceFactory(documentId),
|
||||
documentServiceFactory: new LocalDocumentServiceFactory(localServer),
|
||||
codeLoader: this.codeLoader,
|
||||
logger: this.logger,
|
||||
generateCreateNewRequest: () => createLocalResolverCreateNewRequest(documentId),
|
||||
|
@ -71,7 +59,7 @@ export class SessionStorageModelLoader<ModelType> implements IModelLoader<ModelT
|
|||
public async loadExistingPaused(id: string, sequenceNumber: number): Promise<ModelType> {
|
||||
const modelLoader = new ModelLoader<ModelType>({
|
||||
urlResolver,
|
||||
documentServiceFactory: getDocumentServiceFactory(id),
|
||||
documentServiceFactory: new LocalDocumentServiceFactory(localServer),
|
||||
codeLoader: this.codeLoader,
|
||||
generateCreateNewRequest: () => createLocalResolverCreateNewRequest(id),
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче