generated from napi-rs/package-template
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from ircam-ismm/feat/render-capacity
Feat - AudioRenderCapacity
- Loading branch information
Showing
15 changed files
with
355 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
const conversions = require('webidl-conversions'); | ||
|
||
const { | ||
kNapiObj, | ||
kOnUpdate, | ||
} = require('./lib/symbols.js'); | ||
const { | ||
kEnumerableProperty, | ||
} = require('./lib/utils.js'); | ||
const { | ||
propagateEvent, | ||
} = require('./lib/events.js'); | ||
const { | ||
AudioRenderCapacityEvent, | ||
} = require('./Events.js'); | ||
|
||
class AudioRenderCapacity extends EventTarget { | ||
#onupdate = null; | ||
|
||
constructor(options) { | ||
// Make constructor "private" | ||
if ( | ||
(typeof options !== 'object') | ||
|| !(kNapiObj in options) | ||
|| options[kNapiObj]['Symbol.toStringTag'] !== 'AudioRenderCapacity' | ||
) { | ||
throw new TypeError('Illegal constructor'); | ||
} | ||
|
||
super(); | ||
|
||
this[kNapiObj] = options[kNapiObj]; | ||
|
||
this[kNapiObj][kOnUpdate] = (err, rawEvent) => { | ||
const event = new AudioRenderCapacityEvent('update', rawEvent); | ||
propagateEvent(this, event); | ||
}; | ||
|
||
this[kNapiObj].listen_to_events(); | ||
} | ||
|
||
get onupdate() { | ||
if (!(this instanceof AudioRenderCapacity)) { | ||
throw new TypeError('Invalid Invocation: Value of \'this\' must be of type \'AudioRenderCapacity\''); | ||
} | ||
|
||
return this.#onupdate; | ||
} | ||
|
||
set onupdate(value) { | ||
if (!(this instanceof AudioRenderCapacity)) { | ||
throw new TypeError('Invalid Invocation: Value of \'this\' must be of type \'AudioRenderCapacity\''); | ||
} | ||
|
||
if (isFunction(value) || value === null) { | ||
this.#onupdate = value; | ||
} | ||
} | ||
|
||
start(options = null) { | ||
if (!(this instanceof AudioRenderCapacity)) { | ||
throw new TypeError(`Invalid Invocation: Value of 'this' must be of type 'AudioRenderCapacity'`); | ||
} | ||
|
||
let targetOptions = {}; | ||
|
||
if (typeof options === 'object' && options !== null) { | ||
if (!('updateInterval' in options)) { | ||
throw new TypeError(`Failed to execute 'start' on 'AudioRenderCapacity': Failed to read the 'updateInterval' property on 'AudioRenderCapacityOptions'`); | ||
} | ||
|
||
targetOptions.updateInterval = conversions['double'](options.updateInterval, { | ||
context: `Failed to execute 'start' on 'AudioRenderCapacity': Failed to read the 'updateInterval' property on 'AudioRenderCapacityOptions': The provided value ()` | ||
}); | ||
} else { | ||
targetOptions.updateInterval = 1; | ||
} | ||
|
||
return this[kNapiObj].start(targetOptions); | ||
} | ||
|
||
stop() { | ||
if (!(this instanceof AudioRenderCapacity)) { | ||
throw new TypeError(`Invalid Invocation: Value of 'this' must be of type 'AudioRenderCapacity'`); | ||
} | ||
|
||
return this[kNapiObj].start(); | ||
} | ||
} | ||
|
||
Object.defineProperties(AudioRenderCapacity, { | ||
length: { | ||
__proto__: null, | ||
writable: false, | ||
enumerable: false, | ||
configurable: true, | ||
value: 0, | ||
}, | ||
}); | ||
|
||
Object.defineProperties(AudioRenderCapacity.prototype, { | ||
[Symbol.toStringTag]: { | ||
__proto__: null, | ||
writable: false, | ||
enumerable: false, | ||
configurable: true, | ||
value: 'AudioRenderCapacity', | ||
}, | ||
|
||
onupdate: kEnumerableProperty, | ||
stop: kEnumerableProperty, | ||
stop: kEnumerableProperty, | ||
}); | ||
|
||
module.exports = AudioRenderCapacity; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.