forked from lieuzhenghong/discord-spatial-layer
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Secret key form * lets hope its not broken this time Co-authored-by: Dexter Leng <dexterlengcs@gmail.com>
- Loading branch information
1 parent
f3c8381
commit d5f20e0
Showing
13 changed files
with
250 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,64 @@ | ||
import main from './runClient'; | ||
import GameClient from './GameClient' | ||
import instantiateClient from './instantiateClient' | ||
|
||
window.onload = function() { | ||
console.log('window loaded') | ||
const secret = 'MAGIC_VALUE'; | ||
main(secret); | ||
const SECRET_KEY_FORM_ID = 'secret-key-form' | ||
|
||
window.onload = function () { | ||
const container = document.getElementById('container') | ||
container.style.height = '100%' | ||
container.style.width = '100%' | ||
container.style.position = 'absolute' | ||
|
||
container.insertAdjacentHTML('beforeend', renderSecretKeyForm()) | ||
} | ||
|
||
function renderSecretKeyForm() { | ||
return ` | ||
<form id="${SECRET_KEY_FORM_ID}"> | ||
<label for="secret-key">Secret Key:</label><br> | ||
<input type="text" id="secret-key" name="secret-key"><br> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
` | ||
} | ||
|
||
let gameClient | ||
|
||
function handleSecretKeyFormSubmit(e) { | ||
const secretKey = document.getElementById('secret-key').value | ||
|
||
instantiateClient(secretKey) | ||
.then(client => { | ||
const canvas = '<canvas id=\'main-canvas\' style="height: 100%; width: 100%"></canvas>' | ||
container.innerText = '' | ||
container.insertAdjacentHTML('beforeend', canvas) | ||
gameClient = new GameClient(client) | ||
let tick = 0 | ||
let previous = performance.now() | ||
const loop = function () { | ||
window.requestAnimationFrame(loop) | ||
const now = performance.now() | ||
const delta = (now - previous) / 1000 | ||
previous = now | ||
tick++ | ||
|
||
gameClient.update(delta, tick, now) | ||
} | ||
|
||
loop() | ||
}) | ||
.catch(res => { | ||
alert('shit secret key') | ||
}) | ||
} | ||
|
||
document.addEventListener('submit', e => { | ||
e.preventDefault() | ||
|
||
const form = e.target | ||
const formId = form.getAttribute('id') | ||
|
||
if (formId === SECRET_KEY_FORM_ID) { | ||
handleSecretKeyFormSubmit(e) | ||
} | ||
}, false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import nengi from 'nengi' | ||
import nengiConfig from '../common/nengiConfig' | ||
|
||
function instantiateClient(secret) { | ||
return new Promise((resolve, reject) => { | ||
const client = new nengi.Client(nengiConfig) | ||
|
||
client.onConnect(res => { | ||
console.log('onConnect response:', res) | ||
if (!res.accepted) { | ||
reject(res) | ||
} else { | ||
resolve(client) | ||
} | ||
}) | ||
|
||
client.connect('ws://localhost:8079', { secret }) | ||
}) | ||
} | ||
|
||
export default instantiateClient |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ const config = { | |
MAP_IMAGE: './images/bg.png', | ||
} | ||
|
||
export default config | ||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
chrome.browserAction.onClicked.addListener(function (tab) { | ||
// for the current tab, inject the "inject.js" file & execute it | ||
chrome.tabs.executeScript(tab.ib, { | ||
file: 'inject.bundle.js' | ||
}); | ||
}); | ||
chrome.browserAction.onClicked.addListener(tab => { | ||
// for the current tab, inject the "inject.js" file & execute it | ||
chrome.tabs.executeScript(tab.ib, { | ||
file: 'inject.bundle.js', | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
var webpack = require("webpack"), | ||
config = require("../webpack.config"); | ||
const webpack = require('webpack') | ||
const config = require('../webpack.config') | ||
|
||
delete config.chromeExtensionBoilerplate; | ||
delete config.chromeExtensionBoilerplate | ||
|
||
webpack( | ||
config, | ||
function (err) { if (err) throw err; } | ||
); | ||
config, | ||
err => { if (err) throw err }, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// tiny wrapper with default env vars | ||
module.exports = { | ||
NODE_ENV: (process.env.NODE_ENV || "development"), | ||
PORT: (process.env.PORT || 3000) | ||
}; | ||
NODE_ENV: (process.env.NODE_ENV || 'development'), | ||
PORT: (process.env.PORT || 3000), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,35 @@ | ||
var WebpackDevServer = require("webpack-dev-server"), | ||
webpack = require("webpack"), | ||
config = require("../webpack.config"), | ||
env = require("./env"), | ||
path = require("path"); | ||
const WebpackDevServer = require('webpack-dev-server') | ||
const webpack = require('webpack') | ||
const path = require('path') | ||
const config = require('../webpack.config') | ||
const env = require('./env') | ||
|
||
var options = (config.chromeExtensionBoilerplate || {}); | ||
var excludeEntriesToHotReload = (options.notHotReload || []); | ||
const options = (config.chromeExtensionBoilerplate || {}) | ||
const excludeEntriesToHotReload = (options.notHotReload || []) | ||
|
||
for (var entryName in config.entry) { | ||
if (excludeEntriesToHotReload.indexOf(entryName) === -1) { | ||
config.entry[entryName] = | ||
[ | ||
("webpack-dev-server/client?http://localhost:" + env.PORT), | ||
"webpack/hot/dev-server" | ||
].concat(config.entry[entryName]); | ||
} | ||
for (const entryName in config.entry) { | ||
if (excludeEntriesToHotReload.indexOf(entryName) === -1) { | ||
config.entry[entryName] = [ | ||
(`webpack-dev-server/client?http://localhost:${env.PORT}`), | ||
'webpack/hot/dev-server', | ||
].concat(config.entry[entryName]) | ||
} | ||
} | ||
|
||
config.plugins = | ||
[new webpack.HotModuleReplacementPlugin()].concat(config.plugins || []); | ||
config.plugins = [new webpack.HotModuleReplacementPlugin()].concat(config.plugins || []) | ||
|
||
delete config.chromeExtensionBoilerplate; | ||
delete config.chromeExtensionBoilerplate | ||
|
||
var compiler = webpack(config); | ||
const compiler = webpack(config) | ||
|
||
var server = | ||
new WebpackDevServer(compiler, { | ||
const server = new WebpackDevServer(compiler, { | ||
hot: true, | ||
contentBase: path.join(__dirname, "../build"), | ||
contentBase: path.join(__dirname, '../build'), | ||
sockPort: env.PORT, | ||
headers: { | ||
"Access-Control-Allow-Origin": "*" | ||
'Access-Control-Allow-Origin': '*', | ||
}, | ||
disableHostCheck: true | ||
}); | ||
disableHostCheck: true, | ||
}) | ||
|
||
server.listen(env.PORT); | ||
server.listen(env.PORT) |
Oops, something went wrong.