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