Merge branch 'master' of github.com:cgutman/moonlight-chrome

This commit is contained in:
Cameron Gutman 2016-02-13 18:05:47 -05:00
commit 452314ef91
3 changed files with 73 additions and 13 deletions

View File

@ -12,12 +12,14 @@
<div id="title">
<h1>Moonlight Streaming</h1>
<h2>Chrome App Status: <code id="statusField">NO-STATUS</code></h2>
<p></p>
<code id="logField">log</code>
</div>
<p>Enter the IP/hostname of the GFE streaming computer, or select one from the history:</p>
<input type="text" size="15" id="GFEHostIPField" value="127.0.0.1">
<select>
<select id="selectHost">
<option value="">No history available</option>
</select>
@ -35,7 +37,7 @@
<div hidden id="gameSelectionDiv">
<p>Select a game to run</p>
<select>
<select id="selectGame">
<option value="game_id_1">Game Name 1</option>
<option value="game_id_2">Game Name 2</option>
<option value="game_id_3">Game Name 3</option>

View File

@ -6,25 +6,44 @@ function attachListeners() {
document.getElementById('showAppsButton').addEventListener('click', showAppsPushed);
}
// pair button was pushed. pass what the user entered into the GFEHostIPField.
function pairPushed() {
common.naclModule.postMessage('pair:' + document.getElementById('GFEHostIPField').value);
}
// someone pushed the "show apps" button.
// if they entered something in the GFEHostIPField, use that.
// otherwise, we assume they selected from the host history dropdown.
function showAppsPushed() {
common.naclModule.postMessage('showAppsPushed');
var target = document.getElementById('GFEHostIPField').value;
if (target == null || target == "127.0.0.1") {
var e = document.getElementById("selectHost");
target = e.options[e.selectedIndex].value;
}
common.naclModule.postMessage('showAppsPushed:' + target);
document.getElementById("gameSelectionDiv").style.display = "visible";
}
// user wants to start a stream. We need the host, game ID, and video settings(?)
// TODO: video settings.
function startPushed() {
common.naclModule.postMessage('setGFEHostIPField:' + document.getElementById('GFEHostIPField').value);
var target = document.getElementById('GFEHostIPField').value;
if (target == null || target == "127.0.0.1") {
var e = document.getElementById("selectHost");
target = e.options[e.selectedIndex].value;
}
var gameIDDropdown = document.getElementById("selectGame");
var gameID = gameIDDropdown[gameIDDropdown.selectedIndex].value;
common.naclModule.postMessage('setGFEHostIPField:' + target + ":" + gameID);
}
// user pushed the stop button. we should stop.
function stopPushed() {
common.naclModule.postMessage('stopPushed');
}
// hook from main.cpp into the javascript
function handleMessage(msg) {
var logEl = document.getElementById('GFEHostIPField');
logEl.value = msg.data;
var logEl = document.getElementById('logField');
logEl.innerHTML = msg.data;
}

View File

@ -2,11 +2,20 @@
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include "ppapi/cpp/input_event.h"
static char s_Host[256];
static STREAM_CONFIGURATION s_StreamConfig;
// you pair to a target
#define PAIR_DIRECTIVE "pair:"
// you need to show the apps of a target
#define SHOW_GAMES_DIRECTIVE "showAppsPushed:"
// you need to use a certain target to start a certain gameID
#define START_STREAM_DIRECTIVE "setGFEHostIPField:"
// No parameters. just request a stop.
#define STOP_DIRECTIVE "stopPushed"
MoonlightInstance* g_Instance;
@ -62,13 +71,36 @@ void* MoonlightInstance::ConnectionThreadFunc(void* context) {
return NULL;
}
// hook from javascript into the CPP code.
void MoonlightInstance::HandleMessage(const pp::Var& var_message) {
// Ignore the message if it is not a string.
if (!var_message.is_string())
return;
return; // Ignore the message if it is not a string.
std::string message = var_message.AsString();
std::string host = var_message.AsString();
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);
} else if (strncmp(message.c_str(), STOP_DIRECTIVE, strlen(STOP_DIRECTIVE)) == 0) {
handleStopStream(message);
} else {
// :(
}
}
void MoonlightInstance::handlePair(std::string pairMessage) {
std::string intendedHost = pairMessage.substr(pairMessage.find(PAIR_DIRECTIVE) + strlen(PAIR_DIRECTIVE));
}
void MoonlightInstance::handleShowGames(std::string showGamesMessage) {
std::string host = showGamesMessage.substr(showGamesMessage.find(SHOW_GAMES_DIRECTIVE) + strlen(SHOW_GAMES_DIRECTIVE));
}
void MoonlightInstance::handleStartStream(std::string startStreamMessage) {
// Populate the stream configuration
LiInitializeStreamConfiguration(&s_StreamConfig);
s_StreamConfig.width = 1280;
@ -79,10 +111,13 @@ void MoonlightInstance::HandleMessage(const pp::Var& var_message) {
s_StreamConfig.streamingRemotely = 0;
s_StreamConfig.audioConfiguration = AUDIO_CONFIGURATION_STEREO;
// Store the host
host = host.substr(host.find(":") + 1);
// Store the host, which is between two colons
std::string host = startStreamMessage.substr(strlen(START_STREAM_DIRECTIVE), startStreamMessage.substr(strlen(START_STREAM_DIRECTIVE)).find(":") + 1);
strcpy(s_Host, host.c_str());
// store the gameID to start, which is after the last colon
std::string gameID = startStreamMessage.substr(startStreamMessage.find(host) + host.length() + 1); // +1 for the colon delimiter
// Post a status update before we begin
pp::Var response("Starting connection...");
PostMessage(response);
@ -92,6 +127,10 @@ void MoonlightInstance::HandleMessage(const pp::Var& var_message) {
pthread_create(&t, NULL, MoonlightInstance::ConnectionThreadFunc, this);
}
void MoonlightInstance::handleStopStream(std::string stopStreamMessage) {
}
bool MoonlightInstance::Init(uint32_t argc,
const char* argn[],
const char* argv[]) {