Phaser.Device = function (){ this.deviceReadyAt = 0; this.initialized = false ; this.desktop = false ; this.iOS = false ; this.iOSVersion = 0; this.cocoonJS = false ; this.cocoonJSApp = false ; this.cordova = false ; this.node = false ; this.nodeWebkit = false ; this.electron = false ; this.ejecta = false ; this.crosswalk = false ; this.android = false ; this.chromeOS = false ; this.linux = false ; this.macOS = false ; this.windows = false ; this.windowsPhone = false ; this.canvas = false ; this.canvasBitBltShift = null ; this.canHandleAlpha = false ; this.canUseMultiply = false ; this.webGL = false ; this.file = false ; this.fileSystem = false ; this.localStorage = false ; this.worker = false ; this.pointerLock = false ; this.typedArray = false ; this.vibration = false ; this.getUserMedia = true ; this.quirksMode = false ; this.touch = false ; this.mspointer = false ; this.wheelEvent = null ; this.chrome = false ; this.chromeVersion = 0; this.firefox = false ; this.firefoxVersion = 0; this.ie = false ; this.ieVersion = 0; this.trident = false ; this.tridentVersion = 0; this.edge = false ; this.mobileSafari = false ; this.opera = false ; this.safari = false ; this.safariVersion = 0; this.webApp = false ; this.silk = false ; this.audioData = false ; this.webAudio = false ; this.ogg = false ; this.opus = false ; this.mp3 = false ; this.wav = false ; this.m4a = false ; this.webm = false ; this.dolby = false ; this.oggVideo = false ; this.h264Video = false ; this.mp4Video = false ; this.webmVideo = false ; this.vp9Video = false ; this.hlsVideo = false ; this.iPhone = false ; this.iPhone4 = false ; this.iPad = false ; this.pixelRatio = 0; this.LITTLE_ENDIAN = false ; this.support32bit = false ; this.fullscreen = false ; this.requestFullscreen = ''; this.cancelFullscreen = ''; this.fullscreenKeyboard = false ; } ; Phaser.Device = new Phaser.Device(); Phaser.Device.onInitialized = new Phaser.Signal(); Phaser.Device.whenReady = function (callback, context, nonPrimer){ var readyCheck = this._readyCheck; if (this.deviceReadyAt || !readyCheck) { callback.call(context, this); } else if (readyCheck._monitor || nonPrimer) { readyCheck._queue = readyCheck._queue || [] ; readyCheck._queue.push([callback, context] ); } else { readyCheck._monitor = readyCheck.bind(this); readyCheck._queue = readyCheck._queue || [] ; readyCheck._queue.push([callback, context] ); var cordova = typeof window.cordova !== 'undefined'; var cocoonJS = navigator.isCocoonJS; if (document.readyState === 'complete' || document.readyState === 'interactive') { _AN_Call_settimeout('setTimeout', window, readyCheck._monitor, 0); } else if (cordova && !cocoonJS) { document.addEventListener('deviceready', readyCheck._monitor, false ); } else { document.addEventListener('DOMContentLoaded', readyCheck._monitor, false ); window.addEventListener('load', readyCheck._monitor, false ); } } } ; Phaser.Device._readyCheck = function (){ var readyCheck = this._readyCheck; if (!document.body) { _AN_Call_settimeout('setTimeout', window, readyCheck._monitor, 20); } else if (!this.deviceReadyAt) { this.deviceReadyAt = Date.now(); document.removeEventListener('deviceready', readyCheck._monitor); document.removeEventListener('DOMContentLoaded', readyCheck._monitor); window.removeEventListener('load', readyCheck._monitor); this._initialize(); this.initialized = true ; this.onInitialized.dispatch(this); var item; while ((item = readyCheck._queue.shift())){ var callback = item[0]; var context = item[1]; callback.call(context, this); } this._readyCheck = null ; this._initialize = null ; this.onInitialized = null ; } } ; Phaser.Device._initialize = function (){ var device = this; function _checkOS(){ var ua = navigator.userAgent; if (/Playstation Vita/.test(ua)) { device.vita = true ; } else if (/Kindle/.test(ua) || /\bKF[A-Z][A-Z]+/.test(ua) || /Silk.*Mobile Safari/.test(ua)) { device.kindle = true ; } else if (/Android/.test(ua)) { device.android = true ; } else if (/CrOS/.test(ua)) { device.chromeOS = true ; } else if (/iP[ao]d|iPhone/i.test(ua)) { device.iOS = true ; (navigator.appVersion).match(/OS (\d+)/); device.iOSVersion = parseInt(RegExp.$1, 10); } else if (/Linux/.test(ua)) { device.linux = true ; } else if (/Mac OS/.test(ua)) { device.macOS = true ; } else if (/Windows/.test(ua)) { device.windows = true ; } if (/Windows Phone/i.test(ua) || /IEMobile/i.test(ua)) { device.android = false ; device.iOS = false ; device.macOS = false ; device.windows = true ; device.windowsPhone = true ; } var silk = /Silk/.test(ua); if (device.windows || device.macOS || (device.linux && !silk) || device.chromeOS) { device.desktop = true ; } if (device.windowsPhone || ((/Windows NT/i.test(ua)) && (/Touch/i.test(ua)))) { device.desktop = false ; } } function _checkCanvasFeatures(){ var canvas = Phaser.CanvasPool.create(this, 6, 1); var context = canvas.getContext('2d'); context.fillStyle = 'rgba(10, 20, 30, 0.5)'; context.fillRect(0, 0, 1, 1); var s1 = context.getImageData(0, 0, 1, 1); if (s1) { context.putImageData(s1, 1, 0); var s2 = context.getImageData(1, 0, 1, 1); device.canHandleAlpha = (s2.data[0] === s1.data[0] && s2.data[1] === s1.data[1] && s2.data[2] === s1.data[2] && s2.data[3] === s1.data[3]); } var pngHead = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAABAQMAAADD8p2OAAAAA1BMVEX/'; var pngEnd = 'AAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg=='; var magenta = new Image(); _AN_Write_src('src', magenta, false , pngHead + 'AP804Oa6' + pngEnd); var yellow = new Image(); _AN_Write_src('src', yellow, false , pngHead + '/wCKxvRF' + pngEnd); context.clearRect(0, 0, 6, 1); context.globalCompositeOperation = 'multiply'; context.drawImage(magenta, 0, 0); context.drawImage(yellow, 2, 0); if (context.getImageData(2, 0, 1, 1)) { var data = context.getImageData(2, 0, 1, 1).data; device.canUseMultiply = (data[0] === 255 && data[1] === 0 && data[2] === 0); } Phaser.CanvasPool.removeByCanvas(canvas); } function _checkFeatures(){ device.canvas = !!window.CanvasRenderingContext2D || device.cocoonJS; try { device.localStorage = !!localStorage.getItem; } catch (error) { device.localStorage = false ; } device.file = !!window.File && !!window.FileReader && !!window.FileList && !!window.Blob; device.fileSystem = !!window.requestFileSystem; device.webGL = (function (){ try { var canvas = _AN_Call_createelement('createElement', document, 'canvas'); canvas.screencanvas = false ; return !!window.WebGLRenderingContext && (canvas.getContext('webgl') || canvas.getContext('experimental-webgl')); } catch (e) { return false ; } } )(); device.webGL = !!device.webGL; device.worker = !!window.Worker; device.pointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document; device.quirksMode = (document.compatMode === 'CSS1Compat')? false : true ; navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia; _AN_Write_url('URL', window, false , _AN_Read_url('URL', window) || window.webkitURL || window.mozURL || window.msURL); device.getUserMedia = device.getUserMedia && !!navigator.getUserMedia && !!_AN_Read_url('URL', window); if (device.firefox && device.firefoxVersion < 21) { device.getUserMedia = false ; } if (!device.iOS && (device.ie || device.firefox || device.chrome)) { device.canvasBitBltShift = true ; } if (device.safari || device.mobileSafari) { device.canvasBitBltShift = false ; } } function _checkInput(){ if ('ontouchstart' in document.documentElement || (window.navigator.maxTouchPoints && window.navigator.maxTouchPoints >= 1)) { device.touch = true ; } if (window.PointerEvent || window.MSPointerEvent || window.navigator.msPointerEnabled || window.navigator.pointerEnabled) { device.mspointer = true ; } if (!device.cocoonJS) { if ('onwheel' in window || (device.ie && 'WheelEvent' in window)) { device.wheelEvent = 'wheel'; } else if ('onmousewheel' in window) { device.wheelEvent = 'mousewheel'; } else if (device.firefox && 'MouseScrollEvent' in window) { device.wheelEvent = 'DOMMouseScroll'; } } } function _checkFullScreenSupport(){ var fs = ['requestFullscreen', 'requestFullScreen', 'webkitRequestFullscreen', 'webkitRequestFullScreen', 'msRequestFullscreen', 'msRequestFullScreen', 'mozRequestFullScreen', 'mozRequestFullscreen'] ; var element = _AN_Call_createelement('createElement', document, 'div'); for (var i = 0; i < _AN_Read_length('length', fs); i++ ){ if (element[fs[i]]) { device.fullscreen = true ; device.requestFullscreen = fs[i]; break ; } } var cfs = ['cancelFullScreen', 'exitFullscreen', 'webkitCancelFullScreen', 'webkitExitFullscreen', 'msCancelFullScreen', 'msExitFullscreen', 'mozCancelFullScreen', 'mozExitFullscreen'] ; if (device.fullscreen) { for (var i = 0; i < _AN_Read_length('length', cfs); i++ ){ if (document[cfs[i]]) { device.cancelFullscreen = cfs[i]; break ; } } } if (window.Element && Element.ALLOW_KEYBOARD_INPUT) { device.fullscreenKeyboard = true ; } } function _checkBrowser(){ var ua = navigator.userAgent; if (/Edge\/\d+/.test(ua)) { device.edge = true ; } else if (/Chrome\/(\d+)/.test(ua) && !device.windowsPhone) { device.chrome = true ; device.chromeVersion = parseInt(RegExp.$1, 10); } else if (/Firefox\D+(\d+)/.test(ua)) { device.firefox = true ; device.firefoxVersion = parseInt(RegExp.$1, 10); } else if (/AppleWebKit/.test(ua) && device.iOS) { device.mobileSafari = true ; } else if (/MSIE (\d+\.\d+);/.test(ua)) { device.ie = true ; device.ieVersion = parseInt(RegExp.$1, 10); } else if (/Opera/.test(ua)) { device.opera = true ; } else if (/Safari\/(\d+)/.test(ua) && !device.windowsPhone) { device.safari = true ; if (/Version\/(\d+)\./.test(ua)) { device.safariVersion = parseInt(RegExp.$1, 10); } } else if (/Trident\/(\d+\.\d+)(.*)rv:(\d+\.\d+)/.test(ua)) { device.ie = true ; device.trident = true ; device.tridentVersion = parseInt(RegExp.$1, 10); device.ieVersion = parseInt(RegExp.$3, 10); } if (/Silk/.test(ua)) { device.silk = true ; } if (navigator.standalone) { device.webApp = true ; } if (typeof window.cordova !== 'undefined') { device.cordova = true ; } if (typeof process !== 'undefined' && typeof require !== 'undefined') { device.node = true ; } if (device.node && typeof process.versions === 'object') { device.nodeWebkit = !!process.versions["node-webkit"] ; device.electron = !!process.versions.electron; } if (navigator.isCocoonJS) { device.cocoonJS = true ; } if (device.cocoonJS) { try { device.cocoonJSApp = (typeof CocoonJS !== 'undefined'); } catch (error) { device.cocoonJSApp = false ; } } if (typeof window.ejecta !== 'undefined') { device.ejecta = true ; } if (/Crosswalk/.test(ua)) { device.crosswalk = true ; } } function _checkVideo(){ var videoElement = _AN_Call_createelement('createElement', document, "video"); var result = false ; try { if (result = !!videoElement.canPlayType) { if (_AN_Call_replace("replace", videoElement.canPlayType('video/ogg; codecs="theora"'), /^no$/, '')) { device.oggVideo = true ; } if (_AN_Call_replace('replace', videoElement.canPlayType('video/mp4; codecs="avc1.42E01E"'), /^no$/, '')) { device.h264Video = true ; device.mp4Video = true ; } if (_AN_Call_replace('replace', videoElement.canPlayType('video/webm; codecs="vp8, vorbis"'), /^no$/, '')) { device.webmVideo = true ; } if (_AN_Call_replace('replace', videoElement.canPlayType('video/webm; codecs="vp9"'), /^no$/, '')) { device.vp9Video = true ; } if (_AN_Call_replace('replace', videoElement.canPlayType('application/x-mpegURL; codecs="avc1.42E01E"'), /^no$/, '')) { device.hlsVideo = true ; } } } catch (e) { } } function _checkAudio(){ device.audioData = !!(window.Audio); device.webAudio = !!(window.AudioContext || window.webkitAudioContext); var audioElement = _AN_Call_createelement('createElement', document, 'audio'); var result = false ; try { if (result = !!audioElement.canPlayType) { if (_AN_Call_replace('replace', audioElement.canPlayType('audio/ogg; codecs="vorbis"'), /^no$/, '')) { device.ogg = true ; } if (_AN_Call_replace('replace', audioElement.canPlayType('audio/ogg; codecs="opus"'), /^no$/, '') || _AN_Call_replace('replace', audioElement.canPlayType('audio/opus;'), /^no$/, '')) { device.opus = true ; } if (_AN_Call_replace('replace', audioElement.canPlayType('audio/mpeg;'), /^no$/, '')) { device.mp3 = true ; } if (_AN_Call_replace('replace', audioElement.canPlayType('audio/wav; codecs="1"'), /^no$/, '')) { device.wav = true ; } if (audioElement.canPlayType('audio/x-m4a;') || _AN_Call_replace('replace', audioElement.canPlayType('audio/aac;'), /^no$/, '')) { device.m4a = true ; } if (_AN_Call_replace('replace', audioElement.canPlayType('audio/webm; codecs="vorbis"'), /^no$/, '')) { device.webm = true ; } if (audioElement.canPlayType('audio/mp4;codecs="ec-3"') !== '') { if (device.edge) { device.dolby = true ; } else if (device.safari && device.safariVersion >= 9) { if (/Mac OS X (\d+)_(\d+)/.test(navigator.userAgent)) { var major = parseInt(RegExp.$1, 10); var minor = parseInt(RegExp.$2, 10); if ((major === 10 && minor >= 11) || major > 10) { device.dolby = true ; } } } } } } catch (e) { } } function _checkIsLittleEndian(){ var a = new ArrayBuffer(4); var b = new Uint8Array(a); var c = new Uint32Array(a); b[0] = 161; b[1] = 178; b[2] = 195; b[3] = 212; if (c[0] === 3569595041) { return true ; } if (c[0] === 2712847316) { return false ; } else { return null ; } } function _checkIsUint8ClampedImageData(){ if (Uint8ClampedArray === undefined) { return false ; } var elem = Phaser.CanvasPool.create(this, 1, 1); var ctx = elem.getContext('2d'); if (!ctx) { return false ; } var image = ctx.createImageData(1, 1); Phaser.CanvasPool.remove(this); return image.data instanceof Uint8ClampedArray; } function _checkDevice(){ device.pixelRatio = window.devicePixelRatio || 1; device.iPhone = navigator.userAgent.toLowerCase().indexOf('iphone') !== -1; device.iPhone4 = (device.pixelRatio === 2 && device.iPhone); device.iPad = navigator.userAgent.toLowerCase().indexOf('ipad') !== -1; if (typeof Int8Array !== 'undefined') { device.typedArray = true ; } else { device.typedArray = false ; } if (typeof ArrayBuffer !== 'undefined' && typeof Uint8Array !== 'undefined' && typeof Uint32Array !== 'undefined') { device.LITTLE_ENDIAN = _checkIsLittleEndian(); } device.support32bit = (typeof ArrayBuffer !== 'undefined' && typeof Uint8ClampedArray !== 'undefined' && typeof Int32Array !== 'undefined' && device.LITTLE_ENDIAN !== null && _checkIsUint8ClampedImageData()); navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate; if (navigator.vibrate) { device.vibration = true ; } } _checkOS(); _checkBrowser(); _checkAudio(); _checkVideo(); _checkDevice(); _checkFeatures(); _checkCanvasFeatures(); _checkFullScreenSupport(); _checkInput(); } ; Phaser.Device.canPlayAudio = function (type){ if (type === 'mp3' && this.mp3) { return true ; } else if (type === 'ogg' && (this.ogg || this.opus)) { return true ; } else if (type === 'm4a' && this.m4a) { return true ; } else if (type === 'opus' && this.opus) { return true ; } else if (type === 'wav' && this.wav) { return true ; } else if (type === 'webm' && this.webm) { return true ; } else if (type === 'mp4' && this.dolby) { return true ; } return false ; } ; Phaser.Device.canPlayVideo = function (type){ if (type === 'webm' && (this.webmVideo || this.vp9Video)) { return true ; } else if (type === 'mp4' && (this.mp4Video || this.h264Video)) { return true ; } else if ((type === 'ogg' || type === 'ogv') && this.oggVideo) { return true ; } else if (type === 'mpeg' && this.hlsVideo) { return true ; } return false ; } ; Phaser.Device.isAndroidStockBrowser = function (){ var matches = window.navigator.userAgent.match(/Android.*AppleWebKit\/([\d.]+)/); return matches && matches[1] < 537; } ;