How the microphone is chosen

You have embedded an Eagle 3D Streaming page in an <iframe> on your own website, and you want your visitor to be able to choose which microphone it captures. That takes two commands, not one. This page explains why, in order, from the beginning.

1. Two websites, not one

An <iframe> embed puts two web pages on screen at once, and they belong to two different websites: yours, and Eagle 3D Streaming's inside it. That second part matters more than it sounds, and everything below follows from it.

Your page your-site.example.com The Eagle 3D page connector.eagle3dstreaming.com inside your <iframe>
Two different web addresses, so two different websites. A browser keeps them apart even though they are on screen together.

2. The computer has two microphones

Say the visitor's computer has two: microphone 1 and microphone 2. Both pages can see both of them. Nothing surprising yet.

3. But each website calls them by different names

Every microphone has an id — that is how code says use this one. The catch is that a browser gives each website its own ids for the very same microphones.

Per website, not per page: two pages on your own site share the same ids, so you can pass one between them freely. It is only crossing to a different website — which is exactly what the <iframe> does — that the ids stop meaning anything.

microphone 1 microphone 2 the same two microphones, all along Your page microphone 1 = ID1 microphone 2 = ID2 these names work only here The Eagle 3D page microphone 1 = ID3 microphone 2 = ID4 these names work only here two different websites
Microphone 1 is ID1 to your website and ID3 to Eagle 3D Streaming's. Browsers do this deliberately, so that two websites cannot compare ids to work out they are looking at the same visitor.

4. So your ids are no use to the Eagle 3D page

This is the whole problem. Say your page looks up its own microphones and sends ID1 across, meaning capture this microphone and send its audio through the stream. The Eagle 3D page has never heard of ID1. It knows those two microphones as ID3 and ID4. The message arrives, and there is nothing it can do with it.

Your page sends ID1 The Eagle 3D page knows ID3, ID4 ID1? not one of mine ids do not travel between websites
Sending your own ids across cannot work, no matter how the message is shaped.

5. So ask the Eagle 3D page for its list first

Send getMicDevices. The reply carries the ids that page uses — the ones it will recognise when you send one back, together with a readable name for each.

Your page The Eagle 3D page { cmd: "getMicDevices" } { type: "micDevices", devices: [ { deviceId: "ID3", label: "microphone 1" }, { deviceId: "ID4", label: "microphone 2" } ] } now you hold ids the Eagle 3D page issued
Now your page holds ids the Eagle 3D page issued: something to show your visitor, and something that will be understood when it goes back.

6. Pick one, and send that id back

How you choose is entirely yours. A dropdown, a settings screen, or nothing on screen at all — your code can simply pick one. Whichever it is, send back an id from the list you were given.

Your page The Eagle 3D page { cmd: "setMicDevice", deviceId: "ID4" } { type: "micDeviceChanged", ok: true, deviceId: "ID4" } microphone 2 is now the one being used
ID4 came from the Eagle 3D page, so that page knows exactly which microphone it means.

7. Eagle 3D Streaming takes it from there

Once that id arrives, your part is done. Eagle 3D Streaming captures that microphone and sends its audio over WebRTC to your Unreal application — without restarting the stream. The picture does not flicker and the visitor is not put back in the queue.

microphone 2 The Eagle 3D page your Unreal app WebRTC Your page short messages only the audio never passes through your page
Your page sends a string and receives a string. The audio goes from the microphone into the Eagle 3D page and straight on to your app.

The four messages, together

DirectionMessage
your page → the Eagle 3D page{ cmd: "getMicDevices" }
the Eagle 3D page → your page{ type: "micDevices", ok: true, devices: [{ deviceId, label, isActive }] }
your page → the Eagle 3D page{ cmd: "setMicDevice", deviceId: "<an id from that list>" }
the Eagle 3D page → your page{ type: "micDeviceChanged", ok: true, deviceId, label }
the Eagle 3D page → your page{ type: "micDeviceChanged", ok: false, error, message }

All four are ordinary postMessage traffic across the iframe boundary, the same as every other command.

Last updated