Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import GrWebShmProxy from './protocol/GrWebShmProxy'
import GrWebShmBufferEvents from './protocol/GrWebShmBufferEvents'
// web gl
import GrWebGlBufferProxy from './protocol/GrWebGlBufferProxy'
import GrWebGlProxy from './protocol/GrWebGlProxy'
import GrWebGlBufferEvents from './protocol/GrWebGlBufferEvents'
/**
* @type {WebFS}
*/
const webFS = WebFS.create(_uuidv4())
/**
* @type {Connection}
*/
const connection = new Connection()
/**
* @type {Display}
*/
const display = new Display(connection)
/**
* @returns {string}
* @private
*/
function _uuidv4 () {
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ self.crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
)
}
/**
constructor (display, id) {
super()
/**
* @type {string}
*/
this.id = id
/**
* @type {Connection}
*/
this.connection = new Connection()
/**
* @type {Display}
* @private
*/
this._display = display
/**
* @type {number}
* @private
*/
this._syncEventSerial = 0
/**
* @type {function():void}
* @private
*/
this._destroyedResolver = null
/**
constructor () {
super()
/**
* @type {number}
*/
this.nextId = 1
/**
* @type {Connection}
*/
this.connection = new Connection()
/**
* @type {WlDisplayProxy}
*/
this.displayProxy = new WlDisplayProxy(this, this.nextId++)
/**
* @type {Display}
*/
this.displayProxy.listener = this
}
fromArrayBuffer (arrayBuffer) {
const fd = this._nextFD++
const type = 'ArrayBuffer'
const webFdURL = new URL(`client://`)
webFdURL.searchParams.append('fd', `${fd}`)
webFdURL.searchParams.append('type', type)
webFdURL.searchParams.append('clientId', this._fdDomainUUID)
const webFD = new WebFD(fd, type, webFdURL, () => Promise.resolve(arrayBuffer), () => { delete this._webFDs[fd] })
this._webFDs[fd] = webFD
return webFD
}
fromOffscreenCanvas (offscreenCanvas) {
const fd = this._nextFD++
const type = 'OffscreenCanvas'
const webFdURL = new URL(`client://`)
webFdURL.searchParams.append('fd', `${fd}`)
webFdURL.searchParams.append('type', type)
webFdURL.searchParams.append('clientId', this._fdDomainUUID)
const webFD = new WebFD(fd, type, webFdURL, () => Promise.resolve(offscreenCanvas), () => { delete this._webFDs[fd] })
this._webFDs[fd] = webFD
return webFD
}
fromImageBitmap (imageBitmap) {
const fd = this._nextFD++
const type = 'ImageBitmap'
const webFdURL = new URL(`client://`)
webFdURL.searchParams.append('fd', `${fd}`)
webFdURL.searchParams.append('type', type)
webFdURL.searchParams.append('clientId', this._fdDomainUUID)
const webFD = new WebFD(fd, type, webFdURL, () => Promise.resolve(imageBitmap), () => { delete this._webFDs[fd] })
this._webFDs[fd] = webFD
return webFD
}