Created
April 19, 2019 10:56
-
-
Save NeelBhatt/0accd8ab31605ee5b9cadf4d19827154 to your computer and use it in GitHub Desktop.
popup.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var __awaiter = chrome.extension.getBackgroundPage().__awaiter; | |
var connection = chrome.extension.getBackgroundPage().connection; | |
document.addEventListener('DOMContentLoaded', function () { | |
const streamStartButton = document.getElementById('streamStartButton'); | |
const streamStopButton = document.getElementById('streamStopButton'); | |
const streamContent = document.getElementById('streamContent'); | |
const logContent = document.getElementById('logContent'); | |
streamStartButton.addEventListener("click", (event) => __awaiter(this, void 0, void 0, function* () { | |
streamStartButton.setAttribute("disabled", "disabled"); | |
streamStopButton.removeAttribute("disabled"); | |
try { | |
connection.stream("StartStream") | |
.subscribe({ | |
next: (item) => { | |
streamContent.src = "data:image/jpg;base64," + item; | |
}, | |
complete: () => { | |
var li = document.createElement("li"); | |
li.textContent = "Stream completed"; | |
logContent.appendChild(li); | |
}, | |
error: (err) => { | |
var li = document.createElement("li"); | |
li.textContent = err; | |
logContent.appendChild(li); | |
}, | |
}); | |
} | |
catch (e) { | |
console.error(e.toString()); | |
} | |
event.preventDefault(); | |
})); | |
streamStopButton.addEventListener("click", function () { | |
streamStopButton.setAttribute("disabled", "disabled"); | |
streamStartButton.removeAttribute("disabled"); | |
connection.invoke("StopStream").catch(err => console.error(err.toString())); | |
event.preventDefault(); | |
}); | |
connection.on("StopStream", () => { | |
var li = document.createElement("li"); | |
li.textContent = "stream closed"; | |
logContent.appendChild(li); | |
streamStopButton.setAttribute("disabled", "disabled"); | |
streamStartButton.removeAttribute("disabled"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment