mirror of
https://github.com/moonlight-stream/moonlight-chrome.git
synced 2025-08-17 08:36:42 +00:00
refactored HTML button hooks
moved status messages to new field
This commit is contained in:
parent
8713d261aa
commit
3cfeca7d92
@ -12,12 +12,14 @@
|
|||||||
<div id="title">
|
<div id="title">
|
||||||
<h1>Moonlight Streaming</h1>
|
<h1>Moonlight Streaming</h1>
|
||||||
<h2>Chrome App Status: <code id="statusField">NO-STATUS</code></h2>
|
<h2>Chrome App Status: <code id="statusField">NO-STATUS</code></h2>
|
||||||
|
<p></p>
|
||||||
|
<code id="logField">log</code>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>Enter the IP/hostname of the GFE streaming computer, or select one from the history:</p>
|
<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">
|
<input type="text" size="15" id="GFEHostIPField" value="127.0.0.1">
|
||||||
|
|
||||||
<select>
|
<select id="selectHost">
|
||||||
<option value="">No history available</option>
|
<option value="">No history available</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
@ -35,7 +37,7 @@
|
|||||||
|
|
||||||
<div hidden id="gameSelectionDiv">
|
<div hidden id="gameSelectionDiv">
|
||||||
<p>Select a game to run</p>
|
<p>Select a game to run</p>
|
||||||
<select>
|
<select id="selectGame">
|
||||||
<option value="game_id_1">Game Name 1</option>
|
<option value="game_id_1">Game Name 1</option>
|
||||||
<option value="game_id_2">Game Name 2</option>
|
<option value="game_id_2">Game Name 2</option>
|
||||||
<option value="game_id_3">Game Name 3</option>
|
<option value="game_id_3">Game Name 3</option>
|
||||||
|
27
index.js
27
index.js
@ -6,25 +6,44 @@ function attachListeners() {
|
|||||||
document.getElementById('showAppsButton').addEventListener('click', showAppsPushed);
|
document.getElementById('showAppsButton').addEventListener('click', showAppsPushed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pair button was pushed. pass what the user entered into the GFEHostIPField.
|
||||||
function pairPushed() {
|
function pairPushed() {
|
||||||
common.naclModule.postMessage('pair:' + document.getElementById('GFEHostIPField').value);
|
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() {
|
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";
|
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() {
|
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() {
|
function stopPushed() {
|
||||||
common.naclModule.postMessage('stopPushed');
|
common.naclModule.postMessage('stopPushed');
|
||||||
}
|
}
|
||||||
|
|
||||||
// hook from main.cpp into the javascript
|
// hook from main.cpp into the javascript
|
||||||
function handleMessage(msg) {
|
function handleMessage(msg) {
|
||||||
var logEl = document.getElementById('GFEHostIPField');
|
var logEl = document.getElementById('logField');
|
||||||
logEl.value = msg.data;
|
logEl.innerHTML = msg.data;
|
||||||
}
|
}
|
||||||
|
49
main.cpp
49
main.cpp
@ -2,11 +2,20 @@
|
|||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "ppapi/cpp/input_event.h"
|
#include "ppapi/cpp/input_event.h"
|
||||||
|
|
||||||
static char s_Host[256];
|
static char s_Host[256];
|
||||||
static STREAM_CONFIGURATION s_StreamConfig;
|
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;
|
MoonlightInstance* g_Instance;
|
||||||
|
|
||||||
@ -62,13 +71,36 @@ void* MoonlightInstance::ConnectionThreadFunc(void* context) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
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
|
// Populate the stream configuration
|
||||||
LiInitializeStreamConfiguration(&s_StreamConfig);
|
LiInitializeStreamConfiguration(&s_StreamConfig);
|
||||||
s_StreamConfig.width = 1280;
|
s_StreamConfig.width = 1280;
|
||||||
@ -79,10 +111,13 @@ void MoonlightInstance::HandleMessage(const pp::Var& var_message) {
|
|||||||
s_StreamConfig.streamingRemotely = 0;
|
s_StreamConfig.streamingRemotely = 0;
|
||||||
s_StreamConfig.audioConfiguration = AUDIO_CONFIGURATION_STEREO;
|
s_StreamConfig.audioConfiguration = AUDIO_CONFIGURATION_STEREO;
|
||||||
|
|
||||||
// Store the host
|
// Store the host, which is between two colons
|
||||||
host = host.substr(host.find(":") + 1);
|
std::string host = startStreamMessage.substr(strlen(START_STREAM_DIRECTIVE), startStreamMessage.substr(strlen(START_STREAM_DIRECTIVE)).find(":") + 1);
|
||||||
strcpy(s_Host, host.c_str());
|
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
|
// Post a status update before we begin
|
||||||
pp::Var response("Starting connection...");
|
pp::Var response("Starting connection...");
|
||||||
PostMessage(response);
|
PostMessage(response);
|
||||||
@ -92,6 +127,10 @@ void MoonlightInstance::HandleMessage(const pp::Var& var_message) {
|
|||||||
pthread_create(&t, NULL, MoonlightInstance::ConnectionThreadFunc, this);
|
pthread_create(&t, NULL, MoonlightInstance::ConnectionThreadFunc, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MoonlightInstance::handleStopStream(std::string stopStreamMessage) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool MoonlightInstance::Init(uint32_t argc,
|
bool MoonlightInstance::Init(uint32_t argc,
|
||||||
const char* argn[],
|
const char* argn[],
|
||||||
const char* argv[]) {
|
const char* argv[]) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user