notherbase-fs 1.4.4 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/controllers/authCheck.js +2 -2
- package/controllers/contact.js +3 -3
- package/controllers/explorer.js +139 -172
- package/controllers/game.js +3 -4
- package/controllers/index.js +10 -12
- package/controllers/inventory.js +4 -5
- package/controllers/item.js +3 -4
- package/controllers/pages.js +29 -32
- package/controllers/the-front.js +62 -68
- package/controllers/user.js +6 -7
- package/controllers/void.js +16 -0
- package/models/chat.js +4 -4
- package/models/contact.js +4 -7
- package/models/detail.js +4 -7
- package/models/game.js +4 -7
- package/models/index.js +40 -11
- package/models/inventory.js +4 -7
- package/models/item.js +4 -7
- package/models/page.js +4 -4
- package/models/send-mail.js +3 -5
- package/models/user.js +3 -4
- package/notherbase-fs.js +101 -76
- package/package.json +8 -3
- package/public/js/chat-box.js +39 -25
- package/public/styles/chat.css +13 -16
- package/test/coast/tall-beach/nono-cove/views/index.ejs +11 -8
- package/test/test-index.js +4 -3
- package/views/explorer.ejs +1 -0
- package/controllers/chat.js +0 -28
- package/controllers/portfolio/models/projects.js +0 -16
- package/controllers/portfolio/views/index.ejs +0 -234
- package/controllers/portfolio/views/parts/tamago.ejs +0 -534
- package/models/start-mongoose.js +0 -36
package/controllers/user.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import express from "express";
|
|
2
2
|
const router = express.Router();
|
|
3
|
-
|
|
3
|
+
import bcrypt from "bcrypt";
|
|
4
4
|
|
|
5
5
|
// Import my Data
|
|
6
|
-
|
|
6
|
+
import { user, inventory, sendMail } from "../models/index.js";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
import authCheck from "./authCheck.js";
|
|
9
9
|
|
|
10
10
|
let getAttributes = async function getAttributes(userID) {
|
|
11
11
|
try {
|
|
@@ -71,7 +71,7 @@ router.post("/logout", authCheck, async function(req, res) {
|
|
|
71
71
|
|
|
72
72
|
router.get("/all", async function(req, res) {
|
|
73
73
|
try {
|
|
74
|
-
let foundUsers = await user.find({}, 'username coin home authLevels location attributes');
|
|
74
|
+
let foundUsers = await user.find({}, 'username coin home authLevels location attributes email');
|
|
75
75
|
|
|
76
76
|
res.status(200).send({ foundUsers: foundUsers });
|
|
77
77
|
}
|
|
@@ -410,5 +410,4 @@ router.delete("/", authCheck, async function(req, res) {
|
|
|
410
410
|
}
|
|
411
411
|
});
|
|
412
412
|
|
|
413
|
-
|
|
414
|
-
|
|
413
|
+
export default router;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
let router = express.Router();
|
|
3
|
+
|
|
4
|
+
//the void
|
|
5
|
+
router.use(function(req, res){
|
|
6
|
+
res.render(`explorer`,
|
|
7
|
+
{
|
|
8
|
+
siteTitle: "NotherBase | The Void",
|
|
9
|
+
user: null,
|
|
10
|
+
inventory: null,
|
|
11
|
+
main: `${req.voidDir}/index`,
|
|
12
|
+
route: `/void`
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export default router;
|
package/models/chat.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const chat = mongoose.model('chats', new mongoose.Schema({
|
|
4
4
|
name: String,
|
|
5
5
|
text: String,
|
|
6
6
|
date: Number
|
|
7
|
-
});
|
|
7
|
+
}));
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
export default chat;
|
package/models/contact.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
const mongoose = require("mongoose");
|
|
1
|
+
import mongoose from "mongoose";
|
|
3
2
|
|
|
4
3
|
// This shows the kind of documents we're interacting with in the db
|
|
5
|
-
const contact = new mongoose.Schema({
|
|
4
|
+
const contact = mongoose.model('contacts', new mongoose.Schema({
|
|
6
5
|
user: {
|
|
7
6
|
type: mongoose.Schema.Types.ObjectId,
|
|
8
7
|
ref: "users",
|
|
@@ -10,8 +9,6 @@ const contact = new mongoose.Schema({
|
|
|
10
9
|
},
|
|
11
10
|
location: String,
|
|
12
11
|
content: String
|
|
13
|
-
});
|
|
12
|
+
}));
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
// in our db and then exports the model so we can use it.
|
|
17
|
-
module.exports = mongoose.model('contacts', contact);
|
|
14
|
+
export default contact;
|
package/models/detail.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
const mongoose = require("mongoose");
|
|
1
|
+
import mongoose from "mongoose";
|
|
3
2
|
|
|
4
|
-
const detail = new mongoose.Schema({
|
|
3
|
+
const detail = mongoose.model('details', new mongoose.Schema({
|
|
5
4
|
_lastUpdate: Number,
|
|
6
5
|
route: String,
|
|
7
6
|
service: String,
|
|
@@ -12,8 +11,6 @@ const detail = new mongoose.Schema({
|
|
|
12
11
|
required: false
|
|
13
12
|
},
|
|
14
13
|
data: {}
|
|
15
|
-
});
|
|
14
|
+
}));
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
// in our db and then exports the model so we can use it.
|
|
19
|
-
module.exports = mongoose.model('details', detail);
|
|
16
|
+
export default detail;
|
package/models/game.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const mongoose = require("mongoose");
|
|
1
|
+
import mongoose from "mongoose";
|
|
3
2
|
|
|
4
|
-
const game = new mongoose.Schema({
|
|
3
|
+
const game = mongoose.model('games', new mongoose.Schema({
|
|
5
4
|
name: String,
|
|
6
5
|
data: {}
|
|
7
|
-
});
|
|
6
|
+
}));
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
// in our db and then exports the model so we can use it.
|
|
11
|
-
module.exports = mongoose.model('games', game);
|
|
8
|
+
export default game;
|
package/models/index.js
CHANGED
|
@@ -1,12 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
import dotenv from "dotenv";
|
|
3
|
+
dotenv.config();
|
|
4
|
+
|
|
5
|
+
mongoose.connection.on('connected', (err) => {
|
|
6
|
+
console.log(`Mongoose connected to db`);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
mongoose.connection.on('error', (err) => {
|
|
10
|
+
console.log(`Mongoose ${err}`);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
mongoose.connection.on('disconnected', () => {
|
|
14
|
+
console.log('Mongoose disconnected');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
let connectionSuccess = false;
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
mongoose.connect(process.env.MONGODB_URI, {
|
|
21
|
+
useNewUrlParser: true,
|
|
22
|
+
useUnifiedTopology: true
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
connectionSuccess = true;
|
|
12
26
|
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.log(`Mongoose on connect: ${err}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export {default as chat} from "./chat.js";
|
|
33
|
+
export {default as item} from "./item.js";
|
|
34
|
+
export {default as user} from "./user.js";
|
|
35
|
+
export {default as contact} from "./contact.js";
|
|
36
|
+
export {default as inventory} from "./inventory.js";
|
|
37
|
+
export {default as game} from "./game.js";
|
|
38
|
+
export {default as sendMail} from "./send-mail.js";
|
|
39
|
+
export {default as detail} from "./detail.js";
|
|
40
|
+
export {default as page} from "./page.js";
|
|
41
|
+
export { connectionSuccess };
|
package/models/inventory.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
const mongoose = require("mongoose");
|
|
1
|
+
import mongoose from "mongoose";
|
|
3
2
|
|
|
4
3
|
// This shows the kind of documents we're interacting with in the db
|
|
5
|
-
const inventory = new mongoose.Schema({
|
|
4
|
+
const inventory = mongoose.model('inventories', new mongoose.Schema({
|
|
6
5
|
user: {
|
|
7
6
|
type: mongoose.Schema.Types.ObjectId,
|
|
8
7
|
ref: "users",
|
|
@@ -15,8 +14,6 @@ const inventory = new mongoose.Schema({
|
|
|
15
14
|
},
|
|
16
15
|
amount: Number
|
|
17
16
|
}]
|
|
18
|
-
});
|
|
17
|
+
}));
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
// in our db and then exports the model so we can use it.
|
|
22
|
-
module.exports = mongoose.model('inventories', inventory);
|
|
19
|
+
export default inventory;
|
package/models/item.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
const mongoose = require("mongoose");
|
|
1
|
+
import mongoose from "mongoose";
|
|
3
2
|
|
|
4
|
-
const item = new mongoose.Schema({
|
|
3
|
+
const item = mongoose.model('items', new mongoose.Schema({
|
|
5
4
|
name: String,
|
|
6
5
|
shortDescription: String,
|
|
7
6
|
fullDescription: String,
|
|
8
7
|
icon: String,
|
|
9
8
|
tags: [ String ],
|
|
10
9
|
image: String
|
|
11
|
-
});
|
|
10
|
+
}));
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
// in our db and then exports the model so we can use it.
|
|
15
|
-
module.exports = mongoose.model('items', item);
|
|
12
|
+
export default item;
|
package/models/page.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
2
|
|
|
3
|
-
const page = new mongoose.Schema({
|
|
3
|
+
const page = mongoose.model('pages', new mongoose.Schema({
|
|
4
4
|
name: String,
|
|
5
5
|
type: String,
|
|
6
6
|
user: {
|
|
@@ -9,6 +9,6 @@ const page = new mongoose.Schema({
|
|
|
9
9
|
required: false
|
|
10
10
|
},
|
|
11
11
|
data: {}
|
|
12
|
-
});
|
|
12
|
+
}));
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
export default page;
|
package/models/send-mail.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import nodemailer from "nodemailer";
|
|
2
2
|
|
|
3
3
|
const passwordReset = async (toEmail, resetToken) => {
|
|
4
4
|
var transporter = nodemailer.createTransport({
|
|
@@ -42,7 +42,5 @@ const send = async (toEmail, subject, html) => {
|
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
send: send
|
|
48
|
-
};
|
|
45
|
+
|
|
46
|
+
export default { passwordReset, send };
|
package/models/user.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
2
|
|
|
3
3
|
//convert schema to model
|
|
4
|
-
const user = mongoose.model('users',
|
|
5
|
-
new mongoose.Schema({
|
|
4
|
+
const user = mongoose.model('users', new mongoose.Schema({
|
|
6
5
|
username: String,
|
|
7
6
|
password: String,
|
|
8
7
|
email: String,
|
|
@@ -23,4 +22,4 @@ const user = mongoose.model('users',
|
|
|
23
22
|
})
|
|
24
23
|
);
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
export default user;
|
package/notherbase-fs.js
CHANGED
|
@@ -1,91 +1,116 @@
|
|
|
1
|
-
|
|
1
|
+
import dotenv from "dotenv";
|
|
2
|
+
dotenv.config();
|
|
3
|
+
import * as db from "./models/index.js";
|
|
4
|
+
import { Server } from "socket.io";
|
|
5
|
+
import express from "express";
|
|
6
|
+
import session from 'express-session';
|
|
7
|
+
import methodOverride from 'method-override';
|
|
8
|
+
import MongoStore from 'connect-mongo';
|
|
9
|
+
import favicon from 'serve-favicon';
|
|
10
|
+
import http from 'http';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
const __dirname = fileURLToPath(new URL('./', import.meta.url));
|
|
2
13
|
|
|
3
|
-
|
|
4
|
-
constructor() {
|
|
5
|
-
this.express = require("express");
|
|
6
|
-
this.session = require('express-session');
|
|
7
|
-
this.methodOverride = require('method-override');
|
|
8
|
-
this.MongoStore = require('connect-mongo');
|
|
9
|
-
this.favicon = require('serve-favicon');
|
|
10
|
-
this.http = require('http');
|
|
11
|
-
this.app = this.express();
|
|
12
|
-
this.server = this.http.createServer(this.app);
|
|
13
|
-
this.io = new (require("socket.io").Server)(this.server);
|
|
14
|
-
this.db = require("./models");
|
|
15
|
-
this.started = false;
|
|
16
|
-
}
|
|
14
|
+
import { stripHtml } from "string-strip-html";
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
if (!this.started) {
|
|
20
|
-
//set views path
|
|
21
|
-
this.app.set("view engine", "ejs");
|
|
22
|
-
this.app.set("views", `${__dirname}/views`);
|
|
23
|
-
|
|
24
|
-
// allows us to delete
|
|
25
|
-
this.app.use(this.methodOverride('_method'));
|
|
16
|
+
import * as controllers from "./controllers/index.js";
|
|
26
17
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// sets the favicon image
|
|
35
|
-
this.app.use(this.favicon(__dirname + '/public/img/logo.png'));
|
|
36
|
-
|
|
37
|
-
// Import my Controller
|
|
38
|
-
const controllers = require("./controllers");
|
|
39
|
-
|
|
40
|
-
//enable cookies
|
|
41
|
-
if (this.db.connectionSuccess) {
|
|
42
|
-
this.app.use(this.session({
|
|
43
|
-
store: this.MongoStore.create({ mongoUrl: process.env.MONGODB_URI }),
|
|
44
|
-
secret: process.env.SECRET || "won",
|
|
45
|
-
resave: false,
|
|
46
|
-
saveUninitialized: false
|
|
47
|
-
}));
|
|
48
|
-
|
|
49
|
-
console.log("sessions enabled");
|
|
50
|
-
}
|
|
51
|
-
else console.log("sessions disabled");
|
|
18
|
+
class NotherBaseFS {
|
|
19
|
+
constructor(worldPath, voidPath, frontPath, pagesPath) {
|
|
20
|
+
this.app = express();
|
|
21
|
+
this.server = http.createServer(this.app);
|
|
22
|
+
this.io = new Server(this.server);
|
|
23
|
+
this.db = db;
|
|
52
24
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
25
|
+
//set views path
|
|
26
|
+
this.app.set("view engine", "ejs");
|
|
27
|
+
this.app.set("views", `${__dirname}/views`);
|
|
28
|
+
|
|
29
|
+
// allows us to delete
|
|
30
|
+
this.app.use(methodOverride('_method'));
|
|
31
|
+
|
|
32
|
+
// allows us to use post body data
|
|
33
|
+
this.app.use(express.urlencoded({ extended: true }));
|
|
34
|
+
|
|
35
|
+
// allows us to get static files like css
|
|
36
|
+
this.app.use(express.static('public'));
|
|
37
|
+
this.app.use(express.static(`${__dirname}/public`));
|
|
38
|
+
|
|
39
|
+
// sets the favicon image
|
|
40
|
+
this.app.use(favicon(__dirname + '/public/img/logo.png'));
|
|
41
|
+
|
|
42
|
+
//enable cookies
|
|
43
|
+
if (this.db.connectionSuccess) {
|
|
44
|
+
this.app.use(session({
|
|
45
|
+
store: MongoStore.create({ mongoUrl: process.env.MONGODB_URI }),
|
|
46
|
+
secret: process.env.SECRET,
|
|
47
|
+
resave: false,
|
|
48
|
+
saveUninitialized: false
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
console.log("sessions enabled");
|
|
52
|
+
}
|
|
53
|
+
else console.log("sessions disabled");
|
|
54
|
+
|
|
55
|
+
this.io.on('connection', (socket) => {
|
|
56
|
+
socket.join(socket.handshake.query.room);
|
|
59
57
|
|
|
60
|
-
|
|
58
|
+
this.io.to(socket.handshake.query.room).emit("chat message", {
|
|
59
|
+
name: "Server",
|
|
60
|
+
time: Date.now(),
|
|
61
|
+
text: `${socket.handshake.query.name} has joined the room.`
|
|
61
62
|
});
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this.app.use("/inventory", controllers.authCheck, controllers.inventory);
|
|
72
|
-
|
|
73
|
-
this.app.use("/item", controllers.item);
|
|
64
|
+
socket.on("chat message", (msg) => {
|
|
65
|
+
this.io.to(socket.handshake.query.room).emit("chat message", {
|
|
66
|
+
name: msg.name,
|
|
67
|
+
time: msg.time,
|
|
68
|
+
text: stripHtml(msg.text).result
|
|
69
|
+
});
|
|
70
|
+
});
|
|
74
71
|
|
|
75
|
-
|
|
72
|
+
socket.on('disconnect', () => {
|
|
73
|
+
this.io.to(socket.handshake.query.room).emit("chat message", {
|
|
74
|
+
name: "Server",
|
|
75
|
+
time: Date.now(),
|
|
76
|
+
text: `${socket.handshake.query.name} has left the room.`
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
76
80
|
|
|
77
|
-
|
|
81
|
+
this.app.use((req, res, next) => {
|
|
82
|
+
req.db = this.db;
|
|
83
|
+
req.worldDir = worldPath;
|
|
84
|
+
req.frontDir = frontPath;
|
|
85
|
+
req.pagesDir = pagesPath;
|
|
86
|
+
req.voidDir = voidPath;
|
|
78
87
|
|
|
79
|
-
|
|
88
|
+
next();
|
|
89
|
+
});
|
|
80
90
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
91
|
+
this.app.use("/user", controllers.user);
|
|
92
|
+
|
|
93
|
+
this.app.use("/contact", controllers.contact);
|
|
94
|
+
|
|
95
|
+
this.app.use("/game", controllers.game);
|
|
96
|
+
|
|
97
|
+
this.app.use("/inventory", controllers.authCheck, controllers.inventory);
|
|
98
|
+
|
|
99
|
+
this.app.use("/item", controllers.item);
|
|
100
|
+
|
|
101
|
+
this.app.use("/the-front", controllers.front);
|
|
102
|
+
|
|
103
|
+
this.app.use("/", controllers.authCheck, controllers.explorer);
|
|
104
|
+
|
|
105
|
+
this.app.use("/", controllers.pages);
|
|
85
106
|
|
|
86
|
-
|
|
87
|
-
|
|
107
|
+
this.app.use(controllers.void);
|
|
108
|
+
|
|
109
|
+
this.server.listen(process.env.PORT, function () {
|
|
110
|
+
console.log(`Server started at ${process.env.PORT}`);
|
|
111
|
+
this.started = true;
|
|
112
|
+
});
|
|
88
113
|
}
|
|
89
114
|
}
|
|
90
115
|
|
|
91
|
-
|
|
116
|
+
export default NotherBaseFS;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "notherbase-fs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Functions to help make developing for NotherBase easier.",
|
|
5
|
-
"
|
|
5
|
+
"exports": "./notherbase-fs.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "nodemon test/test-index.js",
|
|
8
8
|
"gmail-auth": "node gmail-auth.js",
|
|
@@ -30,6 +30,11 @@
|
|
|
30
30
|
"mongoose": "^6.1.7",
|
|
31
31
|
"nodemailer": "^6.7.5",
|
|
32
32
|
"serve-favicon": "^2.5.0",
|
|
33
|
-
"socket.io": "^4.4.1"
|
|
33
|
+
"socket.io": "^4.4.1",
|
|
34
|
+
"string-strip-html": "^13.0.0"
|
|
35
|
+
},
|
|
36
|
+
"type": "module",
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=14.16"
|
|
34
39
|
}
|
|
35
40
|
}
|
package/public/js/chat-box.js
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
class ChatBox {
|
|
2
|
-
constructor(
|
|
2
|
+
constructor(username, room) {
|
|
3
3
|
this.socket = null;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
4
|
+
this.username = username;
|
|
5
|
+
this.room = room;
|
|
6
|
+
this.$div = $(`.chat-box#${room}`);
|
|
7
|
+
this.$chatLog = null;
|
|
8
|
+
this.$entry = null;
|
|
9
|
+
this.maxMessages = 100;
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
11
|
+
this.socket = io({
|
|
12
|
+
query: {
|
|
13
|
+
room: this.room,
|
|
14
|
+
name: this.username
|
|
15
|
+
}
|
|
17
16
|
});
|
|
18
17
|
|
|
19
|
-
this.
|
|
20
|
-
this
|
|
21
|
-
this.$chatLog = this.$div.find(".chat-log");
|
|
22
|
-
this.$entry = this.$div.find(".chat-entry");
|
|
18
|
+
this.socket.on('chat message', this.newMessage);
|
|
19
|
+
this.render();
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
newMessage = (msg) => {
|
|
26
23
|
let time = new Date(msg.time);
|
|
27
24
|
this.$chatLog.append(`<p>[${time.toLocaleTimeString('en-US')}] ${msg.name}: ${msg.text}</p>`);
|
|
25
|
+
this.$chatLog.scrollTop(this.$chatLog.prop("scrollHeight"));
|
|
26
|
+
let msgs = this.$chatLog.find("p");
|
|
27
|
+
if (msgs.length > this.maxMessages) {
|
|
28
|
+
for (let i = 0; i < msgs.length - this.maxMessages; i++) {
|
|
29
|
+
msgs[i].remove();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
sendMessage = () => {
|
|
@@ -32,19 +36,29 @@ class ChatBox {
|
|
|
32
36
|
let val = this.$entry.val();
|
|
33
37
|
this.$entry.val("");
|
|
34
38
|
|
|
35
|
-
// $.post("/chat", {
|
|
36
|
-
// room: "<%= room %>",
|
|
37
|
-
// text: val
|
|
38
|
-
// }, function () {
|
|
39
|
-
// $chatLog.scrollTop($chatLog[0].scrollHeight);
|
|
40
|
-
// });
|
|
41
|
-
|
|
42
39
|
this.socket.emit('chat message', {
|
|
43
|
-
name:
|
|
40
|
+
name: this.username,
|
|
44
41
|
time: Date.now(),
|
|
45
42
|
text: val
|
|
46
43
|
});
|
|
47
44
|
}
|
|
48
45
|
}
|
|
46
|
+
|
|
47
|
+
render() {
|
|
48
|
+
this.$div.empty();
|
|
49
|
+
|
|
50
|
+
this.$div.append(`<h4>Chatting with the name ${this.username}:`);
|
|
51
|
+
this.$div.append(`<div class="chat-log"> </div>`);
|
|
52
|
+
this.$div.append(`<input autocomplete="off" type="text" class="chat-entry">`);
|
|
53
|
+
this.$div.append(`<button class="chat-send">Send</button>`);
|
|
54
|
+
|
|
55
|
+
this.$chatLog = this.$div.find(".chat-log");
|
|
56
|
+
this.$entry = this.$div.find(".chat-entry");
|
|
57
|
+
|
|
58
|
+
this.$div.find("button").on("click", this.sendMessage);
|
|
59
|
+
this.$entry.on("keyup", (e) => {
|
|
60
|
+
if (e.keyCode == 13) this.sendMessage();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
49
63
|
}
|
|
50
64
|
|
package/public/styles/chat.css
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
.chat-box {
|
|
2
2
|
position: relative;
|
|
3
|
-
box-shadow:
|
|
4
|
-
margin-top: 20px;
|
|
3
|
+
box-shadow: var(--boxShadow);
|
|
5
4
|
width: 100%;
|
|
6
|
-
|
|
5
|
+
height: 400px;
|
|
7
6
|
}
|
|
8
7
|
|
|
9
8
|
.chat-name {
|
|
@@ -13,24 +12,23 @@
|
|
|
13
12
|
|
|
14
13
|
.chat-log {
|
|
15
14
|
width: 100%;
|
|
16
|
-
height:
|
|
15
|
+
height: 300px;
|
|
17
16
|
background-color: rgba(0, 0, 0, 0.534);
|
|
18
17
|
overflow: auto;
|
|
19
18
|
padding: 5px;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
.chat-send {
|
|
23
|
-
|
|
24
|
-
right: 0;
|
|
25
|
-
bottom: 0;
|
|
26
|
-
height: 25px;
|
|
22
|
+
height: calc(var(--pSize) + 2 * var(--padding));
|
|
27
23
|
width: 5em;
|
|
28
24
|
outline: none;
|
|
29
25
|
background-color: var(--bgColor);
|
|
30
|
-
border:
|
|
26
|
+
border: var(--standardBorder);
|
|
31
27
|
color: var(--textColor);
|
|
32
28
|
text-align: center;
|
|
33
|
-
padding:
|
|
29
|
+
padding: 0;
|
|
30
|
+
margin: 0;
|
|
31
|
+
border-radius: 0;
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
.chat-send:hover {
|
|
@@ -40,21 +38,20 @@
|
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
.chat-entry {
|
|
43
|
-
|
|
44
|
-
left: 0;
|
|
45
|
-
bottom: 0;
|
|
46
|
-
height: 25px;
|
|
41
|
+
height: calc(var(--pSize) + 2 * var(--padding));
|
|
47
42
|
width: calc(100% - 5em);
|
|
48
43
|
outline: none;
|
|
49
44
|
background-color: var(--bgColor);
|
|
50
|
-
border:
|
|
45
|
+
border: var(--standardBorder);
|
|
51
46
|
color: var(--textColor);
|
|
47
|
+
margin: 0;
|
|
48
|
+
padding: var(--padding);
|
|
52
49
|
}
|
|
53
50
|
|
|
54
51
|
.chat-log > p {
|
|
55
52
|
color: var(--textColor);
|
|
56
53
|
margin: 0;
|
|
57
|
-
padding:
|
|
54
|
+
padding: 2px;
|
|
58
55
|
line-height: 1em;
|
|
59
56
|
text-align: left;
|
|
60
57
|
}
|