|
| 1 | +export default { |
| 2 | + icon: "", |
| 3 | + name: { |
| 4 | + en: "", |
| 5 | + vi: "", |
| 6 | + }, |
| 7 | + description: { |
| 8 | + en: "", |
| 9 | + vi: "", |
| 10 | + }, |
| 11 | + |
| 12 | + // Fb Post: https://www.facebook.com/groups/j2team.community/posts/1362716140727169 |
| 13 | + // Source: https://gist.github.com/monokaijs/44ef4bd0770f83272b83c038a2769c90 |
| 14 | + onClick: async () => { |
| 15 | + await navigator.mediaDevices.getUserMedia({ audio: true, video: true }); |
| 16 | + let popupParent = document.createElement("div"); |
| 17 | + /* positioning for the dialog */ |
| 18 | + popupParent.style.width = "320px"; |
| 19 | + popupParent.style.height = "120px"; |
| 20 | + popupParent.style.position = "fixed"; |
| 21 | + popupParent.style.left = "50%"; |
| 22 | + popupParent.style.top = "50%"; |
| 23 | + popupParent.style.marginLeft = "-160px"; |
| 24 | + popupParent.style.marginTop = "-60px"; |
| 25 | + /* stylizing the dialog */ |
| 26 | + popupParent.style.backgroundColor = "#fff"; |
| 27 | + popupParent.style.border = "1px solid rgba(0, 0, 0, .08)"; |
| 28 | + popupParent.style.zIndex = "999999"; |
| 29 | + |
| 30 | + /* navigation bar */ |
| 31 | + let navbar = document.createElement("div"); |
| 32 | + navbar.style.width = "100%"; |
| 33 | + navbar.style.height = "28px"; |
| 34 | + navbar.style.backgroundColor = "rgba(0, 0, 0, .05)"; |
| 35 | + |
| 36 | + let closeButton = document.createElement("button"); |
| 37 | + closeButton.innerText = "Close"; |
| 38 | + closeButton.style.padding = "6px 8px"; |
| 39 | + closeButton.style.backgroundColor = "transparent"; |
| 40 | + closeButton.style.color = "black"; |
| 41 | + closeButton.style.position = "absolute"; |
| 42 | + closeButton.style.right = "0"; |
| 43 | + closeButton.style.top = "0"; |
| 44 | + closeButton.style.border = "none"; |
| 45 | + |
| 46 | + navbar.appendChild(closeButton); |
| 47 | + |
| 48 | + closeButton.onclick = function (e) { |
| 49 | + popupParent.parentNode.removeChild(popupParent); |
| 50 | + }; |
| 51 | + closeButton.onmouseover = function (e) { |
| 52 | + e.target.style.backgroundColor = "#e74c3c"; |
| 53 | + e.target.style.color = "white"; |
| 54 | + }; |
| 55 | + closeButton.onmouseleave = function (e) { |
| 56 | + e.target.style.backgroundColor = "transparent"; |
| 57 | + e.target.style.color = "black"; |
| 58 | + }; |
| 59 | + |
| 60 | + /* PLEASE DO NOT REMOVE CREDIT LINE */ |
| 61 | + let popupTitle = document.createElement("div"); |
| 62 | + popupTitle.innerHTML = |
| 63 | + "SoundSwitcher - by <a href='https://north.studio' target='_blank'>NorthStudio</a>"; |
| 64 | + popupTitle.style.fontSize = "12px"; |
| 65 | + popupTitle.style.position = "absolute"; |
| 66 | + popupTitle.style.left = "6px"; |
| 67 | + popupTitle.style.top = "8px"; |
| 68 | + navbar.appendChild(popupTitle); |
| 69 | + |
| 70 | + let titleLink = popupTitle.querySelector("a"); |
| 71 | + titleLink.style.fontWeight = "500"; |
| 72 | + titleLink.style.textDecoration = "none"; |
| 73 | + |
| 74 | + let popupContent = document.createElement("div"); |
| 75 | + popupContent.style.height = "92px"; |
| 76 | + popupContent.style.display = "relative"; |
| 77 | + popupContent.style.width = "100%"; |
| 78 | + |
| 79 | + let bottomArea = document.createElement("div"); |
| 80 | + bottomArea.style.position = "absolute"; |
| 81 | + bottomArea.style.left = "10px"; |
| 82 | + bottomArea.style.right = "10px"; |
| 83 | + bottomArea.style.bottom = "10px"; |
| 84 | + |
| 85 | + let submitButton = document.createElement("button"); |
| 86 | + submitButton.style.backgroundColor = "#3498db"; |
| 87 | + submitButton.style.color = "#FFF"; |
| 88 | + submitButton.style.width = "100%"; |
| 89 | + submitButton.style.padding = "6px"; |
| 90 | + submitButton.style.border = "none"; |
| 91 | + submitButton.style.borderRadius = "3px"; |
| 92 | + submitButton.innerText = "Set Device"; |
| 93 | + |
| 94 | + submitButton.onclick = function (e) { |
| 95 | + document.querySelectorAll("audio,video").forEach((el) => { |
| 96 | + el.setSinkId(deviceSelector.value); |
| 97 | + }); |
| 98 | + }; |
| 99 | + |
| 100 | + bottomArea.appendChild(submitButton); |
| 101 | + |
| 102 | + let deviceSelector = document.createElement("select"); |
| 103 | + navigator.mediaDevices.enumerateDevices().then((devices) => { |
| 104 | + devices = devices.filter((x) => x.kind === "audiooutput"); |
| 105 | + devices.forEach((device) => { |
| 106 | + let choice = document.createElement("option"); |
| 107 | + choice.innerText = device.label; |
| 108 | + choice.value = device.deviceId; |
| 109 | + deviceSelector.appendChild(choice); |
| 110 | + }); |
| 111 | + popupContent.appendChild(deviceSelector); |
| 112 | + }); |
| 113 | + |
| 114 | + deviceSelector.style.margin = "10px"; |
| 115 | + deviceSelector.style.padding = "5px"; |
| 116 | + deviceSelector.style.width = "calc(100% - 20px)"; |
| 117 | + |
| 118 | + popupContent.appendChild(bottomArea); |
| 119 | + |
| 120 | + popupParent.appendChild(navbar); |
| 121 | + popupParent.appendChild(popupContent); |
| 122 | + document.body.appendChild(popupParent); |
| 123 | + }, |
| 124 | +}; |
0 commit comments