Fix returning to the app screen after stopping the stream. Remove messages that aren't meant to be handled in NaCl.

This commit is contained in:
Cameron Gutman 2016-02-18 01:05:58 -05:00
parent 8bac82b694
commit 38d7b5d6c3
2 changed files with 22 additions and 44 deletions

View File

@ -6,14 +6,13 @@
#include "ppapi/cpp/input_event.h" #include "ppapi/cpp/input_event.h"
// you pair to a target
#define PAIR_DIRECTIVE "pair:" // Requests the NaCl module to connection to the server specified after the :
// you need to show the apps of a target #define MSG_START_REQUEST "startRequest:"
#define SHOW_GAMES_DIRECTIVE "showAppsPushed:" // Requests the NaCl module stop streaming
// you need to use a certain target to start a certain gameID #define MSG_STOP_REQUEST "stopRequest"
#define START_STREAM_DIRECTIVE "setGFEHostIPField:" // Sent by the NaCl module when the stream has stopped whether user-requested or not
// No parameters. just request a stop. #define MSG_STREAM_TERMINATED "streamTerminated"
#define STOP_DIRECTIVE "stopPushed"
MoonlightInstance* g_Instance; MoonlightInstance* g_Instance;
@ -49,10 +48,9 @@ void MoonlightInstance::OnConnectionStopped(uint32_t error) {
pthread_join(g_Instance->m_ConnectionThread, NULL); pthread_join(g_Instance->m_ConnectionThread, NULL);
pthread_join(g_Instance->m_GamepadThread, NULL); pthread_join(g_Instance->m_GamepadThread, NULL);
pp::Var response("Connection terminated"); // Notify the JS code that the stream has ended
pp::Var response(MSG_STREAM_TERMINATED);
g_Instance->PostMessage(response); g_Instance->PostMessage(response);
printf("Connection teardown complete\n");
} }
void MoonlightInstance::StopConnection() { void MoonlightInstance::StopConnection() {
@ -117,36 +115,20 @@ void* MoonlightInstance::ConnectionThreadFunc(void* context) {
// hook from javascript into the CPP code. // hook from javascript into the CPP code.
void MoonlightInstance::HandleMessage(const pp::Var& var_message) { void MoonlightInstance::HandleMessage(const pp::Var& var_message) {
// Ignore the message if it is not a string.
if (!var_message.is_string()) if (!var_message.is_string())
return; // Ignore the message if it is not a string. return;
std::string message = var_message.AsString(); std::string message = var_message.AsString();
if (message.substr(0, strlen(MSG_START_REQUEST)) == MSG_START_REQUEST) {
if(strncmp(message.c_str(), PAIR_DIRECTIVE, strlen(PAIR_DIRECTIVE)) == 0) {
handlePair(message);
} else if (strncmp(message.c_str(), SHOW_GAMES_DIRECTIVE, strlen(SHOW_GAMES_DIRECTIVE)) == 0) {
handleShowGames(message);
} else if (strncmp(message.c_str(), START_STREAM_DIRECTIVE, strlen(START_STREAM_DIRECTIVE)) == 0) {
handleStartStream(message); handleStartStream(message);
} else if (strncmp(message.c_str(), STOP_DIRECTIVE, strlen(STOP_DIRECTIVE)) == 0) { } else if (message.substr(0, strlen(MSG_STOP_REQUEST)) == MSG_STOP_REQUEST) {
handleStopStream(message); handleStopStream(message);
} else { } else {
pp::Var response("Unhandled message received: " + message); pp::Var response("Unhandled message received: " + message);
PostMessage(response); PostMessage(response);
} }
}
void MoonlightInstance::handlePair(std::string pairMessage) {
pp::Var response("Pair button pushed. Pairing is unimplemented.");
PostMessage(response);
std::string intendedHost = pairMessage.substr(pairMessage.find(PAIR_DIRECTIVE) + strlen(PAIR_DIRECTIVE));
}
void MoonlightInstance::handleShowGames(std::string showGamesMessage) {
pp::Var response("Show Games button pushed. Show Games is unimplemented");
PostMessage(response);
std::string host = showGamesMessage.substr(showGamesMessage.find(SHOW_GAMES_DIRECTIVE) + strlen(SHOW_GAMES_DIRECTIVE));
} }
void MoonlightInstance::handleStartStream(std::string startStreamMessage) { void MoonlightInstance::handleStartStream(std::string startStreamMessage) {
@ -161,16 +143,16 @@ void MoonlightInstance::handleStartStream(std::string startStreamMessage) {
m_ServerMajorVersion = 4; m_ServerMajorVersion = 4;
// Store the host, which is between two colons // Store the host from the start message
m_Host = startStreamMessage.substr(strlen(START_STREAM_DIRECTIVE), startStreamMessage.substr(strlen(START_STREAM_DIRECTIVE)).find(":")); m_Host = startStreamMessage.substr(strlen(MSG_START_REQUEST));
// Start the worker thread to establish the connection // Start the worker thread to establish the connection
pthread_create(&m_ConnectionThread, NULL, MoonlightInstance::ConnectionThreadFunc, this); pthread_create(&m_ConnectionThread, NULL, MoonlightInstance::ConnectionThreadFunc, this);
} }
void MoonlightInstance::handleStopStream(std::string stopStreamMessage) { void MoonlightInstance::handleStopStream(std::string stopStreamMessage) {
pp::Var response("Stop button pushed. Ignoring."); // Begin connection teardown
PostMessage(response); StopConnection();
} }
bool MoonlightInstance::Init(uint32_t argc, bool MoonlightInstance::Init(uint32_t argc,

View File

@ -24,7 +24,6 @@ function hideAllWorkflowDivs() {
// pair button was pushed. pass what the user entered into the GFEHostIPField. // pair button was pushed. pass what the user entered into the GFEHostIPField.
function pairPushed() { function pairPushed() {
common.naclModule.postMessage('pair:' + document.getElementById('GFEHostIPField').value);
} }
// someone pushed the "show apps" button. // someone pushed the "show apps" button.
@ -37,7 +36,6 @@ function showAppsPushed() {
var e = document.getElementById("selectHost"); var e = document.getElementById("selectHost");
target = e.options[e.selectedIndex].value; target = e.options[e.selectedIndex].value;
} }
common.naclModule.postMessage('showAppsPushed:' + target);
// we just finished the hostSettings section. expose the next one // we just finished the hostSettings section. expose the next one
showAppsMode(); showAppsMode();
} }
@ -60,9 +58,7 @@ function startPushed() {
var e = document.getElementById("selectHost"); var e = document.getElementById("selectHost");
target = e.options[e.selectedIndex].value; target = e.options[e.selectedIndex].value;
} }
var gameIDDropdown = document.getElementById("selectGame"); common.naclModule.postMessage('startRequest:' + target);
var gameID = gameIDDropdown[gameIDDropdown.selectedIndex].value;
common.naclModule.postMessage('setGFEHostIPField:' + target + ":" + gameID);
// we just finished the gameSelection section. only expose the NaCl section // we just finished the gameSelection section. only expose the NaCl section
playGameMode(); playGameMode();
} }
@ -95,17 +91,17 @@ function fullscreenNaclModule() {
// user pushed the stop button. we should stop. // user pushed the stop button. we should stop.
function stopPushed() { function stopPushed() {
common.naclModule.postMessage('stopPushed'); common.naclModule.postMessage('stopRequested');
} }
// hook from main.cpp into the javascript // hook from main.cpp into the javascript
function handleMessage(msg) { function handleMessage(msg) {
var quitStreamString = "quitStream"; var quitStreamString = "streamTerminated";
var logEl = document.getElementById('logField'); var logEl = document.getElementById('logField');
logEl.innerHTML = msg.data; logEl.innerHTML = msg.data;
console.log("message received: " + msg.data); console.log("message received: " + msg.data);
if (msg.data.lastIndexOf(quitStreamString, 0) === 0) { if (msg.data.lastIndexOf(quitStreamString, 0) === 0) {
console.log("quit stream received. returning to 'show apps' screen.") console.log("Stream termination message received. returning to 'show apps' screen.")
showAppsMode(); showAppsMode();
} }
} }