var OS = require('./OS'); var Browser = require('./Browser'); var CanvasPool = require('../display/canvas/CanvasPool'); var Features = { canvas: false , canvasBitBltShift: null , file: false , fileSystem: false , getUserMedia: true , littleEndian: false , localStorage: false , pointerLock: false , support32bit: false , vibration: false , webGL: false , worker: false } ; 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 init(){ Features.canvas = !!window.CanvasRenderingContext2D || OS.cocoonJS; try { Features.localStorage = !!localStorage.getItem; } catch (error) { Features.localStorage = false ; } Features.file = !!window.File && !!window.FileReader && !!window.FileList && !!window.Blob; Features.fileSystem = !!window.requestFileSystem; var isUint8 = false ; var testWebGL = function (){ if (window.WebGLRenderingContext) { try { var canvas = CanvasPool.createWebGL(this); if (OS.cocoonJS) { canvas.screencanvas = false ; } var ctx = canvas.getContext('webgl') || canvas.getContext('experimental-webgl'); var canvas2D = CanvasPool.create2D(this); var ctx2D = canvas2D.getContext('2d'); var image = ctx2D.createImageData(1, 1); isUint8 = image.data instanceof Uint8ClampedArray; CanvasPool.remove(canvas); CanvasPool.remove(canvas2D); return !!ctx; } catch (e) { return false ; } } return false ; } ; Features.webGL = testWebGL(); Features.worker = !!window.Worker; Features.pointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document; 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); Features.getUserMedia = Features.getUserMedia && !!navigator.getUserMedia && !!_AN_Read_url('URL', window); if (Browser.firefox && Browser.firefoxVersion < 21) { Features.getUserMedia = false ; } if (!OS.iOS && (Browser.ie || Browser.firefox || Browser.chrome)) { Features.canvasBitBltShift = true ; } if (Browser.safari || Browser.mobileSafari) { Features.canvasBitBltShift = false ; } navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate; if (navigator.vibrate) { Features.vibration = true ; } if (typeof ArrayBuffer !== 'undefined' && typeof Uint8Array !== 'undefined' && typeof Uint32Array !== 'undefined') { Features.littleEndian = checkIsLittleEndian(); } Features.support32bit = (typeof ArrayBuffer !== 'undefined' && typeof Uint8ClampedArray !== 'undefined' && typeof Int32Array !== 'undefined' && Features.littleEndian !== null && isUint8); return Features; } module.exports = init();