rework rpc

This commit is contained in:
ntr
2018-10-08 23:26:28 +11:00
parent c950a0a866
commit 4d862a7900
7 changed files with 165 additions and 134 deletions
-1
View File
@@ -33,7 +33,6 @@ function CrypPanel({ cryps, sendCombatPve }) {
<div>
<a className="button is-large is-fullwidth">
<span>Spawn 👾</span>
<span className="icon is-medium"><i className="fab fa-plus"></i></span>
</a>
{crypPanels}
</div>
+1
View File
@@ -26,6 +26,7 @@ store.subscribe(() => console.log(store.getState()));
const ws = createSocket(store);
store.dispatch(actions.setWs(ws));
ws.connect();
// tells jdenticon to look for new svgs and render them
// so we don't have to setInnerHtml or manually call update
+29 -20
View File
@@ -16,8 +16,34 @@ function errorToast(err) {
// requires the redux store in order to push updates
// to components
function createSocket(store) {
const ws = new WebSocket('ws://localhost:40000');
ws.binaryType = 'arraybuffer';
let ws;
function connect() {
ws = new WebSocket('ws://localhost:40000');
ws.binaryType = 'arraybuffer';
// Connection opened
ws.addEventListener('open', function wsOpen(event) {
send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } });
});
// Listen for messages
ws.addEventListener('message', onMessage);
ws.addEventListener('error', function wsError(event) {
console.error('WebSocket error', event);
account = null;
// return setTimeout(connect, 5000);
});
ws.addEventListener('close', function wsClose(event) {
console.error('WebSocket closed', event);
account = null;
return setTimeout(connect, 5000);
});
return ws;
}
// handle account auth within the socket itself
// https://www.christian-schneider.net/CrossSiteWebSocketHijacking.html
@@ -103,27 +129,10 @@ function createSocket(store) {
return handlers[method](params);
}
// Connection opened
ws.addEventListener('open', function wsOpen(event) {
send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } });
});
// Listen for messages
ws.addEventListener('message', onMessage);
ws.addEventListener('error', function wsError(event) {
console.error('WebSocket error', event);
account = null;
});
ws.addEventListener('close', function wsClose(event) {
console.error('WebSocket closed', event);
account = null;
});
return {
sendAccountLogin,
sendCombatPve,
connect,
};
}