ProtocolClient -> SocketClient
This commit is contained in:
parent
aa731bdc89
commit
6dc7f21555
|
@ -29,12 +29,12 @@ import store from './ui/store';
|
||||||
import renderApp from './components/App';
|
import renderApp from './components/App';
|
||||||
|
|
||||||
import { initRenderer, getRenderer } from './ui/renderer';
|
import { initRenderer, getRenderer } from './ui/renderer';
|
||||||
import ProtocolClient from './socket/ProtocolClient';
|
import SocketClient from './socket/SocketClient';
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
initRenderer(store, false);
|
initRenderer(store, false);
|
||||||
|
|
||||||
ProtocolClient.on('pixelUpdate', ({
|
SocketClient.on('pixelUpdate', ({
|
||||||
i, j, pixels,
|
i, j, pixels,
|
||||||
}) => {
|
}) => {
|
||||||
pixels.forEach((pxl) => {
|
pixels.forEach((pxl) => {
|
||||||
|
@ -43,18 +43,18 @@ function init() {
|
||||||
receivePixelUpdate(store, i, j, offset, color & 0x7F);
|
receivePixelUpdate(store, i, j, offset, color & 0x7F);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
ProtocolClient.on('pixelReturn', ({
|
SocketClient.on('pixelReturn', ({
|
||||||
retCode, wait, coolDownSeconds, pxlCnt,
|
retCode, wait, coolDownSeconds, pxlCnt,
|
||||||
}) => {
|
}) => {
|
||||||
receivePixelReturn(store, retCode, wait, coolDownSeconds, pxlCnt);
|
receivePixelReturn(store, retCode, wait, coolDownSeconds, pxlCnt);
|
||||||
});
|
});
|
||||||
ProtocolClient.on('cooldownPacket', (coolDown) => {
|
SocketClient.on('cooldownPacket', (coolDown) => {
|
||||||
store.dispatch(receiveCoolDown(coolDown));
|
store.dispatch(receiveCoolDown(coolDown));
|
||||||
});
|
});
|
||||||
ProtocolClient.on('onlineCounter', (online) => {
|
SocketClient.on('onlineCounter', (online) => {
|
||||||
store.dispatch(receiveOnline(online));
|
store.dispatch(receiveOnline(online));
|
||||||
});
|
});
|
||||||
ProtocolClient.on('chatMessage', (
|
SocketClient.on('chatMessage', (
|
||||||
name,
|
name,
|
||||||
text,
|
text,
|
||||||
country,
|
country,
|
||||||
|
@ -84,13 +84,13 @@ function init() {
|
||||||
!!isRead,
|
!!isRead,
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
ProtocolClient.on('changedMe', () => {
|
SocketClient.on('changedMe', () => {
|
||||||
store.dispatch(fetchMe());
|
store.dispatch(fetchMe());
|
||||||
});
|
});
|
||||||
ProtocolClient.on('remch', (cid) => {
|
SocketClient.on('remch', (cid) => {
|
||||||
store.dispatch(removeChatChannel(cid));
|
store.dispatch(removeChatChannel(cid));
|
||||||
});
|
});
|
||||||
ProtocolClient.on('addch', (channel) => {
|
SocketClient.on('addch', (channel) => {
|
||||||
store.dispatch(addChatChannel(channel));
|
store.dispatch(addChatChannel(channel));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ function init() {
|
||||||
store.dispatch(initTimer());
|
store.dispatch(initTimer());
|
||||||
|
|
||||||
store.dispatch(fetchMe());
|
store.dispatch(fetchMe());
|
||||||
ProtocolClient.connect();
|
SocketClient.connect();
|
||||||
|
|
||||||
store.dispatch(fetchStats());
|
store.dispatch(fetchStats());
|
||||||
// TODO: We don't have to do this this often
|
// TODO: We don't have to do this this often
|
||||||
|
@ -144,7 +144,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
const [zc, xc, yc] = value.cell;
|
const [zc, xc, yc] = value.cell;
|
||||||
if (!renderer.isChunkInView(zc, xc, yc)) {
|
if (!renderer.isChunkInView(zc, xc, yc)) {
|
||||||
if (value.isBasechunk) {
|
if (value.isBasechunk) {
|
||||||
ProtocolClient.deRegisterChunk([xc, yc]);
|
SocketClient.deRegisterChunk([xc, yc]);
|
||||||
}
|
}
|
||||||
chunks.delete(key);
|
chunks.delete(key);
|
||||||
value.destructor();
|
value.destructor();
|
||||||
|
@ -176,7 +176,7 @@ window.onCaptcha = async function onCaptcha(token) {
|
||||||
const {
|
const {
|
||||||
i, j, pixels,
|
i, j, pixels,
|
||||||
} = window.pixel;
|
} = window.pixel;
|
||||||
ProtocolClient.requestPlacePixels(i, j, pixels);
|
SocketClient.requestPlacePixels(i, j, pixels);
|
||||||
|
|
||||||
if (typeof window.hcaptcha !== 'undefined') {
|
if (typeof window.hcaptcha !== 'undefined') {
|
||||||
window.hcaptcha.reset();
|
window.hcaptcha.reset();
|
||||||
|
|
|
@ -21,7 +21,7 @@ import {
|
||||||
showContextMenu,
|
showContextMenu,
|
||||||
setWindowTitle,
|
setWindowTitle,
|
||||||
} from '../../actions';
|
} from '../../actions';
|
||||||
import ProtocolClient from '../../socket/ProtocolClient';
|
import SocketClient from '../../socket/SocketClient';
|
||||||
import splitChatMessage from '../../core/chatMessageFilter';
|
import splitChatMessage from '../../core/chatMessageFilter';
|
||||||
|
|
||||||
function escapeRegExp(string) {
|
function escapeRegExp(string) {
|
||||||
|
@ -100,7 +100,7 @@ const Chat = ({
|
||||||
const msg = inputMessage.trim();
|
const msg = inputMessage.trim();
|
||||||
if (!msg) return;
|
if (!msg) return;
|
||||||
// send message via websocket
|
// send message via websocket
|
||||||
ProtocolClient.sendChatMessage(msg, chatChannel);
|
SocketClient.sendChatMessage(msg, chatChannel);
|
||||||
dispatch(setChatInputMessage(windowId, ''));
|
dispatch(setChatInputMessage(windowId, ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import ChangedMe from './packets/ChangedMe';
|
||||||
|
|
||||||
const chunks = [];
|
const chunks = [];
|
||||||
|
|
||||||
class ProtocolClient extends EventEmitter {
|
class SocketClient extends EventEmitter {
|
||||||
url: string;
|
url: string;
|
||||||
ws: WebSocket;
|
ws: WebSocket;
|
||||||
canvasId: number;
|
canvasId: number;
|
||||||
|
@ -30,7 +30,7 @@ class ProtocolClient extends EventEmitter {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
console.log('creating ProtocolClient');
|
console.log('Creating WebSocketClient');
|
||||||
this.isConnecting = false;
|
this.isConnecting = false;
|
||||||
this.isConnected = false;
|
this.isConnected = false;
|
||||||
this.ws = null;
|
this.ws = null;
|
||||||
|
@ -243,4 +243,4 @@ class ProtocolClient extends EventEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new ProtocolClient();
|
export default new SocketClient();
|
|
@ -5,7 +5,7 @@ import thunk from 'redux-thunk';
|
||||||
import { persistStore } from 'redux-persist';
|
import { persistStore } from 'redux-persist';
|
||||||
|
|
||||||
import audio from './audio';
|
import audio from './audio';
|
||||||
import protocolClientHook from './protocolClientHook';
|
import socketClientHook from './socketClientHook';
|
||||||
import rendererHook from './rendererHook';
|
import rendererHook from './rendererHook';
|
||||||
// import ads from './ads';
|
// import ads from './ads';
|
||||||
import array from './array';
|
import array from './array';
|
||||||
|
@ -28,7 +28,7 @@ const store = createStore(
|
||||||
audio,
|
audio,
|
||||||
notifications,
|
notifications,
|
||||||
title,
|
title,
|
||||||
protocolClientHook,
|
socketClientHook,
|
||||||
rendererHook,
|
rendererHook,
|
||||||
placePixelControl,
|
placePixelControl,
|
||||||
extensions,
|
extensions,
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* @flow
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ProtocolClient from '../socket/ProtocolClient';
|
import SocketClient from '../socket/SocketClient';
|
||||||
|
|
||||||
export default (store) => (next) => (action) => {
|
export default (store) => (next) => (action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
@ -14,14 +14,14 @@ export default (store) => (next) => (action) => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const [, cx, cy] = action.center;
|
const [, cx, cy] = action.center;
|
||||||
ProtocolClient.registerChunk([cx, cy]);
|
SocketClient.registerChunk([cx, cy]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'SET_NAME':
|
case 'SET_NAME':
|
||||||
case 'LOGIN':
|
case 'LOGIN':
|
||||||
case 'LOGOUT': {
|
case 'LOGOUT': {
|
||||||
ProtocolClient.reconnect();
|
SocketClient.reconnect();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ export default (store) => (next) => (action) => {
|
||||||
case 'RECEIVE_ME': {
|
case 'RECEIVE_ME': {
|
||||||
const state = store.getState();
|
const state = store.getState();
|
||||||
const { canvasId } = state.canvas;
|
const { canvasId } = state.canvas;
|
||||||
ProtocolClient.setCanvas(canvasId);
|
SocketClient.setCanvas(canvasId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import {
|
||||||
pixelWait,
|
pixelWait,
|
||||||
updatePixel,
|
updatePixel,
|
||||||
} from '../actions';
|
} from '../actions';
|
||||||
import ProtocolClient from '../socket/ProtocolClient';
|
import SocketClient from '../socket/SocketClient';
|
||||||
|
|
||||||
let pixelTimeout = null;
|
let pixelTimeout = null;
|
||||||
/*
|
/*
|
||||||
|
@ -59,7 +59,7 @@ export function requestFromQueue(store) {
|
||||||
|
|
||||||
lastRequestValues = pixelQueue.shift();
|
lastRequestValues = pixelQueue.shift();
|
||||||
const { i, j, pixels } = lastRequestValues;
|
const { i, j, pixels } = lastRequestValues;
|
||||||
ProtocolClient.requestPlacePixels(i, j, pixels);
|
SocketClient.requestPlacePixels(i, j, pixels);
|
||||||
store.dispatch(setRequestingPixel(false));
|
store.dispatch(setRequestingPixel(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user