* fix(ui): fix up mobile recordings display * fix(ui): some messages * fix(ui): some messages * fix(player): fix msg generation for ios messages * feat(player): add generic mmanager interface for ios player impl * feat(player): mobile player and message manager; touch manager; videoplayer * feat(player): add iphone shells, add log panel, * feat(player): detect ios sessions and inject correct player * feat(player): move screen mapper to utils * feat(player): events panel for mobile, map shell sizes to device type data, * feat(player): added network tab to mobile player; unify network message (ios and web) * feat(player): resize canvas up to phone screen size, fix capitalize util * feat(player): some general changes to support mobile events and network entries * feat(player): remove swipes from timeline * feat(player): more stuff for list walker * fix(ui): performance tab, mobile project typings and form * fix(ui):some ui touches for ios replayer shell * fix(ui): more fixes for ui, new onboarding screen for mobile projects * feat(ui): mobile overview panel (xray) * feat(ui): fixes for phone shell and tap events * fix(tracker): change phone shells and sizes * fix(tracker): fix border on replay screen * feat(ui): use crashes from db to show in session * feat(ui): use event name for xray * feat(ui): some overall ui fixes * feat(ui): IOS -> iOS * feat(ui): change tags to ant d * fix(ui): fast fix * fix(ui): fix for capitalizer * fix(ui): fix for browser display * fix(ui): fix for note popup * fix(ui): change exceptions display * fix(ui): add click rage to ios xray * fix(ui): some icons and resizing * fix(ui): fix ios context menu overlay, fix console logs creation for ios * feat(ui): added icons * feat(ui): performance warnings * feat(ui): performance warnings * feat(ui): different styles * feat(ui): rm debug true * feat(ui): fix warnings display * feat(ui): some styles for animation * feat(ui): add some animations to warnings * feat(ui): move perf warnings to performance graph * feat(ui): hide/show warns dynamically * feat(ui): new mobile touch animation * fix(tracker): update msg for ios * fix(ui): taprage fixes * fix(ui): regenerate icons and messages * fix(ui): fix msgs * fix(backend): fix events gen * fix(backend): fix userid msg
116 lines
3.5 KiB
TypeScript
116 lines
3.5 KiB
TypeScript
import * as typedLocalStorage from './localStorage';
|
|
|
|
import type { Store } from '../common/types';
|
|
import Animator, { IMessageManager } from './Animator';
|
|
import type { GetState as AnimatorGetState } from './Animator';
|
|
export const SPEED_OPTIONS = [0.5, 1, 2, 4, 8, 16]
|
|
import type { Message } from "Player/web/messages";
|
|
|
|
/* == separate this == */
|
|
const HIGHEST_SPEED = 16
|
|
const SPEED_STORAGE_KEY = "__$player-speed$__"
|
|
const SKIP_STORAGE_KEY = "__$player-skip$__"
|
|
const SKIP_TO_ISSUE_STORAGE_KEY = "__$session-skipToIssue$__"
|
|
const AUTOPLAY_STORAGE_KEY = "__$player-autoplay$__"
|
|
const SHOW_EVENTS_STORAGE_KEY = "__$player-show-events$__"
|
|
const storedSpeed: number = typedLocalStorage.number(SPEED_STORAGE_KEY)
|
|
const initialSpeed = SPEED_OPTIONS.includes(storedSpeed) ? storedSpeed : 1
|
|
const initialSkip = typedLocalStorage.boolean(SKIP_STORAGE_KEY)
|
|
const initialSkipToIssue = typedLocalStorage.boolean(SKIP_TO_ISSUE_STORAGE_KEY)
|
|
const initialAutoplay = typedLocalStorage.boolean(AUTOPLAY_STORAGE_KEY)
|
|
const initialShowEvents = typedLocalStorage.boolean(SHOW_EVENTS_STORAGE_KEY)
|
|
|
|
export type State = typeof Player.INITIAL_STATE
|
|
/* == */
|
|
|
|
export default class Player extends Animator {
|
|
static INITIAL_STATE = {
|
|
...Animator.INITIAL_STATE,
|
|
skipToIssue: initialSkipToIssue,
|
|
showEvents: initialShowEvents,
|
|
|
|
autoplay: initialAutoplay,
|
|
skip: initialSkip,
|
|
speed: initialSpeed,
|
|
} as const
|
|
|
|
constructor(private pState: Store<State & AnimatorGetState>, private manager: IMessageManager) {
|
|
super(pState, manager)
|
|
|
|
// Autoplay
|
|
if (pState.get().autoplay) {
|
|
let autoPlay = true;
|
|
document.addEventListener("visibilitychange", () => {
|
|
if (document.hidden) {
|
|
const { playing } = pState.get();
|
|
autoPlay = playing
|
|
if (playing) {
|
|
this.pause();
|
|
}
|
|
} else if (autoPlay) {
|
|
this.play();
|
|
}
|
|
})
|
|
|
|
if (!document.hidden) {
|
|
this.play();
|
|
}
|
|
}
|
|
}
|
|
|
|
/* === TODO: incapsulate in LSCache === */
|
|
|
|
toggleAutoplay() {
|
|
const autoplay = !this.pState.get().autoplay
|
|
localStorage.setItem(AUTOPLAY_STORAGE_KEY, `${autoplay}`);
|
|
this.pState.update({ autoplay })
|
|
}
|
|
|
|
//TODO: move to react part (with localStorage-cache react hook)?
|
|
toggleEvents() {
|
|
const showEvents = !this.pState.get().showEvents
|
|
localStorage.setItem(SHOW_EVENTS_STORAGE_KEY, `${showEvents}`);
|
|
this.pState.update({ showEvents })
|
|
}
|
|
|
|
// TODO: move to React part
|
|
toggleSkipToIssue() {
|
|
const skipToIssue = !this.pState.get().skipToIssue
|
|
localStorage.setItem(SKIP_TO_ISSUE_STORAGE_KEY, `${skipToIssue}`);
|
|
this.pState.update({ skipToIssue })
|
|
}
|
|
|
|
toggleSkip() {
|
|
const skip = !this.pState.get().skip
|
|
localStorage.setItem(SKIP_STORAGE_KEY, `${skip}`);
|
|
this.pState.update({ skip })
|
|
}
|
|
private updateSpeed(speed: number) {
|
|
localStorage.setItem(SPEED_STORAGE_KEY, `${speed}`);
|
|
this.pState.update({ speed })
|
|
}
|
|
|
|
toggleSpeed(index: number | null) {
|
|
const { speed } = this.pState.get();
|
|
const newSpeedIndex = index === null ? null : Math.max(0, Math.min(SPEED_OPTIONS.length - 1, index));
|
|
this.updateSpeed(newSpeedIndex === null ? speed * 2 : SPEED_OPTIONS[newSpeedIndex]);
|
|
}
|
|
|
|
speedUp() {
|
|
const { speed } = this.pState.get()
|
|
this.updateSpeed(Math.min(HIGHEST_SPEED, speed * 2))
|
|
}
|
|
|
|
speedDown() {
|
|
const { speed } = this.pState.get()
|
|
this.updateSpeed(Math.max(1, speed / 2))
|
|
}
|
|
/* === === */
|
|
|
|
|
|
clean() {
|
|
this.pause()
|
|
this.manager.clean()
|
|
}
|
|
|
|
}
|