add option to use collabora server
This commit is contained in:
@@ -129,7 +129,8 @@ async function getTab(tabId) {
|
||||
* @param {number} tabId - The ID of the tab to start capturing.
|
||||
* @returns {Promise<void>} - A Promise that resolves when the capture process is started successfully.
|
||||
*/
|
||||
async function startCapture(tabId) {
|
||||
async function startCapture(options) {
|
||||
const { tabId } = options;
|
||||
const optionTabId = await getLocalStorageValue("optionTabId");
|
||||
if (optionTabId) {
|
||||
await removeChromeTab(optionTabId);
|
||||
@@ -149,7 +150,7 @@ async function startCapture(tabId) {
|
||||
|
||||
await sendMessageToTab(optionTab.id, {
|
||||
type: "start_capture",
|
||||
data: { currentTabId: currentTab.id },
|
||||
data: { currentTabId: currentTab.id, host: options.host, port: options.port },
|
||||
});
|
||||
} else {
|
||||
console.log("No Audio");
|
||||
@@ -184,7 +185,7 @@ async function stopCapture() {
|
||||
*/
|
||||
chrome.runtime.onMessage.addListener((message) => {
|
||||
if (message.action === "startCapture") {
|
||||
startCapture(message.tabId);
|
||||
startCapture(message);
|
||||
} else if (message.action === "stopCapture") {
|
||||
stopCapture();
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ async function startRecord(option) {
|
||||
window.close();
|
||||
};
|
||||
|
||||
const socket = new WebSocket("ws://localhost:9090/");
|
||||
const socket = new WebSocket(`ws://${option.host}:${option.port}/`);
|
||||
let isServerReady = false;
|
||||
socket.onopen = function(e) {
|
||||
socket.send("handshake");
|
||||
|
||||
@@ -11,5 +11,9 @@
|
||||
<div class="button" id="startCapture">Start Capture</div>
|
||||
<div class="button" id="stopCapture" disabled>Stop Capture</div>
|
||||
</div>
|
||||
<div class="checkbox-container">
|
||||
<input type="checkbox" id="useServerCheckbox">
|
||||
<label for="useServerCheckbox">Use Collabora Whisper-Live Server</label>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -3,6 +3,8 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
const startButton = document.getElementById("startCapture");
|
||||
const stopButton = document.getElementById("stopCapture");
|
||||
|
||||
const useServerCheckbox = document.getElementById("useServerCheckbox");
|
||||
|
||||
// Add click event listeners to the buttons
|
||||
startButton.addEventListener("click", startCapture);
|
||||
stopButton.addEventListener("click", stopCapture);
|
||||
@@ -16,6 +18,13 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
}
|
||||
});
|
||||
|
||||
// Retrieve checkbox state from storage on popup open
|
||||
chrome.storage.local.get("useServerState", ({ useServerState }) => {
|
||||
if (useServerState !== undefined) {
|
||||
useServerCheckbox.checked = useServerState;
|
||||
}
|
||||
});
|
||||
|
||||
// Function to handle the start capture button click event
|
||||
async function startCapture() {
|
||||
// Ignore click if the button is disabled
|
||||
@@ -27,7 +36,20 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
const currentTab = await getCurrentTab();
|
||||
|
||||
// Send a message to the background script to start capturing
|
||||
chrome.runtime.sendMessage({ action: "startCapture", tabId: currentTab.id }, () => {
|
||||
let host = "localhost";
|
||||
let port = "9090";
|
||||
const useCollaboraServer = useServerCheckbox.checked;
|
||||
if (useCollaboraServer){
|
||||
host = "transcription.kurg.org"
|
||||
port = "7090"
|
||||
}
|
||||
|
||||
chrome.runtime.sendMessage(
|
||||
{
|
||||
action: "startCapture",
|
||||
tabId: currentTab.id,
|
||||
host: host,
|
||||
port: port }, () => {
|
||||
// Update capturing state in storage and toggle the buttons
|
||||
chrome.storage.local.set({ capturingState: { isCapturing: true } }, () => {
|
||||
toggleCaptureButtons(true);
|
||||
@@ -64,7 +86,14 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
function toggleCaptureButtons(isCapturing) {
|
||||
startButton.disabled = isCapturing;
|
||||
stopButton.disabled = !isCapturing;
|
||||
useServerCheckbox.disabled = isCapturing;
|
||||
startButton.classList.toggle("disabled", isCapturing);
|
||||
stopButton.classList.toggle("disabled", !isCapturing);
|
||||
}
|
||||
});
|
||||
|
||||
// Save the checkbox state when it's toggled
|
||||
useServerCheckbox.addEventListener("change", () => {
|
||||
const useServerState = useServerCheckbox.checked;
|
||||
chrome.storage.local.set({ useServerState });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -101,3 +101,7 @@ label {
|
||||
width: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.checkbox-container {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user