openreplay/frontend/app/player/web/WebLivePlayer.ts
Delirium dbc142c114
UI patches (28.03) (#3231)
* ui: force getting url for location in tabmanagers

* Assist add turn servers (#3229)

* fixed conflicts

* add offers

* add config to sicket query

* add config to sicket query

* add config init

* removed console logs

* removed wrong updates

* fixed conflicts

* add offers

* add config to sicket query

* add config to sicket query

* add config init

* removed console logs

* removed wrong updates

* ui: fix chat draggable, fix default params

---------

Co-authored-by: nick-delirium <nikita@openreplay.com>

* ui: fix spritemap generation for assist sessions

* ui: fix yarnlock

* fix errors

* updated widget link

* resolved conflicts

* updated widget url

---------

Co-authored-by: Andrey Babushkin <55714097+reyand43@users.noreply.github.com>
Co-authored-by: Андрей Бабушкин <andreybabushkin2000@gmail.com>
2025-03-28 17:32:12 +01:00

118 lines
3.4 KiB
TypeScript

import type { Store, SessionFilesInfo, PlayerMsg } from 'Player';
import WebPlayer from './WebPlayer';
import AssistManager from './assist/AssistManager';
import { requestEFSDom } from './network/loadFiles';
export default class WebLivePlayer extends WebPlayer {
static readonly INITIAL_STATE = {
...WebPlayer.INITIAL_STATE,
...AssistManager.INITIAL_STATE,
liveTimeTravel: false,
};
assistManager: AssistManager; // public so far
private readonly incomingMessages: PlayerMsg[] = [];
private historyFileIsLoading = false;
private lastMessageInFileTime = 0;
constructor(
wpState: Store<typeof WebLivePlayer.INITIAL_STATE>,
private session: SessionFilesInfo,
config: RTCIceServer[] | null,
agentId: number,
projectId: number,
uiErrorHandler?: { error: (msg: string) => void },
) {
super(wpState, session, true, false, uiErrorHandler);
this.assistManager = new AssistManager(
session,
(f) => this.messageManager.setMessagesLoading(f),
(msg) => {
this.incomingMessages.push(msg);
if (!this.historyFileIsLoading) {
// TODO: fix index-ing after historyFile-load
this.messageManager.distributeMessage(msg);
}
},
this.screen,
config,
wpState,
(id) => this.messageManager.getNode(id),
agentId,
this.messageManager.updateSpriteMap,
uiErrorHandler,
);
this.assistManager.connect(session.agentToken!, agentId, projectId);
}
/**
* Loads in-progress dom file from EFS directly
* then reads it to add everything happened before "now" to message manager
* to be able to replay it like usual
* */
toggleTimetravel = async () => {
if (
(this.wpState.get() as typeof WebLivePlayer.INITIAL_STATE).liveTimeTravel
) {
return;
}
let result = false;
this.historyFileIsLoading = true;
this.messageManager.setMessagesLoading(true); // do it in one place. update unique loading states each time instead
this.messageManager.resetMessageManagers();
try {
const bytes = await requestEFSDom(this.session.sessionId);
const reader = this.messageLoader.createNewParser(
false,
(msgs) => {
msgs.forEach((msg) => {
this.messageManager.distributeMessage(msg);
});
},
'cobrowse dom',
);
await reader(bytes);
this.wpState.update({
liveTimeTravel: true,
});
result = true;
// here we need to update also lists state, if we're going use them this.messageManager.onFileReadSuccess
} catch (e) {
this.uiErrorHandler?.error('Error requesting a session file');
console.error('EFS file download error:', e);
}
// Append previously received messages
this.incomingMessages
.filter((msg) => msg.time >= this.lastMessageInFileTime)
.forEach((msg) => this.messageManager.distributeMessage(msg));
this.incomingMessages.length = 0;
this.historyFileIsLoading = false;
this.messageManager.setMessagesLoading(false);
return result;
};
jumpToLive = () => {
this.wpState.update({
live: true,
livePlay: true,
});
this.jump(this.wpState.get().lastMessageTime);
};
clean = () => {
this.incomingMessages.length = 0;
this.assistManager.clean();
this.screen?.clean?.();
// @ts-ignore
this.screen = undefined;
super.clean();
};
}