notherbase-fs 1.3.9 → 1.3.11
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/chat.js +0 -2
- package/controllers/pages.js +13 -0
- package/models/index.js +2 -1
- package/models/page.js +14 -0
- package/notherbase-fs.js +4 -0
- package/package.json +1 -1
- package/public/js/chat-box.js +50 -0
- package/test/coast/tall-beach/nono-cove/views/index.ejs +17 -0
- package/test/views/check.ejs +1 -11
- package/views/head.ejs +1 -0
- package/views/chat-box.ejs +0 -47
package/controllers/chat.js
CHANGED
|
@@ -4,8 +4,6 @@ const router = express.Router();
|
|
|
4
4
|
const getRouterWithIO = function getRouterWithIO(io) {
|
|
5
5
|
router.post("/", async function(req, res) {
|
|
6
6
|
try {
|
|
7
|
-
//const foundAccount = await User.findOne({ _id: req.session.currentUser });
|
|
8
|
-
|
|
9
7
|
if (req.session.currentUser) {
|
|
10
8
|
io.to(req.body.room).emit('chat message', {
|
|
11
9
|
name: req.session.currentUser,
|
package/controllers/pages.js
CHANGED
|
@@ -2,10 +2,23 @@ const express = require("express");
|
|
|
2
2
|
const router = express.Router();
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
|
|
5
|
+
const db = require("../models");
|
|
6
|
+
|
|
5
7
|
module.exports = function name(path)
|
|
6
8
|
{
|
|
7
9
|
let files = fs.readdirSync(path);
|
|
8
10
|
|
|
11
|
+
router.post(`/serve/:script`, async function(req, res) {
|
|
12
|
+
try {
|
|
13
|
+
let scriptResult = await require(`${path}/scripts/${req.params.script}.js`)(db, req.session.currentUser, req.body);
|
|
14
|
+
res.send(scriptResult);
|
|
15
|
+
}
|
|
16
|
+
catch(err) {
|
|
17
|
+
console.log(err);
|
|
18
|
+
res.status(500).end();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
9
22
|
files.forEach(file => {
|
|
10
23
|
file = file.slice(0, -4);
|
|
11
24
|
|
package/models/index.js
CHANGED
package/models/page.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const page = new mongoose.Schema({
|
|
4
|
+
name: String,
|
|
5
|
+
type: String,
|
|
6
|
+
user: {
|
|
7
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
8
|
+
ref: "users",
|
|
9
|
+
required: false
|
|
10
|
+
},
|
|
11
|
+
data: {}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
module.exports = mongoose.model('pages', page);
|
package/notherbase-fs.js
CHANGED
|
@@ -52,6 +52,10 @@ class NotherBaseFS {
|
|
|
52
52
|
|
|
53
53
|
this.io.on('connection', (socket) => {
|
|
54
54
|
socket.join(socket.handshake.query.room);
|
|
55
|
+
|
|
56
|
+
console.log(socket.rooms);
|
|
57
|
+
|
|
58
|
+
socket.to(socket.handshake.query.room).emit(`${socket.handshake.query.name} has joined the room`);
|
|
55
59
|
|
|
56
60
|
socket.on('disconnect', () => {});
|
|
57
61
|
});
|
package/package.json
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
class ChatBox {
|
|
2
|
+
constructor(name, box, room) {
|
|
3
|
+
this.socket = null;
|
|
4
|
+
import("/socket.io/socket.io.js").then(() => {
|
|
5
|
+
this.socket = io({
|
|
6
|
+
query: {
|
|
7
|
+
room: room,
|
|
8
|
+
name: name
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
this.socket.on('chat message', this.newMessage);
|
|
13
|
+
$(".chat-send").on("click", this.sendMessage);
|
|
14
|
+
this.$entry.on("keyup", function(e) {
|
|
15
|
+
if (e.keyCode == 13) sendMessage();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
this.room = room;
|
|
20
|
+
this.$div = $(`.chat-box #${box}`)
|
|
21
|
+
this.$chatLog = this.$div.find(".chat-log");
|
|
22
|
+
this.$entry = this.$div.find(".chat-entry");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
newMessage = (msg) => {
|
|
26
|
+
let time = new Date(msg.time);
|
|
27
|
+
this.$chatLog.append(`<p>[${time.toLocaleTimeString('en-US')}] ${msg.name}: ${msg.text}</p>`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
sendMessage = () => {
|
|
31
|
+
if (this.$entry.val() !== ""){
|
|
32
|
+
let val = this.$entry.val();
|
|
33
|
+
this.$entry.val("");
|
|
34
|
+
|
|
35
|
+
// $.post("/chat", {
|
|
36
|
+
// room: "<%= room %>",
|
|
37
|
+
// text: val
|
|
38
|
+
// }, function () {
|
|
39
|
+
// $chatLog.scrollTop($chatLog[0].scrollHeight);
|
|
40
|
+
// });
|
|
41
|
+
|
|
42
|
+
this.socket.emit('chat message', {
|
|
43
|
+
name: name,
|
|
44
|
+
time: Date.now(),
|
|
45
|
+
text: val
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
@@ -4,6 +4,19 @@
|
|
|
4
4
|
|
|
5
5
|
<hr>
|
|
6
6
|
|
|
7
|
+
<div class="chat-box" id="test-box">
|
|
8
|
+
<div class="chat-name">Chatting using the name <%= user.username %>:</div>
|
|
9
|
+
|
|
10
|
+
<div class="chat-log">
|
|
11
|
+
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<input autocomplete="off" type="text" name="text" class="chat-entry">
|
|
15
|
+
<div value="Send" class="chat-send">Send</div>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
<hr>
|
|
19
|
+
|
|
7
20
|
<h3>Game Test</h3>
|
|
8
21
|
|
|
9
22
|
<button onclick="addToTime()">Add</button>
|
|
@@ -67,7 +80,11 @@
|
|
|
67
80
|
Go to Nono Cove
|
|
68
81
|
</a>
|
|
69
82
|
|
|
83
|
+
|
|
84
|
+
<script src="/js/chat-box.js"></script>
|
|
70
85
|
<script>
|
|
86
|
+
let chatTest = new ChatBox("<%= user.username %>", "test-box", "testRoom");
|
|
87
|
+
|
|
71
88
|
let bought = false;
|
|
72
89
|
|
|
73
90
|
let tradeForDoll = async function tradeForDoll() {
|
package/test/views/check.ejs
CHANGED
|
@@ -4,14 +4,4 @@
|
|
|
4
4
|
|
|
5
5
|
<a href="/the-front">
|
|
6
6
|
Go to The Front
|
|
7
|
-
</a>
|
|
8
|
-
|
|
9
|
-
<script>
|
|
10
|
-
// $.post("/forest/eye-of-the-forest/square/test/save", {
|
|
11
|
-
// test: 36
|
|
12
|
-
// });
|
|
13
|
-
|
|
14
|
-
// $.get("/forest/eye-of-the-forest/square/test/load", function (data) {
|
|
15
|
-
// console.log(data);
|
|
16
|
-
// });
|
|
17
|
-
</script>
|
|
7
|
+
</a>
|
package/views/head.ejs
CHANGED
package/views/chat-box.ejs
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
<link rel="stylesheet" href="/styles/chat.css">
|
|
2
|
-
|
|
3
|
-
<div class="chat-box">
|
|
4
|
-
<div class="chat-name">Chatting using the name <%= user.username %>:</div>
|
|
5
|
-
|
|
6
|
-
<div class="chat-log">
|
|
7
|
-
|
|
8
|
-
</div>
|
|
9
|
-
<input autocomplete="off" type="text" name="text" class="chat-entry">
|
|
10
|
-
<div value="Send" class="chat-send">Send</div>
|
|
11
|
-
</div>
|
|
12
|
-
|
|
13
|
-
<script>
|
|
14
|
-
<%- include("../node_modules/socket.io/client-dist/socket.io.js"); %>
|
|
15
|
-
|
|
16
|
-
let socket = io({
|
|
17
|
-
query: {
|
|
18
|
-
room: "<%= room %>"
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
let $chatLog = $(".chat-log");
|
|
22
|
-
let $entry = $(".chat-entry");
|
|
23
|
-
|
|
24
|
-
socket.on('chat message', function(msg) {
|
|
25
|
-
let time = new Date(msg.time);
|
|
26
|
-
$chatLog.append(`<p>[${time.toLocaleTimeString('en-US')}] ${msg.name}: ${msg.text}</p>`);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const sendMessage = function() {
|
|
30
|
-
if ($entry.val() !== ""){
|
|
31
|
-
let val = $entry.val();
|
|
32
|
-
$entry.val("");
|
|
33
|
-
|
|
34
|
-
$.post("/chat", {
|
|
35
|
-
room: "<%= room %>",
|
|
36
|
-
text: val
|
|
37
|
-
}, function () {
|
|
38
|
-
$chatLog.scrollTop($chatLog[0].scrollHeight);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
$(".chat-send").on("click", sendMessage);
|
|
44
|
-
$entry.on("keyup", function(e) {
|
|
45
|
-
if (e.keyCode == 13) sendMessage();
|
|
46
|
-
});
|
|
47
|
-
</script>
|