JS_WebSocket_Gaming_Project
- [Done] Single client to Single server
- [Done] Using express-ws to activate WebSocket
- [Done] Multiple clients to Single server (broadcast msg to other all clients)
- [Done] Detection of client's disconnection
- [Done] Identification of each client
- [Done] Create database by sql3 & sqlite
- [Done] Read player data from database before starting game
- [Done] Add a status in db to check whether player is been used or not
- [Done] Update db account status if player login
- [Done] Different players have different token while connecting to server (personal account)
- [Done] Update db player status (character, position, direction, ...) if player moves
- [Done] Player's character controls (left, right, up, down)
- [Done] Characters always stay in the center
- [Done] Login page before playing game
- [Done] Body & Item block
- [Done] One client can see player controlled by another client
- [Done] Two client controll different player
- [Done] Three client controll different player by different computer (only three now)
- [Done] Clients login at different time but still having same view (body block & direction)
- In order for npm to manage our modules (create a configuration file named “package.json”)
npm init
- To add a module (create a folder named node_modules)
npm add --save express
npm add express express-ws
- Use npm to install the ws (WebSocket) module and to check WebSocket version
npm install --save ws
npm ls ws
- To run this game, in a terminal placed in the folder where “server.js” is located
node server.js
- To create a database "db.sqlite"
node db.js
- To create initial data in "db.sqlite"
node db_init.js
- If having this problem : An invalid form control with name='xxx' is not focusable, it means that "require" in html element inputbox causes some problmes.
- According to this : window.location.href doesn't redirect, if type of inputbox is "submit", window.location.href won't work. We need to use type "button".
- According to this : How to use a function from another file using require(), because we didn't use module type in our project, we cannot use import/export in our js files, we need to use require()/module.export to implement module concept.
- We had problem of broadcasting while changing module ws to express-ws, but solving by following this : Minimal express-ws broadcast to all clients
- In order to reconnect once client gets valid token from server, we can refresh client website to update url's token by following this : WebSocket: How to automatically reconnect after it dies.
- Because of using async-await function with return value to deal with database, we can create functions in another js files by following this : 彻底搞懂 async await 的return问题. But we didn't really use this kind of function eventually as async-await functions are not used to returning values.
- To connect to server by different computer, we need to change "localhost" to "IPv4 Address" (from Wireless LAN Wi-Fi) in client.js
- According to What is the (function(){})() construct in JavaScript?, we can reload init.js just right after client gets its own id by giving the function in init.js a varable name.
- ws: a node.js websocket library
- WebSocket
- 如何使用JavaScript实现客户端与服务器的websocket通信?
- Node.js WebSocket Tutorial - Real-Time Chat Room using Multiple Clients
- nodejs websocket detect disconnected socket
- unique identifier for each client request to websocket server #859
- Express 实战: 使用 express-ws 实现 WebSocket 协议
- express-ws实现WebSocket
- express-ws
- Node.js — 從一個實例看Express 的運作方式
- Sequelize tutorial
- JavaScript Add to List : examples