Compare commits

..

9 Commits

Author SHA1 Message Date
Kayne Ruse 95d229c561 Bumped version number 2022-01-03 08:31:56 +00:00
Kayne Ruse 0b1456ebde Merge branch 'timestamps' 2022-01-03 08:30:23 +00:00
Kayne Ruse bd5b6e8233 Added async keyword 2022-01-03 08:30:03 +00:00
Keith Campbell 05eecf8bdd removed everything but lines 50-60 2022-01-02 18:35:50 -05:00
Keith Campbell 2aedb6e938 ready for PR/review 2022-01-02 18:00:16 -05:00
Keith Campbell ab73d05471 updated original code, using createdAt from log 2022-01-01 21:45:09 -05:00
Keith Campbell f72b0e5522 added timestamp to messages and logs, need to test 2022-01-01 17:11:11 -05:00
Kayne Ruse 900312752b Cleaning up tools 2021-12-23 14:00:47 +00:00
Kayne Ruse 1b2868d68f Updated README.md 2021-12-21 19:38:08 +00:00
6 changed files with 16 additions and 10 deletions
+2
View File
@@ -2,6 +2,8 @@
An API centric chat server. Uses Sequelize and mariaDB by default. An API centric chat server. Uses Sequelize and mariaDB by default.
This server is available via docker hub at krgamestudios/chat-server.
# Setup # Setup
There are multiple ways to run this app - it can run on it's own via `npm start` (for production) or `npm run dev` (for development). it can also run inside docker using `docker-compose up --build` - run `node configure-script.js` to generate docker-compose.yml and startup.sql. There are multiple ways to run this app - it can run on it's own via `npm start` (for production) or `npm run dev` (for development). it can also run inside docker using `docker-compose up --build` - run `node configure-script.js` to generate docker-compose.yml and startup.sql.
+1 -1
View File
@@ -33,7 +33,7 @@ const question = (prompt, def = null) => {
const appPort = await question('App Port', '3300'); const appPort = await question('App Port', '3300');
const appDBUser = await question('DB User', appName); const appDBUser = await question('DB User', appName);
const appDBPass = await question('DB Pass', uuid()); const appDBPass = await question('DB Pass', 'blastoise');
const dbRootPass = await question('DB Root Pass'); const dbRootPass = await question('DB Root Pass');
const appSecretAccess = await question('Access Token Secret', uuid(32)); const appSecretAccess = await question('Access Token Secret', uuid(32));
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "chat-server", "name": "chat-server",
"version": "1.2.4", "version": "1.2.5",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "chat-server", "name": "chat-server",
"version": "1.2.4", "version": "1.2.5",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"cors": "^2.8.5", "cors": "^2.8.5",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "chat-server", "name": "chat-server",
"version": "1.2.4", "version": "1.2.5",
"description": "An API centric chat server. Uses Sequelize and mariaDB by default.", "description": "An API centric chat server. Uses Sequelize and mariaDB by default.",
"main": "server/server.js", "main": "server/server.js",
"scripts": { "scripts": {
+6 -6
View File
@@ -35,7 +35,7 @@ const chat = io => {
}); });
//from here, handles all normal messages //from here, handles all normal messages
socket.on('open chat', message => { socket.on('open chat', async message => {
//handle rooms - only in a room if you've opened chat //handle rooms - only in a room if you've opened chat
const newlyOpened = !socket.user.room; const newlyOpened = !socket.user.room;
socket.user.room = socket.user.room || 'general'; //default to general socket.user.room = socket.user.room || 'general'; //default to general
@@ -46,11 +46,8 @@ const chat = io => {
socket.join(socket.user.room); socket.join(socket.user.room);
//broadcast to this room
socket.broadcast.to(socket.user.room).emit('message', { emphasis: true, text: `${socket.user.username} entered chat` });
//log //log
chatlog.create({ const log = await chatlog.create({
notification: true, notification: true,
username: socket.user.username, username: socket.user.username,
text: `${socket.user.username} entered chat`, text: `${socket.user.username} entered chat`,
@@ -58,6 +55,9 @@ const chat = io => {
emphasis: true emphasis: true
}); });
//broadcast to this room
socket.broadcast.to(socket.user.room).emit('message', {timestamp: log.createdAt, emphasis: true, text: `${socket.user.username} entered chat` });
//send backlog to the user //send backlog to the user
chatlog.findAll({ chatlog.findAll({
where: { where: {
@@ -120,7 +120,7 @@ const chat = io => {
socket.broadcast.to(socket.user.room).emit('message', log); socket.broadcast.to(socket.user.room).emit('message', log);
}); });
socket.on('disconnect', reason => { socket.on('disconnect', async reason => {
//broadcast to this room //broadcast to this room
if (!socket.user) { if (!socket.user) {
return; return;
+4
View File
@@ -0,0 +1,4 @@
#use this while debugging
CREATE DATABASE IF NOT EXISTS chat;
CREATE USER IF NOT EXISTS 'chat'@'%' IDENTIFIED BY 'blastoise';
GRANT ALL PRIVILEGES ON chat.* TO 'chat'@'%';