Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions packages/liveblocks-server/src/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ export class Room<RM, SM, CM extends JsonObject, C = undefined> {

public meta: RM;
public readonly driver: IStorageDriver;
public logger: Logger;
#logger: Logger;

/**
* While a room is in "maintenance mode", all WebSocket connections to the
Expand Down Expand Up @@ -541,7 +541,7 @@ export class Room<RM, SM, CM extends JsonObject, C = undefined> {
const driver = options?.storage ?? makeNewInMemoryDriver();
this.meta = meta;
this.driver = driver;
this.logger = options?.logger ?? BLACK_HOLE;
this.#logger = options?.logger ?? BLACK_HOLE;
this.hooks = {
isClientMsgAllowed:
options?.hooks?.isClientMsgAllowed ??
Expand All @@ -568,6 +568,14 @@ export class Room<RM, SM, CM extends JsonObject, C = undefined> {
this.#_debug = options?.enableDebugLogging ?? false;
}

public get logger(): Logger {
return this.#logger;
}

public addLoggerContext(attrs: JsonObject): void {
this.#logger = this.#logger.withContext(attrs);
}

public get loadingState(): LoadingState {
if (this._loadData$ === null) {
return "initial";
Expand Down Expand Up @@ -828,7 +836,7 @@ export class Room<RM, SM, CM extends JsonObject, C = undefined> {
defer
);

this.logger.warn(
this.#logger.warn(
`Previous session for actor ${ticket.actor} killed in favor of new session`
);
}
Expand Down Expand Up @@ -1416,13 +1424,13 @@ export class Room<RM, SM, CM extends JsonObject, C = undefined> {

private async _loadStorage(): Promise<Storage> {
const storage = new Storage(this.driver);
await storage.load(this.logger);
await storage.load(this.#logger);
return storage;
}

private async _loadYjsStorage(): Promise<YjsStorage> {
const yjsStorage = new YjsStorage(this.driver);
await yjsStorage.load(this.logger);
await yjsStorage.load(this.#logger);
return yjsStorage;
}

Expand Down Expand Up @@ -1476,7 +1484,7 @@ export class Room<RM, SM, CM extends JsonObject, C = undefined> {
private async handlePing(sessionKey: SessionKey, ctx?: C): Promise<void> {
const session = this.sessions.get(sessionKey);
if (session === undefined) {
this.logger
this.#logger
.withContext({ sessionKey })
.warn("[probe] in handlePing, no such session exists");
return;
Expand All @@ -1499,7 +1507,7 @@ export class Room<RM, SM, CM extends JsonObject, C = undefined> {
): Promise<void> {
const session = this.sessions.get(sessionKey);
if (!session) {
this.logger
this.#logger
.withContext({ sessionKey })
.warn("[probe] in handleClientMsgs, no such session exists");
return;
Expand Down Expand Up @@ -1746,9 +1754,9 @@ export class Room<RM, SM, CM extends JsonObject, C = undefined> {
const guid = msg.guid as Guid | undefined;
const isV2 = msg.v2;
const [update, stateVector, snapshotHash] = await Promise.all([
this.yjsStorage.getYDocUpdate(this.logger, vector, guid, isV2),
this.yjsStorage.getYStateVector(this.logger, guid),
this.yjsStorage.getSnapshotHash(this.logger, { guid, isV2 }),
this.yjsStorage.getYDocUpdate(this.#logger, vector, guid, isV2),
this.yjsStorage.getYStateVector(this.#logger, guid),
this.yjsStorage.getSnapshotHash(this.#logger, { guid, isV2 }),
]);

if (update !== null && snapshotHash !== null) {
Expand All @@ -1770,7 +1778,7 @@ export class Room<RM, SM, CM extends JsonObject, C = undefined> {
const guid = msg.guid as Guid | undefined;
const isV2 = msg.v2;
const [result, error] = await tryCatch(
this.yjsStorage.addYDocUpdate(this.logger, update, guid, isV2)
this.yjsStorage.addYDocUpdate(this.#logger, update, guid, isV2)
);

if (error)
Expand Down
Loading