ProtocolClient -> SocketClient

This commit is contained in:
HF 2022-01-12 01:58:08 +01:00
parent aa731bdc89
commit 6dc7f21555
6 changed files with 25 additions and 25 deletions

View File

@ -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();

View File

@ -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, ''));
}

View File

@ -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();

View File

@ -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,

View File

@ -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;
}

View File

@ -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));
}