diff --git a/main.cpp b/main.cpp index 906a40c..5c2405d 100644 --- a/main.cpp +++ b/main.cpp @@ -29,6 +29,9 @@ class MoonlightModule : public pp::Module { }; void MoonlightInstance::OnConnectionStarted(uint32_t unused) { + // Tell the front end + pp::Var response("Connection Established"); + g_Instance->PostMessage(response); // Start receiving input events g_Instance->RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); g_Instance->RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD); diff --git a/static/js/common.js b/static/js/common.js index 7f32805..d56e16e 100644 --- a/static/js/common.js +++ b/static/js/common.js @@ -330,7 +330,7 @@ var common = (function() { } else { logMessage('Unhandled message: ' + message_event.data); } - } // TODO: page reloads here??? + } /** * Called when the DOM content has loaded; i.e. the page's document is fully diff --git a/static/js/index.js b/static/js/index.js index 0e2c687..181ffc0 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -1,15 +1,19 @@ +var target = ""; +var hosts = []; + // Called by the common.js module. function attachListeners() { document.getElementById('startButton').addEventListener('click', startPushed); document.getElementById('stopButton').addEventListener('click', stopPushed); document.getElementById('pairButton').addEventListener('click', pairPushed); document.getElementById('showAppsButton').addEventListener('click', showAppsPushed); + document.getElementById('selectResolution').addEventListener('change', saveResolution); + document.getElementById('selectFramerate').addEventListener('change', saveFramerate); window.addEventListener("resize", fullscreenNaclModule); } function moduleDidLoad() { - var logEl = document.getElementById('logField'); - logEl.innerHTML = "module loaded"; + console.log("NaCl module loaded."); } // we want the user to progress through the streaming process @@ -24,6 +28,7 @@ function hideAllWorkflowDivs() { // pair button was pushed. pass what the user entered into the GFEHostIPField. function pairPushed() { + } // someone pushed the "show apps" button. @@ -31,7 +36,7 @@ function pairPushed() { // otherwise, we assume they selected from the host history dropdown. // TODO: pass the host info to the appChoose screen function showAppsPushed() { - var target = document.getElementById('GFEHostIPField').value; + target = document.getElementById('GFEHostIPField').value; if (target == null || target == "127.0.0.1") { var e = document.getElementById("selectHost"); target = e.options[e.selectedIndex].value; @@ -53,8 +58,8 @@ function showAppsMode() { // user wants to start a stream. We need the host, game ID, and video settings(?) // TODO: video settings. function startPushed() { - var target = document.getElementById('GFEHostIPField').value; - if (target == null || target == "127.0.0.1") { + target = document.getElementById('GFEHostIPField').value; + if (target == null || target == "127.0.0.1" || target == "") { var e = document.getElementById("selectHost"); target = e.options[e.selectedIndex].value; } @@ -97,19 +102,75 @@ function stopPushed() { // hook from main.cpp into the javascript function handleMessage(msg) { var quitStreamString = "streamTerminated"; - var logEl = document.getElementById('logField'); - logEl.innerHTML = msg.data; + var connectionEstablishedString = "Connection Established"; console.log("message received: " + msg.data); if (msg.data.lastIndexOf(quitStreamString, 0) === 0) { console.log("Stream termination message received. returning to 'show apps' screen.") showAppsMode(); + } else if (msg.data.lastIndexOf(connectionEstablishedString, 0) === 0) { + var hostSelect = document.getElementById('selectHost'); + for(var i = 0; i < hostSelect.length; i++) { + if (hostSelect.options[i].value == target) return; + } + + var opt = document.createElement('option'); + opt.appendChild(document.createTextNode(target)); + opt.value = target; + document.getElementById('selectHost').appendChild(opt); + hosts.push(target); + saveHosts(); } } +function storeData(key, data, callbackFunction) { + var obj = {}; + obj[key] = data; + chrome.storage.sync.set(obj, callbackFunction); +} + +function readData(key, callbackFunction) { + chrome.storage.sync.get(key, callbackFunction); +} + +function loadResolution(previousValue) { + document.getElementById('selectResolution').value = previousValue.resolution != null ? previousValue.resolution : '720'; +} + +function saveResolution() { + storeData('resolution', document.getElementById('selectResolution').value, null); +} + +function loadFramerate(previousValue) { + document.getElementById('selectFramerate').value = previousValue.frameRate != null ? previousValue.frameRate : '30'; +} + +function saveFramerate() { + storeData('frameRate', document.getElementById('selectFramerate').value, null); +} + +function saveHosts() { + storeData('hosts', hosts, null); +} + +function loadHosts(previousValue) { + hosts = previousValue.hosts != null ? previousValue.hosts : []; + if (document.getElementById('selectHost').length > 0) { + document.getElementById('selectHost').remove(document.getElementById('selectHost').selectedIndex); + } + for(var i = 0; i < hosts.length; i++) { // programmatically add each new host. + var opt = document.createElement('option'); + opt.appendChild(document.createTextNode(hosts[i])); + opt.value = hosts[i]; + document.getElementById('selectHost').appendChild(opt); + } +} function onWindowLoad(){ - document.getElementById('streamSettings').style.display = 'none'; + // document.getElementById('streamSettings').style.display = 'none'; document.getElementById('gameSelection').style.display = 'none'; + readData('resolution', loadResolution); + readData('frameRate', loadFramerate); + readData('hosts', loadHosts); } window.onload = onWindowLoad;