Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Https Server #16

Merged
merged 3 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions core/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ module.exports = async function(arg) {
return;
}

global.electron = require('electron').remote;
global.app = electron.app;
global.dialog = {};

dialog.select = async function(opt) {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
"ws": "^8.1.0"
},
"description": "Maps the right stick to motion controls for Cemu.",
"devDependencies": {},
"devDependencies": {
"electron": "^24.4.0",
"electron-builder": "^23.6.0"
},
"entry point": "app.js",
"homepage": "https://github.com/quinton-ashley/cemu-no-gyro#readme",
"keywords": [
Expand Down
53 changes: 53 additions & 0 deletions views/js/cert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const cert = `-----BEGIN CERTIFICATE-----
MIIDazCCAlOgAwIBAgIUF8tP4yWAQG7snBUeIYoCOmFOfOwwDQYJKoZIhvcNAQEL
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMzA1MjcyMDQ5NDlaFw0yMzA2
MjYyMDQ5NDlaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw
HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggEiMA0GCSqGSIb3DQEB
AQUAA4IBDwAwggEKAoIBAQCXkOmGLY4W9QNU2vH5a6zHPVq6J19LS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oGAU6TI
DzoRTXoCwzTfmBaIlbwedb3dk7MDi9GerLfAzBsTbzUh03qKF1Qa69UWhbXbV/eM
48YpxG7UG1Q8OMdKVP15f7S2DfodV/T4ip50gn9gtPPbk4r9+GgMdIVEcotUJAiX
vmnEkFcGm/bP2pX93DoOfWM0QKFyTX3fFBJBsCkCgYBkB6XTJBQwNPmZO5pMdv1k
xzFf+JH6SetR5uY3e0B5BIMZS6V3PDOHejQ5Nt5rKeHw2YsRQ4+mmZZeIblHA6JB
lBJHLv9eizrR/CG/TRCwPCNzXhpqBm5AhLduhrjkoB2eNyLzb7hcEWGL01OKP8+h
v1ruIXsnBgWDNZb65KUVCg==
-----END PRIVATE KEY-----
`

module.exports = {key, cert}
2 changes: 1 addition & 1 deletion views/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function screenChange(val) {
}
var time = 0;
var bar = window.location.href;
var wsAddress = `ws://${bar.match(/^https?:\/\/([^:]+).+$/)[1]}:1337`;
var wsAddress = `wss://${bar.match(/^https?:\/\/([^:]+).+$/)[1]}:8443/wss`;
console.log(wsAddress);
var ws = new WebSocket(wsAddress);
ws.onopen = function(ws_evnt) {
Expand Down
58 changes: 27 additions & 31 deletions views/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = async function (arg) {
const { Mouse, Keyboard, Gamepad, or, and } = require('contro');
let gamepad = new Gamepad();

const http = require('http');
const WebSocket = require('ws');

let btnNames = ['lt', 'rt'];
Expand Down Expand Up @@ -60,7 +59,7 @@ module.exports = async function (arg) {
$('#gyroY').on('click', toggleAxis);
$('#gyroZ').on('click', toggleAxis);

function toggleControls() {
function toggleControls() {f
let $btn = $(this);
let axis = $btn.attr('id')[6].toLowerCase();
$btn.toggleClass('enabled');
Expand Down Expand Up @@ -156,35 +155,10 @@ module.exports = async function (arg) {

loop();

const wss = new WebSocket.Server({
port: 1337,
});

wss.on('connection', function connection(ws) {
log('WS Connected');
phoneIsConnected = true;
$('#phoneIndicator').text('Phone connected!');
ws.on('message', function incoming(message) {
// log(message);
data = JSON.parse(message);
gyroServer.sendMotionData(data.gyro, null, data.ts);
});
ws.on('error', () => {
phoneIsConnected = false;
log('WS ERROR');
});
ws.on('close', () => {
phoneIsConnected = false;
log('WS Disconnected');
$('#phoneIndicator').text('Phone disconnected');
});
});

/////////////////////////////////////////////////

let express = require('express');
let xps = express();

// set up the template engine
xps.set('views', __root + '/views');
xps.set('view engine', 'pug');
Expand All @@ -194,9 +168,10 @@ module.exports = async function (arg) {
xps.get('/', function (req, res) {
res.render('pug/client');
});

// start up the server
xps.listen(8080, function () {
const https = require("https");
const httpsOptions = require('./cert');
const server = https.createServer(httpsOptions, xps);
server.listen(8443, function () {
log(`
## Usage
1. Run Cemu.exe and Checked Options->GamePad mation source->DSU1->By Slot
Expand All @@ -208,13 +183,34 @@ module.exports = async function (arg) {
interfaces[k][i].family == 'IPv4' &&
interfaces[k][i].address != '127.0.0.1'
) {
let url = 'http://' + interfaces[k][i].address + ':8080';
let url = 'https://' + interfaces[k][i].address + ':8443';
log(url);
$('#phoneURL').text($('#phoneURL').text() + url + ' ');
}
}
}
});
const wss = new WebSocket.Server({server, path: '/wss'});
wss.on('connection', function connection(ws) {
log('WS Connected');
phoneIsConnected = true;
$('#phoneIndicator').text('Phone connected!');
ws.on('message', function incoming(message) {
// log(message);
data = JSON.parse(message);
gyroServer.sendMotionData(data.gyro, null, data.ts);
});
ws.on('error', () => {
phoneIsConnected = false;
log('WS ERROR');
});
ws.on('close', () => {
phoneIsConnected = false;
log('WS Disconnected');
$('#phoneIndicator').text('Phone disconnected');
});
});


require('process').on('uncaughtException', function (err) {
log(err);
Expand Down