Methods
destroy()
Releases resources held by this AirConsole instance.
Call this when the instance is no longer needed — for example, when navigating
away in a single-page application — to remove the message event listener and
cancel any pending getUserMedia timeout. Failing to call destroy() in such
environments will leave a dangling listener and possibly a live timeout.
- Source:
getUserMedia(constraints) → {Promise.<MediaStream>}
Requests microphone permissions for the controller device.
Can only be called by a controller (not the screen). Video constraints are not supported.
Parameters:
| Name | Type | Description |
|---|---|---|
constraints |
AirConsole~GetUserMediaConstraint | Media constraints. Must include `audio: true`. Video constraints are not supported and will cause the promise to reject with AirConsole.USER_MEDIA_ERROR_TYPE.invalidConstraints. |
- Source:
- See:
-
- AirConsole.USER_MEDIA_ERROR_TYPE
- AirConsole.prototype.onUserMediaAccessGranted
- AirConsole.prototype.onUserMediaAccessDenied
Returns:
Resolves with the granted MediaStream
on success. Rejects with {AirConsoleUserMediaError} (see AirConsole.USER_MEDIA_ERROR_TYPE) for
AirConsole-specific failures, or with a native
DOMException
(e.g. `NotAllowedError`, `NotFoundError`) when the browser itself denies the request.
Note: callers are responsible for stopping stream tracks when the stream is no longer needed:
`stream.getTracks().forEach(function(t) { t.stop(); })`
- Type
- Promise.<MediaStream>
Example
airconsole.getUserMedia({ audio: true }).then(function(stream) {
console.info('Media access granted', stream);
// Remember to stop tracks when done:
// stream.getTracks().forEach(function(t) { t.stop(); });
}).catch(function(error) {
if (error.name === 'AirConsole.UserMediaError') {
// AirConsole-specific error, see AirConsole.USER_MEDIA_ERROR_TYPE for possible values
console.error('AirConsole media error:', error.message);
} else {
// Native browser error (e.g. NotAllowedError, NotFoundError, AbortError)
console.error('Browser media access error:', error);
}
});
(abstract) onUserMediaAccessDenied(device_id)
Gets called on all other devices in the game as a result of to a denied request to getUserMedia on the specific
device with device_id.
On the requesting device, this callback is not invoked at this time.
The requesting device currently needs to rely on the getUserMedia promise which will provide the result at the point of promise resolution.
Parameters:
| Name | Type | Description |
|---|---|---|
device_id |
number | The device_id of the controller. |
- Source:
- See:
-
- AirConsole.prototype.getUserMedia
- AirConsole.prototype.onUserMediaAccessGranted
Example
airconsole.onUserMediaAccessDenied = function (device_id) {
console.info('Controller ' + device_id + ' was denied media access');
};
(abstract) onUserMediaAccessGranted(device_id)
Gets called on all other devices in the game as a result of to a successful request to getUserMedia on the specific
device with device_id.
On the requesting device, this callback is not invoked at this time.
The requesting device currently needs to rely on the getUserMedia promise which will provide the result at the point of promise resolution.
Parameters:
| Name | Type | Description |
|---|---|---|
device_id |
number | The device_id of the controller that was granted access. |
- Source:
- See:
-
- AirConsole.prototype.getUserMedia
- AirConsole.prototype.onUserMediaAccessDenied
Example
airconsole.onUserMediaAccessGranted = function (device_id) {
console.info('Controller ' + device_id + ' was granted media access');
};