diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/util/PingManager.ts | 23 | ||||
-rw-r--r-- | src/client/views/MainView.tsx | 156 | ||||
-rw-r--r-- | src/client/views/topbar/TopBar.tsx | 4 |
3 files changed, 81 insertions, 102 deletions
diff --git a/src/client/util/PingManager.ts b/src/client/util/PingManager.ts index 7562faf03..9f4bd3642 100644 --- a/src/client/util/PingManager.ts +++ b/src/client/util/PingManager.ts @@ -1,5 +1,5 @@ -import { action, IReactionDisposer, observable, observe, reaction } from "mobx"; -import { Networking } from "../Network"; +import { action, observable } from 'mobx'; +import { Networking } from '../Network'; export class PingManager { // create static instance and getter for global use @observable static _instance: PingManager; @@ -7,25 +7,24 @@ export class PingManager { return PingManager._instance; } - @observable isBeating: boolean = true; - private setIsBeating = action((status: boolean) => this.isBeating = status); + @observable IsBeating: boolean = true; + private setIsBeating = action((status: boolean) => (this.IsBeating = status)); - ping = async (): Promise<void> => { + sendPing = async (): Promise<void> => { try { - const response = await Networking.PostToServer('/ping', { date: new Date() }); - // console.log('ping response', response, this.interval); - !this.isBeating && this.setIsBeating(true); + await Networking.PostToServer('/ping', { date: new Date() }); + !this.IsBeating && this.setIsBeating(true); } catch { console.error('ping error'); - this.isBeating && this.setIsBeating(false); + this.IsBeating && this.setIsBeating(false); } - } + }; // not used now, but may need to clear interval - private interval: NodeJS.Timeout | null = null; + private _interval: NodeJS.Timeout | null = null; INTERVAL_SECONDS = 1; constructor() { PingManager._instance = this; - this.interval = setInterval(this.ping, this.INTERVAL_SECONDS * 1000); + this._interval = setInterval(this.sendPing, this.INTERVAL_SECONDS * 1000); } } diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx index fbe44cf7a..6c05db892 100644 --- a/src/client/views/MainView.tsx +++ b/src/client/views/MainView.tsx @@ -145,95 +145,75 @@ export class MainView extends React.Component { componentDidMount() { document.getElementById('root')?.addEventListener('scroll', e => (ele => (ele.scrollLeft = ele.scrollTop = 0))(document.getElementById('root')!)); const ele = document.getElementById('loader'); - console.log(PingManager.Instance); - - const wrapper = () => { - const prog = document.getElementById('dash-progress'); - if (ele && prog) { - // remove from DOM - setTimeout(() => { - //clearTimeout(); - prog.style.transition = '1s'; - prog.style.width = '100%'; - }, 0); - setTimeout(() => (ele.outerHTML = ''), 1000); - } - this._sidebarContent.proto = undefined; - if (!MainView.Live) { - DocServer.setPlaygroundFields([ - 'dataTransition', - 'viewTransition', - 'treeViewOpen', - 'showSidebar', - 'itemIndex', // for changing slides in presentations - 'sidebarWidthPercent', - 'currentTimecode', - 'timelineHeightPercent', - 'presStatus', - 'panX', - 'panY', - 'overlayX', - 'overlayY', - 'fitWidth', - 'nativeWidth', - 'nativeHeight', - 'text-scrollHeight', - 'text-height', - 'hideMinimap', - 'viewScale', - 'scrollTop', - 'hidden', - 'curPage', - 'viewType', - 'chromeHidden', - 'currentFrame', - 'width', - 'height', - 'nativeWidth', - ]); // can play with these fields on someone else's - } - DocServer.GetRefField('rtfProto').then( - proto => - proto instanceof Doc && - reaction( - () => StrCast(proto.BROADCAST_MESSAGE), - msg => msg && alert(msg) - ) - ); - - const tag = document.createElement('script'); - tag.src = 'https://www.youtube.com/iframe_api'; - const firstScriptTag = document.getElementsByTagName('script')[0]; - firstScriptTag.parentNode!.insertBefore(tag, firstScriptTag); - window.removeEventListener('keydown', KeyManager.Instance.handle); - window.addEventListener('keydown', KeyManager.Instance.handle); - window.removeEventListener('keyup', KeyManager.Instance.unhandle); - window.addEventListener('keyup', KeyManager.Instance.unhandle); - window.addEventListener('paste', KeyManager.Instance.paste as any); - document.addEventListener('dash', (e: any) => { - // event used by chrome plugin to tell Dash which document to focus on - const id = FormattedTextBox.GetDocFromUrl(e.detail); - DocServer.GetRefField(id).then(doc => (doc instanceof Doc ? DocumentManager.Instance.showDocument(doc, { willPan: false }) : null)); - }); - document.addEventListener('linkAnnotationToDash', Hypothesis.linkListener); - this.initEventListeners(); - }; - - if (PingManager.Instance.isBeating) { - wrapper(); - } else { - console.error('PingManager is not beating', new Date()); - const dispose = reaction( - () => PingManager.Instance.isBeating, - isBeating => { - if (isBeating) { - console.log('PingManager is beating', new Date()); - wrapper(); - dispose(); - } - } - ); + const prog = document.getElementById('dash-progress'); + if (ele && prog) { + // remove from DOM + setTimeout(() => { + //clearTimeout(); + prog.style.transition = '1s'; + prog.style.width = '100%'; + }, 0); + setTimeout(() => (ele.outerHTML = ''), 1000); } + this._sidebarContent.proto = undefined; + if (!MainView.Live) { + DocServer.setPlaygroundFields([ + 'dataTransition', + 'viewTransition', + 'treeViewOpen', + 'showSidebar', + 'itemIndex', // for changing slides in presentations + 'sidebarWidthPercent', + 'currentTimecode', + 'timelineHeightPercent', + 'presStatus', + 'panX', + 'panY', + 'overlayX', + 'overlayY', + 'fitWidth', + 'nativeWidth', + 'nativeHeight', + 'text-scrollHeight', + 'text-height', + 'hideMinimap', + 'viewScale', + 'scrollTop', + 'hidden', + 'curPage', + 'viewType', + 'chromeHidden', + 'currentFrame', + 'width', + 'height', + 'nativeWidth', + ]); // can play with these fields on someone else's + } + DocServer.GetRefField('rtfProto').then( + proto => + proto instanceof Doc && + reaction( + () => StrCast(proto.BROADCAST_MESSAGE), + msg => msg && alert(msg) + ) + ); + + const tag = document.createElement('script'); + tag.src = 'https://www.youtube.com/iframe_api'; + const firstScriptTag = document.getElementsByTagName('script')[0]; + firstScriptTag.parentNode!.insertBefore(tag, firstScriptTag); + window.removeEventListener('keydown', KeyManager.Instance.handle); + window.addEventListener('keydown', KeyManager.Instance.handle); + window.removeEventListener('keyup', KeyManager.Instance.unhandle); + window.addEventListener('keyup', KeyManager.Instance.unhandle); + window.addEventListener('paste', KeyManager.Instance.paste as any); + document.addEventListener('dash', (e: any) => { + // event used by chrome plugin to tell Dash which document to focus on + const id = FormattedTextBox.GetDocFromUrl(e.detail); + DocServer.GetRefField(id).then(doc => (doc instanceof Doc ? DocumentManager.Instance.showDocument(doc, { willPan: false }) : null)); + }); + document.addEventListener('linkAnnotationToDash', Hypothesis.linkListener); + this.initEventListeners(); } componentWillUnMount() { diff --git a/src/client/views/topbar/TopBar.tsx b/src/client/views/topbar/TopBar.tsx index 68d652cc4..157d7c04a 100644 --- a/src/client/views/topbar/TopBar.tsx +++ b/src/client/views/topbar/TopBar.tsx @@ -38,10 +38,10 @@ export class TopBar extends React.Component { @observable textColor: string = Colors.LIGHT_GRAY; @observable backgroundColor: string = Colors.DARK_GRAY; - @observable happyHeart: boolean = PingManager.Instance.isBeating; + @observable happyHeart: boolean = PingManager.Instance.IsBeating; setHappyHeart = action((status: boolean) => (this.happyHeart = status)); dispose = reaction( - () => PingManager.Instance.isBeating, + () => PingManager.Instance.IsBeating, isBeating => this.setHappyHeart(isBeating) ); |