started edition of chat in node
+ handled cors + added css fo chat scroll and newline
This commit is contained in:
@@ -8,4 +8,4 @@
|
||||
<body><div class="mxgraph" style="max-width:100%;border:1px solid transparent;" data-mxgraph="{"highlight":"#0000ff","nav":true,"resize":true,"toolbar":"zoom layers tags lightbox","edit":"_blank","xml":"<mxfile host=\"www.draw.io\" modified=\"2022-10-31T09:17:07.403Z\" agent=\"5.0 (X11; Ubuntu)\" etag=\"c-fjD9Itp8SMr4AJSRT6\" version=\"20.5.1\"><diagram id=\"6a731a19-8d31-9384-78a2-239565b7b9f0\" name=\"Page-1\">7V1bc9q6Fv41zN7nIYzvl8eEhLYzTdMpyZzdR4EFuDWIbQuSnF9/JFs2tiyIMVgGah4Sa1nWxfrWRUtLck8fLN4+hWA1f0QeDHqa4r319PuepumaoZN/lPKeUFTVNhPKLPQ9RtsSRv7/ICMqjLr2PRgVMmKEAuyvisQJWi7hBBdoIAzRazHbFAXFWldgBkuE0QQEZep/fQ/P025Y7vbGZ+jP5qxqR7OTG2Mw+T0L0XrJ6luiJUzuLEBaDOtjNAcees2R9IeePggRwsnV4m0AA/pe0zeWPDfccTdrcgiXuNIDtmElz2xAsGYdZ03D7+mbgB55MSwZd0a/i7sHaSkKSf1aL1ZchjleBCSlksuskzRrAMYwuMve0AAFKNw+FWEQ4ls6eBxt6AcBKwEuvTTHJABR5E8SIstCa/wFMX5niAJrjAgJhXiOZmgJgq8IrdKW4RD9hmkbegS1Q/POHmR30nHXCWWKlngIFn5A8fwZBhuI/QlgN1hdqsXS+SJ1wzDvaZErMPGXM0I1Sao8UmzwIrQOJzAbHgY28g5mkGUcPt89gZvI+nHzMtMnd+bzzY11o9oOwxQdrVyJbOA/QbSAOHwnGUIYAOxvijAHjFtmWb7s0e/IJ23UFMbats74mDG24WjFIpK2sqe24CMXuWZsSTEkd8LT6eB5YfAkcl4/NRILGNoPGFcAGCsgbbvz/A25nNHL74j0lJFJmbk7JXRtoUSH5HXuYzgir4refSWa7wgs5Qe3QCyMK4GNC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OxbuN/YQKiE/Nq1ozrWdn3QSXOK4c0p6tAjrh3NOSCBLxGJ9c8/cGJa1O6GSqu8ZxqcP/yG/aX2ADMDhgNOpUTNHg7T4JWHqf+WNmG+ryHBB1O8tGeoFwerkiupL+/xts4IT8jxvUwujnAdhW3Q3z41/zYjhxFkkM91dMBWhODnJmWI0g8cLUvWB/sNRzbAvd0P4InVhoA8NpEBtbc9/zSDcbCBpXFe6caMF2LCOd7uadO9m3lU/v3XFU0YT0UhX44Onbt4d/vjx9O03dHyjrjGVyZ/fLFdaVKz6pqD6ouycV1E0Iju1c6HIEh8gtLJQcfCxZBcFBktsPmScThe2X4vWH/wM=</diagram></mxfile>"}"></div>
|
||||
<script type="text/javascript" src="https://viewer.diagrams.net/js/viewer-static.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
85
tests_hugo/README.md
Normal file
85
tests_hugo/README.md
Normal file
@@ -0,0 +1,85 @@
|
||||
```
|
||||
fetch conversations
|
||||
___________________
|
||||
| _ |
|
||||
| no conversation | if len == 0
|
||||
| |
|
||||
| [join public] |
|
||||
| |
|
||||
| [start new] |
|
||||
| |
|
||||
|...................|
|
||||
| |
|
||||
|___________________|
|
||||
___________________
|
||||
| convs _ |
|
||||
|___________________| if len > 0
|
||||
| |
|
||||
| |
|
||||
| |
|
||||
| |
|
||||
| |
|
||||
|___________________|
|
||||
| |send |
|
||||
|_____________|_____|
|
||||
___________________
|
||||
| convs _ |
|
||||
|_ ____________|
|
||||
| .list |
|
||||
| .of |
|
||||
| .convs |
|
||||
| |
|
||||
| |
|
||||
|___________________|
|
||||
| |send |
|
||||
|_____________|_____|
|
||||
___________________
|
||||
| [join public] _ |
|
||||
| | if join_public
|
||||
| .list | fetch public_conversations
|
||||
| .of |
|
||||
| .public |
|
||||
| .convs |
|
||||
| |
|
||||
| |
|
||||
| |
|
||||
|___________________|
|
||||
___________________
|
||||
| [start new] _ |
|
||||
| | if start_new
|
||||
| .list | fetch friends
|
||||
| .of |
|
||||
| .friends |
|
||||
| |
|
||||
| |
|
||||
| |
|
||||
| |
|
||||
|___________________|
|
||||
___________________
|
||||
| convs _ |
|
||||
|___________________| if click_on_list_element
|
||||
| .blablabla | fetch conversation(list_element)
|
||||
| blablabla. |
|
||||
| .bla | --server side--
|
||||
| blabla. | if conversation_exist
|
||||
| bla. | return text
|
||||
|___________________| else if is_allowed
|
||||
| |send | return "start conv"
|
||||
|_____________|_____|
|
||||
|
||||
```
|
||||
|
||||
### goals :
|
||||
- own messages are not sent to myself and directly printed
|
||||
- i can create a room
|
||||
- my messages are sent to other people in room
|
||||
- i can choose in which room to send the messages
|
||||
|
||||
### routes :
|
||||
- https://transcendance:8080/api/v2/chat/conversations
|
||||
- returns list of objects, each object contains :
|
||||
- id: unique conv identification
|
||||
- title: name of the conversation (name of other guy if direct message)
|
||||
-
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="./style/chat.css" type="text/css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -20,11 +21,13 @@
|
||||
|
||||
<div class="chat_item msg_thread">
|
||||
<div class="msg_box" id="msg_thread">
|
||||
<!-- messages go there -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="chat_item msg_write">
|
||||
<div class="text_area" id="msg_write" contenteditable>
|
||||
<!-- write message here -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -48,32 +51,5 @@
|
||||
<script src="./chat_submit_msg.js"></script>
|
||||
<script src="./chat_receive_msg.js"></script>
|
||||
|
||||
|
||||
<!--
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script>
|
||||
|
||||
let socket = io();
|
||||
|
||||
let send = function () {
|
||||
let text = document.getElementById('message').value;
|
||||
socket.emit('chat_message', text);
|
||||
}
|
||||
|
||||
let receive = function (msg) {
|
||||
let li = document.createElement('li');
|
||||
li.innerText = msg;
|
||||
document.getElementById('messages').appendChild(li);
|
||||
}
|
||||
socket.on('chat_message', receive);
|
||||
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<ul id="messages"></ul>
|
||||
<input id="message" type="text"/>
|
||||
<button onclick="send()">send</button>
|
||||
</div>
|
||||
-->
|
||||
</body>
|
||||
</html>
|
||||
20
tests_hugo/chat_node/chat_client/chat_receive_msg.js
Normal file
20
tests_hugo/chat_node/chat_client/chat_receive_msg.js
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
socket.on('chat_message', ({ data }) => {
|
||||
handle_new_message(data);
|
||||
});
|
||||
|
||||
const handle_new_message = (message) => {
|
||||
const div_thread = document.getElementById('msg_thread');
|
||||
|
||||
console.log("received message:");
|
||||
console.log(`[${message}]`);
|
||||
|
||||
div_thread.appendChild(build_new_message(message));
|
||||
}
|
||||
|
||||
const build_new_message = (message) => {
|
||||
const p = document.createElement("p");
|
||||
p.appendChild(document.createTextNode(message));
|
||||
return p;
|
||||
}
|
||||
|
||||
18
tests_hugo/chat_node/chat_client/chat_submit_msg.js
Normal file
18
tests_hugo/chat_node/chat_client/chat_submit_msg.js
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
const submit_new_message = () => {
|
||||
const div_msg = document.getElementById('msg_write');
|
||||
/*
|
||||
const msg = div_msg.value;
|
||||
const msg = div_msg.innerText;
|
||||
*/
|
||||
const msg = div_msg.innerText.trim();
|
||||
div_msg.innerText = "";
|
||||
|
||||
console.log("msg:");
|
||||
console.log(`[${msg}]`);
|
||||
console.log(msg.length);
|
||||
|
||||
if (msg.length > 0)
|
||||
socket.emit('chat_message', { data: msg });
|
||||
}
|
||||
|
||||
113
tests_hugo/chat_node/chat_client/style/chat.css
Normal file
113
tests_hugo/chat_node/chat_client/style/chat.css
Normal file
@@ -0,0 +1,113 @@
|
||||
|
||||
@import 'msg_thread.css';
|
||||
@import 'msg_write.css';
|
||||
|
||||
/**
|
||||
* GRID
|
||||
*/
|
||||
|
||||
|
||||
/* Hide scrollbar */
|
||||
.chat_box * {
|
||||
-ms-overflow-style: none; /* IE and Edge */
|
||||
scrollbar-width: none; /* Firefox */
|
||||
}
|
||||
.chat_box *::-webkit-scrollbar {
|
||||
display: none; /* Chrome, Safari and Opera */
|
||||
}
|
||||
|
||||
/* global settings */
|
||||
.chat_box * {
|
||||
position: relative;
|
||||
box-sizing: border-box;
|
||||
/* Hide scrollbar for IE, Edge and Firefox */
|
||||
-ms-overflow-style: none; /* IE and Edge */
|
||||
scrollbar-width: none; /* Firefox */
|
||||
}
|
||||
.chat_box .chat_item.controls_area { grid-area: controls;}
|
||||
.chat_box .chat_item.open_close { grid-area: open_close;}
|
||||
.chat_box .chat_item.msg_thread { grid-area: msg_thread;}
|
||||
.chat_box .chat_item.msg_write { grid-area: msg_write;}
|
||||
.chat_box .chat_item.msg_send { grid-area: msg_send;}
|
||||
.chat_box {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
right: 20px;
|
||||
display: grid;
|
||||
grid:
|
||||
' controls open_close ' auto
|
||||
' msg_thread msg_thread ' 1fr
|
||||
' msg_write msg_send ' auto
|
||||
/ 1fr auto;
|
||||
gap: 0px;
|
||||
padding: 0px;
|
||||
width: auto;
|
||||
height: auto;
|
||||
|
||||
border: 1px solid green;
|
||||
}
|
||||
.chat_box .chat_item * {
|
||||
display: flex;
|
||||
}
|
||||
/* buttons settings */
|
||||
.chat_box .chat_item.button {
|
||||
display: flex;
|
||||
width: auto;
|
||||
padding: 10px;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
border: none;
|
||||
background-color: rgb(220, 220, 220);
|
||||
}
|
||||
.chat_box .chat_item.button p {
|
||||
margin: auto;
|
||||
}
|
||||
.chat_box .chat_item.button:hover {
|
||||
background-color: rgb(200, 200, 200);
|
||||
}
|
||||
.chat_box .chat_item.button:active {
|
||||
background-color: rgb(220, 220, 220);
|
||||
}
|
||||
/* collapse settings */
|
||||
.chat_box .chat_item:not(.open_close) {
|
||||
display: none;
|
||||
}
|
||||
#chat_input:checked +
|
||||
.chat_box {
|
||||
gap: 5px;
|
||||
padding: 5px;
|
||||
width: 300px;
|
||||
height: 400px;
|
||||
}
|
||||
#chat_input:checked +
|
||||
.chat_box .chat_item {
|
||||
display: flex;
|
||||
}
|
||||
#chat_input:checked +
|
||||
.chat_box .chat_item.open_close p {
|
||||
display: none;
|
||||
}
|
||||
#chat_input:checked +
|
||||
.chat_box .chat_item.open_close {
|
||||
/*
|
||||
*/
|
||||
width: 30px;
|
||||
height: 20px;
|
||||
padding: 0px;
|
||||
justify-self: end;
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
}
|
||||
#chat_input:checked +
|
||||
.chat_box .chat_item.open_close::before {
|
||||
--collapse_width: 20px;
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
height: 2px;
|
||||
width: 15px;
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
19
tests_hugo/chat_node/chat_client/style/msg_thread.css
Normal file
19
tests_hugo/chat_node/chat_client/style/msg_thread.css
Normal file
@@ -0,0 +1,19 @@
|
||||
.chat_box .chat_item.msg_thread {
|
||||
flex-direction: column-reverse;
|
||||
overflow: scroll;
|
||||
border: 1px solid blue;
|
||||
}
|
||||
|
||||
.chat_box .chat_item .msg_box {
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.chat_box #msg_thread p {
|
||||
white-space: pre-wrap;
|
||||
margin: 5px auto 5px 0px;
|
||||
padding: 5px;
|
||||
border-radius: 5px;
|
||||
background-color: rgb(210, 210, 210);
|
||||
}
|
||||
20
tests_hugo/chat_node/chat_client/style/msg_write.css
Normal file
20
tests_hugo/chat_node/chat_client/style/msg_write.css
Normal file
@@ -0,0 +1,20 @@
|
||||
.chat_box .chat_item .text_area {
|
||||
display: block;
|
||||
position: absolute;
|
||||
bottom: 0px;
|
||||
left: 0px;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
min-height: 100%;
|
||||
max-height: 300px;
|
||||
/*
|
||||
resize: none;
|
||||
*/
|
||||
overflow-x: hidden;
|
||||
overflow-y: scroll;
|
||||
background-color: white;
|
||||
border: 1px solid red;
|
||||
}
|
||||
.chat_box .chat_item .text_area div {
|
||||
display: block ruby;
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
{
|
||||
"name": "chat_node",
|
||||
"name": "chat_server",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
"nodemon": "^2.0.20",
|
||||
"socket.io": "^4.5.3"
|
||||
@@ -48,9 +49,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/anymatch": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz",
|
||||
"integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==",
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
|
||||
"integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==",
|
||||
"dependencies": {
|
||||
"normalize-path": "^3.0.0",
|
||||
"picomatch": "^2.0.4"
|
||||
@@ -915,9 +916,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/simple-update-notifier": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-1.0.7.tgz",
|
||||
"integrity": "sha512-BBKgR84BJQJm6WjWFMHgLVuo61FBDSj1z/xSFUIozqO6wO7ii0JxCqlIud7Enr/+LhlbNI0whErq96P2qHNWew==",
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-1.1.0.tgz",
|
||||
"integrity": "sha512-VpsrsJSUcJEseSbMHkrsrAVSdvVS5I96Qo1QAQ4FxQ9wXFcB+pjj7FB7/us9+GcgfW4ziHtYMc1J0PLczb55mg==",
|
||||
"dependencies": {
|
||||
"semver": "~7.0.0"
|
||||
},
|
||||
@@ -934,16 +935,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io": {
|
||||
"version": "4.5.3",
|
||||
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.5.3.tgz",
|
||||
"integrity": "sha512-zdpnnKU+H6mOp7nYRXH4GNv1ux6HL6+lHL8g7Ds7Lj8CkdK1jJK/dlwsKDculbyOHifcJ0Pr/yeXnZQ5GeFrcg==",
|
||||
"version": "4.5.4",
|
||||
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.5.4.tgz",
|
||||
"integrity": "sha512-m3GC94iK9MfIEeIBfbhJs5BqFibMtkRk8ZpKwG2QwxV0m/eEhPIV4ara6XCF1LWNAus7z58RodiZlAH71U3EhQ==",
|
||||
"dependencies": {
|
||||
"accepts": "~1.3.4",
|
||||
"base64id": "~2.0.0",
|
||||
"debug": "~4.3.2",
|
||||
"engine.io": "~6.2.0",
|
||||
"engine.io": "~6.2.1",
|
||||
"socket.io-adapter": "~2.4.0",
|
||||
"socket.io-parser": "~4.2.0"
|
||||
"socket.io-parser": "~4.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
@@ -1155,9 +1156,9 @@
|
||||
}
|
||||
},
|
||||
"anymatch": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz",
|
||||
"integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==",
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
|
||||
"integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==",
|
||||
"requires": {
|
||||
"normalize-path": "^3.0.0",
|
||||
"picomatch": "^2.0.4"
|
||||
@@ -1787,9 +1788,9 @@
|
||||
}
|
||||
},
|
||||
"simple-update-notifier": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-1.0.7.tgz",
|
||||
"integrity": "sha512-BBKgR84BJQJm6WjWFMHgLVuo61FBDSj1z/xSFUIozqO6wO7ii0JxCqlIud7Enr/+LhlbNI0whErq96P2qHNWew==",
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-1.1.0.tgz",
|
||||
"integrity": "sha512-VpsrsJSUcJEseSbMHkrsrAVSdvVS5I96Qo1QAQ4FxQ9wXFcB+pjj7FB7/us9+GcgfW4ziHtYMc1J0PLczb55mg==",
|
||||
"requires": {
|
||||
"semver": "~7.0.0"
|
||||
},
|
||||
@@ -1802,16 +1803,16 @@
|
||||
}
|
||||
},
|
||||
"socket.io": {
|
||||
"version": "4.5.3",
|
||||
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.5.3.tgz",
|
||||
"integrity": "sha512-zdpnnKU+H6mOp7nYRXH4GNv1ux6HL6+lHL8g7Ds7Lj8CkdK1jJK/dlwsKDculbyOHifcJ0Pr/yeXnZQ5GeFrcg==",
|
||||
"version": "4.5.4",
|
||||
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.5.4.tgz",
|
||||
"integrity": "sha512-m3GC94iK9MfIEeIBfbhJs5BqFibMtkRk8ZpKwG2QwxV0m/eEhPIV4ara6XCF1LWNAus7z58RodiZlAH71U3EhQ==",
|
||||
"requires": {
|
||||
"accepts": "~1.3.4",
|
||||
"base64id": "~2.0.0",
|
||||
"debug": "~4.3.2",
|
||||
"engine.io": "~6.2.0",
|
||||
"engine.io": "~6.2.1",
|
||||
"socket.io-adapter": "~2.4.0",
|
||||
"socket.io-parser": "~4.2.0"
|
||||
"socket.io-parser": "~4.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
"nodemon": "^2.0.20",
|
||||
"socket.io": "^4.5.3"
|
||||
45
tests_hugo/chat_node/chat_server/server.js
Normal file
45
tests_hugo/chat_node/chat_server/server.js
Normal file
@@ -0,0 +1,45 @@
|
||||
//let app = require('express')();
|
||||
//let server = require('http').createServer(app);
|
||||
//let io = require('socket.io')(http);
|
||||
|
||||
const express = require('express');
|
||||
//const cors = require('cors');
|
||||
const app = express();
|
||||
const http = require('http');
|
||||
const server = http.createServer(app);
|
||||
const { Server } = require("socket.io");
|
||||
// https://socket.io/docs/v4/handling-cors/
|
||||
const io = new Server(server, {
|
||||
cors: {
|
||||
origin: "*"
|
||||
}
|
||||
});
|
||||
|
||||
// cors : https://stackoverflow.com/questions/7067966/why-doesnt-adding-cors-headers-to-an-options-route-allow-browsers-to-access-my
|
||||
// https://www.npmjs.com/package/cors
|
||||
//app.use(cors());
|
||||
|
||||
//app.get("/", function (req, res) {
|
||||
// console.log("req.headers: ");
|
||||
// console.log(req.headers);
|
||||
//})
|
||||
|
||||
io.on('connection', function (socket) {
|
||||
|
||||
console.log('a user is connected');
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
console.log('a user is disconnected');
|
||||
})
|
||||
|
||||
socket.on('chat_message', function (msg) {
|
||||
console.log('message received: ' + msg);
|
||||
io.emit('chat_message', msg);
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
server.listen(3000, function () {
|
||||
console.log('server running on 3000');
|
||||
})
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//let app = require('express')();
|
||||
let http = require('http').Server(app);
|
||||
let io = require('socket.io')(http);
|
||||
|
||||
//app.get("/", function (req, res) {
|
||||
// console.log("req.headers: ");
|
||||
// console.log(req.headers);
|
||||
// res.sendFile(__dirname + '/index.html');
|
||||
//})
|
||||
|
||||
io.on('connection', function (socket) {
|
||||
|
||||
console.log('a user is connected');
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
console.log('a user is disconnected');
|
||||
})
|
||||
|
||||
socket.on('chat_message', function (msg) {
|
||||
console.log('message received: ' + msg);
|
||||
io.emit('chat_message', msg);
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
http.listen(3000, function () {
|
||||
console.log('server running on 3000');
|
||||
})
|
||||
|
||||
133
tests_hugo/js_async/async.js
Normal file
133
tests_hugo/js_async/async.js
Normal file
@@ -0,0 +1,133 @@
|
||||
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * *
|
||||
UTILITIES
|
||||
*/
|
||||
|
||||
function resolveAfter2Seconds() {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve(spent_time(ori_date) + 'lente');
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
function resolveAfter1Seconds() {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve(spent_time(ori_date) + 'rapide');
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
function print_time(my_date = new Date) {
|
||||
let my_time = my_date.getSeconds();
|
||||
my_time += ":";
|
||||
my_time += my_date.getMilliseconds();
|
||||
return '[' + my_time + '] ';
|
||||
}
|
||||
function spent_time(ori_date) {
|
||||
let my_date = new Date();
|
||||
|
||||
let my_seconds = my_date.getSeconds() - ori_date.getSeconds();
|
||||
if (my_seconds < 0 ) my_seconds += 60;
|
||||
|
||||
let my_millis = my_date.getMilliseconds() - ori_date.getMilliseconds();
|
||||
if (my_millis < 0 ) my_millis += 1000;
|
||||
|
||||
return '[' + my_seconds + ':' + my_millis + '] ';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * *
|
||||
TESTS
|
||||
/*
|
||||
|
||||
async function asyncCall() {
|
||||
console.log(spent_time(ori_date) + 'calling');
|
||||
const lente = await resolveAfter2Seconds();
|
||||
const rpide = await resolveAfter1Seconds();
|
||||
console.log(spent_time(ori_date) + lente);
|
||||
console.log(spent_time(ori_date) + rpide);
|
||||
}
|
||||
// "[0:1] calling"
|
||||
// "[0:4] after"
|
||||
// "[3:6] [2:4] lente"
|
||||
// "[3:15] [3:6] rapide"
|
||||
*/
|
||||
|
||||
/*
|
||||
function asyncCall() {
|
||||
console.log(spent_time(ori_date) + 'calling');
|
||||
const lente = resolveAfter2Seconds();
|
||||
const rpide = resolveAfter1Seconds();
|
||||
console.log(spent_time(ori_date) + lente);
|
||||
console.log(spent_time(ori_date) + rpide);
|
||||
}
|
||||
// "[0:1] calling"
|
||||
// "[0:4] [object Promise]"
|
||||
// "[0:12] [object Promise]"
|
||||
// "[0:19] after"
|
||||
*/
|
||||
|
||||
/*
|
||||
function asyncCall() {
|
||||
console.log(spent_time(ori_date) + 'calling');
|
||||
resolveAfter2Seconds().then(message => console.log(spent_time(ori_date) + message))
|
||||
.then(() => resolveAfter1Seconds()).then(message => console.log(spent_time(ori_date) + message));
|
||||
}
|
||||
// "[0:1] calling"
|
||||
// "[0:4] after"
|
||||
// "[2:4] [2:4] lente"
|
||||
// "[3:15] [3:15] rapide"
|
||||
*/
|
||||
|
||||
/*
|
||||
async function asyncCall() {
|
||||
console.log(spent_time(ori_date) + 'calling');
|
||||
const lente = await resolveAfter2Seconds();
|
||||
console.log(spent_time(ori_date) + 'middle');
|
||||
const rpide = await resolveAfter1Seconds();
|
||||
console.log(spent_time(ori_date) + lente);
|
||||
console.log(spent_time(ori_date) + rpide);
|
||||
}
|
||||
// "[0:1] calling"
|
||||
// "[0:2] after"
|
||||
// "[2:4] middle"
|
||||
// "[3:7] [2:4] lente"
|
||||
// "[3:8] [3:6] rapide"
|
||||
*/
|
||||
|
||||
async function asyncCall() {
|
||||
console.log(spent_time(ori_date) + 'calling');
|
||||
const lente = resolveAfter2Seconds();
|
||||
const rpide = resolveAfter1Seconds();
|
||||
console.log(spent_time(ori_date) + await lente);
|
||||
console.log(spent_time(ori_date) + await rpide);
|
||||
}
|
||||
// "[0:0] calling"
|
||||
// "[0:3] after"
|
||||
// "[0:3] [2:4] lente"
|
||||
// "[2:5] [1:3] rapide"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * *
|
||||
LAUNCH TEST
|
||||
*/
|
||||
|
||||
let ori_date = new Date();
|
||||
asyncCall();
|
||||
|
||||
console.log(spent_time(ori_date) + "after");
|
||||
|
||||
@@ -26,7 +26,7 @@ class myServer {
|
||||
constructor() {
|
||||
this._gets = {};
|
||||
this._posts = {};
|
||||
this._putss = {};
|
||||
this._puts = {};
|
||||
this._deletes = {};
|
||||
|
||||
this._server = http.createServer((req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user