1 import { Injectable } from '@angular/core'
4 export class ScreenService {
5 isBroadcastMessageDisplayed = false
7 private windowInnerWidth: number
8 private lastFunctionCallTime: number
9 private cacheForMs = 500
12 this.refreshWindowInnerWidth()
15 isInSmallView (marginLeft = 0) {
17 const contentWidth = this.getWindowInnerWidth() - marginLeft
18 return contentWidth < 800
21 return this.getWindowInnerWidth() < 800
25 return this.getWindowInnerWidth() < 1100
29 return this.getWindowInnerWidth() < 500
33 return 'ontouchstart' in window || navigator.msMaxTouchPoints
36 getNumberOfAvailableMiniatures () {
37 const screenWidth = this.getWindowInnerWidth()
39 let numberOfVideos = 1
41 if (screenWidth > 1850) numberOfVideos = 7
42 else if (screenWidth > 1600) numberOfVideos = 6
43 else if (screenWidth > 1370) numberOfVideos = 5
44 else if (screenWidth > 1100) numberOfVideos = 4
45 else if (screenWidth > 850) numberOfVideos = 3
50 // Cache window inner width, because it's an expensive call
51 getWindowInnerWidth () {
52 if (this.cacheWindowInnerWidthExpired()) this.refreshWindowInnerWidth()
54 return this.windowInnerWidth
57 private refreshWindowInnerWidth () {
58 this.lastFunctionCallTime = new Date().getTime()
60 this.windowInnerWidth = window.innerWidth
63 private cacheWindowInnerWidthExpired () {
64 if (!this.lastFunctionCallTime) return true
66 return new Date().getTime() > (this.lastFunctionCallTime + this.cacheForMs)