> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes. # Device Management To let users pick which microphone, camera, and speaker a call uses, subscribe to the device lists, render a picker, and apply the user's choice — either as a preference for the next call or as a live swap during one. The same APIs cover hot-plug events, so a new headset shows up in the list as soon as it's connected. **`Browser`** ```ts Browser import { SignalWire, StaticCredentialProvider } from "@signalwire/js"; const client = new SignalWire(new StaticCredentialProvider({ token: SAT })); // 1. Prompt for permission so devices come back with real labels. await client.requestMediaPermissions({ audio: true, video: true }); // 2. Render the lists; they re-emit when devices are plugged or unplugged. client.audioInputDevices$.subscribe((mics) => renderMicOptions(mics)); client.videoInputDevices$.subscribe((cams) => renderCamOptions(cams)); client.audioOutputDevices$.subscribe((speakers) => renderSpeakerOptions(speakers)); // 3. Apply the user's choice. Before a call, set the preference on the client; // during a call, switch the live track on `call.self`. micSelect.onchange = () => { const mic = client.audioInputDevices.find((d) => d.deviceId === micSelect.value); if (activeCall?.self) activeCall.self.selectAudioInputDevice(mic); else client.selectAudioInputDevice(mic); }; ``` The sections below cover requesting permission, reading the device lists, applying the user's pick before a call and again mid-call, routing remote audio to the chosen speaker, and reacting when a device disappears. > **Info** > > **Before you start.** Devices live behind the browser's permission gate. `getUserMedia` only runs on secure origins (HTTPS or `localhost`), and device labels are empty strings until the user has granted access at least once. Plan the UX so picking a device comes *after* the prompt — not the other way around. ## The three device kinds Each kind comes with its own pair of observables: one for the list of available devices, and one for the current selection. Subscribe to both whenever you render a picker so the `` reflects the right value when the SDK switches devices on its own: **`Browser`** ```ts Browser let mics = []; let selectedMic = null; function renderMics() { micSelect.innerHTML = ""; for (const mic of mics) { const option = new Option(mic.label || `Microphone ${mic.deviceId.slice(0, 6)}`, mic.deviceId); option.selected = mic.deviceId === selectedMic?.deviceId; micSelect.append(option); } } client.audioInputDevices$.subscribe((list) => { mics = list; renderMics(); }); client.selectedAudioInputDevice$.subscribe((device) => { selectedMic = device; renderMics(); }); ``` The same pattern fits `videoInputDevices$` and `audioOutputDevices$` — only the property names change. Caching the latest of each list in module-scope state keeps the rendering pure and avoids pulling in observable combinators. ## Apply the user's choice There are two scopes for "use this device." Match the scope to the moment the user picks: #### Before a call Set a preference on the client. The selection sticks for every future [`dial()`](/docs/browser-sdk/v4/reference/signalwire/dial) and [`answer()`](/docs/browser-sdk/v4/reference/interfaces/call), so the next outbound call is captured from the right mic and camera without any extra wiring. Wire the picker's `change` event to look up the chosen `MediaDeviceInfo` from the live list and pass it to [`selectAudioInputDevice()`](/docs/browser-sdk/v4/reference/signalwire/select-audio-input-device) or [`selectVideoInputDevice()`](/docs/browser-sdk/v4/reference/signalwire/select-video-input-device): **`Browser`** ```ts Browser // ` elements, dials a test destination on demand, and switches the mic, camera, or speaker on the live call from the same picker. The handler routes preference changes through `client.*` before the call and live-track swaps through `activeCall.self.*` while the call is up — so the same dropdowns exercise both branches of the [Apply the user's choice](#apply-the-users-choice) section. ### Issue a Subscriber Access Token Create a SAT for your project — the [Authentication guide](/docs/browser-sdk/v4/guides/authentication) covers the production version of this flow; the [Create Subscriber Token](/docs/apis/rest/subscribers/tokens/create-subscriber-token) reference sends the request for you. ### Request POST https\://%7BYour\_Space\_Name%7D.signalwire.com/api/fabric/subscribers/tokens ```curl curl -X POST https://{your_space_name}.signalwire.com/api/fabric/subscribers/tokens \ -H "Content-Type: application/json" \ -u ":" \ -d '{ "reference": "john.doe@example.com" }' ``` ```python import requests url = "https://{your_space_name}.signalwire.com/api/fabric/subscribers/tokens" payload = { "reference": "john.doe@example.com" } headers = { "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers, auth=("", "")) print(response.json()) ``` ```javascript const url = 'https://{your_space_name}.signalwire.com/api/fabric/subscribers/tokens'; const credentials = btoa(":"); const options = { method: 'POST', headers: { Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json' }, body: '{"reference":"john.doe@example.com"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://{your_space_name}.signalwire.com/api/fabric/subscribers/tokens" payload := strings.NewReader("{\n \"reference\": \"john.doe@example.com\"\n}") req, _ := http.NewRequest("POST", url, payload) req.SetBasicAuth("", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://{your_space_name}.signalwire.com/api/fabric/subscribers/tokens") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request.basic_auth("", "") request["Content-Type"] = 'application/json' request.body = "{\n \"reference\": \"john.doe@example.com\"\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://{your_space_name}.signalwire.com/api/fabric/subscribers/tokens") .basicAuth("", "") .header("Content-Type", "application/json") .body("{\n \"reference\": \"john.doe@example.com\"\n}") .asString(); ``` ```php request('POST', 'https://{your_space_name}.signalwire.com/api/fabric/subscribers/tokens', [ 'body' => '{ "reference": "john.doe@example.com" }', 'headers' => [ 'Content-Type' => 'application/json', ], 'auth' => ['', ''], ]); echo $response->getBody(); ``` ```csharp using RestSharp; using RestSharp.Authenticators; var client = new RestClient("https://{your_space_name}.signalwire.com/api/fabric/subscribers/tokens"); client.Authenticator = new HttpBasicAuthenticator("", ""); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"reference\": \"john.doe@example.com\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let credentials = Data(":".utf8).base64EncodedString() let headers = [ "Authorization": "Basic \(credentials)", "Content-Type": "application/json" ] let parameters = ["reference": "john.doe@example.com"] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://{your_space_name}.signalwire.com/api/fabric/subscribers/tokens")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` ### Open the demo and request permission Save the page below as `devices-demo.html` and open it over HTTPS (or `localhost`). Paste the SAT and click **Connect** — the log reports the WebSocket coming up. Click **Request permission** to drive the browser's prompt; the three dropdowns populate with labelled devices. Pick a different mic, camera, or speaker before dialing. The log records each pick as `preference: …` — that's the `client.select*` branch in action. Plug or unplug a USB headset to see `deviceRecovered$` fire. #### devices-demo.html — full source ```html SignalWire SDK device-management demo

SignalWire SDK device-management demo



    
  

```

### Switch a device mid-call

Enter a destination in the **Destination** field (a `/public/`, `/private/`, PSTN number, or SIP URI the token can reach — see [Outbound calling](/docs/platform/voice/make-and-receive-calls#prepare-for-your-first-call) for the destination shapes) and click **Dial**. The local and remote tiles populate once the call connects.

With the call connected, change the **Microphone** or **Camera** dropdown again. The log now records the change as `live: …` — the picker is routing through `activeCall.self.selectAudioInputDevice()` instead of the client-level preference, and the remote side hears or sees the new device immediately without renegotiation. Picking a new **Speaker** triggers `applySelectedAudioOutputDevice()` on the remote `