{
"spec": {
"title": "Audio Output Devices API",
"url": "https://w3c.github.io/mediacapture-output/"
},
"algorithms": [
{
"html": "When the HTMLMediaElement constructor is invoked, the user\n agent MUST add the following initializing step:",
"rationale": "let",
"steps": [
{
"html": "
Let the element have a [[SinkId]] internal slot,\n initialized to \"\".\n
Let globalObject be the\n \n current settings object's\n \n relevant global object.
" }, { "html": "Let document be globalObject's\n \n associated Document.
If document is not\n \n allowed to use the feature identified by\n \"speaker-selection\", return a\n promise rejected with a new DOMException\n whose name is NotAllowedError.\n
If globalObject does not have transient activation,\n the user agent MAY return a promise rejected with a\n DOMException object whose name attribute has\n the value InvalidStateError.
Let element be the HTMLMediaElement\n object on which this method was invoked.
Let sinkId be the method's first argument.
" }, { "html": "If sinkId is equal to element's\n [[SinkId]],\n return a promise resolved with undefined.
Let p be a new promise.
" }, { "html": "Run the following substeps in parallel:", "rationale": "if", "steps": [ { "html": "If sinkId is not the empty string and does not\n match any audio output device identified by the result that\n would be provided by enumerateDevices(),\n reject p with a new\n DOMException whose name is\n NotFoundError and abort these substeps.
If sinkId is not the empty string, and the\n application would not be permitted to play audio through\n the device identified by sinkId if it weren't the\n current user agent default device, reject p\n with a new DOMException whose name is\n NotAllowedError and abort these substeps.
Switch the underlying audio output device for element\n to the audio device identified by sinkId.
" }, { "html": "If the preceding substep failed, reject p\n with a new DOMException whose name is\n AbortError,\n and abort these substeps.
Set element's [[SinkId]] to\n sinkId.
Resolve p.
" } ] } ] }, { "html": "Return p.
" } ] }, { "html": "In this scenario, the user agent must run the following steps:", "rationale": "let", "steps": [ { "html": "Let sinkId be the identifier for the newly available\n device.
" }, { "html": "For each media element whosesinkId attribute is equal to\n sinkId:",
"rationale": "if",
"steps": [
{
"html": "If the media element's\n paused attribute is false, start rendering\n this object's audio out of the device represented by the\n sinkId\n attribute.
selectAudioOutput method is called,\n the user agent MUST run the following steps:",
"rationale": "if",
"steps": [
{
"html": "If the relevant global object of this does not have\n transient activation, return a promise rejected with\n a DOMException object whose name attribute\n has the value InvalidStateError.
Let options be the method's first argument.
" }, { "html": "Let deviceId be options.deviceId.
Let mediaDevices be this.
" }, { "html": "Let p be a new promise.
" }, { "html": "Run the following steps in parallel:", "rationale": "let", "steps": [ { "html": "Let descriptor be a PermissionDescriptor with its\n name set to \"speaker-selection\"
If descriptor's permission state is\n \"denied\", reject\n p with a new DOMException whose\n name attribute has the value\n NotAllowedError, and abort these steps.
Probe the user agent for available audio output devices.
" }, { "html": "If there is no audio output device, reject p\n with a new DOMException whose name\n attribute has the value NotFoundError and abort\n these steps.
\"\"\n run the following sub steps:",
"rationale": "if",
"steps": [
{
"html": "If deviceId matches a\n a device id previously exposed by\n selectAudioOutput in this or an earlier browsing\n session, or matches a device id of an audio output device\n with the same groupId as an audio input device previously\n exposed by getUserMedia() in this or an earlier browsing\n session, the user agent MAY decide, based on its previous\n decision of whether to persist this id or not for this set\n of origins, to run the following sub steps:",
"rationale": "let",
"steps": [
{
"html": "Let device be the device identified by\n deviceId, if available.
" }, { "html": "If device is available, resolve\n p with either deviceId or a freshly\n rotated device id for device, and abort the\n in-parallel steps.
" } ] } ] }, { "html": "Prompt the user to choose an audio output device, with\n descriptor.
" }, { "html": "If the result of the request is \"denied\", reject\n p with a new DOMException whose name attribute\n has the value NotAllowedError and abort these steps.
Let selectedDevice be the user-selected audio output device.
" }, { "html": "Let deviceInfo be the result of\n creating a device info object to represent selectedDevice,\n with mediaDevices.
" }, { "html": "Add deviceInfo.deviceId\n to [[explicitlyGrantedAudioOutputDevices]].
Resolve p with deviceInfo.
" } ] }, { "html": "Return p.
" } ] }, { "name": "exposure decision algorithm for devices other than camera and microphone", "href": "https://w3c.github.io/mediacapture-output/#dfn-exposure-decision-algorithm-for-devices-other-than-camera-and-microphone", "html": "This specification specifies the \n exposure decision algorithm for devices other than camera and microphone.\n The algorithm runs as follows, with device, microphoneList and cameraList as input:", "rationale": "let", "steps": [ { "html": "Let document be the\n \n current settings object's\n \n relevant global object's\n \n associated Document.
Let mediaDevices be the\n \n current settings object's\n \n relevant global object's\n \n associated MediaDevices.
Let deviceInfo be the result of\n creating a device info object to represent device,\n with mediaDevices.
" }, { "html": "If document is not \n allowed to use the feature identified by \"speaker-selection\",\n or deviceInfo.kind is not \"audiooutput\",\n return false.
If deviceInfo.deviceId\n is in [[explicitlyGrantedAudioOutputDevices]], return true.
If microphone information can be exposed on mediaDevices is true,\n return true.
return false.