@pdc-test/chat-io 1.1.5 → 1.1.6
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/package.json +1 -2
- package/src/chat/index.js +4 -4
- package/src/index.js +1 -1
- package/test-client.js +13 -0
- package/test-local.js +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdc-test/chat-io",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"chat-io": "bin/cli.js"
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"start": "node src/server/index.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@pdc-test/chat-io": "^1.1.5",
|
|
13
12
|
"crypto-js": "^4.2.0",
|
|
14
13
|
"ws": "^8.0.0"
|
|
15
14
|
}
|
package/src/chat/index.js
CHANGED
|
@@ -9,7 +9,7 @@ function startChat(onExit, mode = 'udp') {
|
|
|
9
9
|
console.clear();
|
|
10
10
|
const PORT = 41234;
|
|
11
11
|
const BROADCAST_IP = "172.16.41.255";
|
|
12
|
-
const
|
|
12
|
+
const SERVER_URL = "wss://chat-io-production.up.railway.app";
|
|
13
13
|
let socket;
|
|
14
14
|
|
|
15
15
|
let username = "";
|
|
@@ -222,10 +222,10 @@ function startChat(onExit, mode = 'udp') {
|
|
|
222
222
|
|
|
223
223
|
// == ESTABLECER CONEXION ==
|
|
224
224
|
if (mode === 'cloud') {
|
|
225
|
-
console.log("☁️ Intentando conectar a
|
|
226
|
-
socket = new WebSocket(
|
|
225
|
+
console.log("☁️ Intentando conectar a Railway...");
|
|
226
|
+
socket = new WebSocket(SERVER_URL);
|
|
227
227
|
socket.on("open", () => {
|
|
228
|
-
console.log("✅ Conectado a Servidor Global
|
|
228
|
+
console.log("✅ Conectado a Servidor Global Railway!");
|
|
229
229
|
initChatUI();
|
|
230
230
|
});
|
|
231
231
|
socket.on("message", (msg) => {
|
package/src/index.js
CHANGED
|
@@ -13,7 +13,7 @@ function showMenu() {
|
|
|
13
13
|
console.log(" 🚀 MULTI-HERRAMIENTA CLI 🚀");
|
|
14
14
|
console.log("=====================================");
|
|
15
15
|
console.log("1. Entrar al Chat P2P (Red Local/UDP)");
|
|
16
|
-
console.log("2. Entrar al Chat Global (
|
|
16
|
+
console.log("2. Entrar al Chat Global (Railway/WS)");
|
|
17
17
|
console.log("3. Jugar Piedra, Papel o Tijera (Local)");
|
|
18
18
|
console.log("4. Salir");
|
|
19
19
|
console.log("=====================================");
|
package/test-client.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const WebSocket = require('ws');
|
|
2
|
+
const ws = new WebSocket('wss://chat-io-production.up.railway.app/');
|
|
3
|
+
|
|
4
|
+
ws.on('open', () => {
|
|
5
|
+
ws.send(JSON.stringify({ type: "register", name: "agent2" }));
|
|
6
|
+
setInterval(() => {
|
|
7
|
+
ws.send(JSON.stringify({ type: "chat", msg: "Hello from agent2!" }));
|
|
8
|
+
}, 2000);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
ws.on('message', (data) => {
|
|
12
|
+
console.log("AGENT2 RECEIVED:", String(data));
|
|
13
|
+
});
|
package/test-local.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const WebSocket = require('ws');
|
|
2
|
+
const ws1 = new WebSocket('ws://localhost:3000');
|
|
3
|
+
const ws2 = new WebSocket('ws://localhost:3000');
|
|
4
|
+
|
|
5
|
+
ws1.on('open', () => {
|
|
6
|
+
ws1.send(JSON.stringify({ type: "register", name: "user1" }));
|
|
7
|
+
});
|
|
8
|
+
ws1.on('message', (d) => console.log('user1:', String(d)));
|
|
9
|
+
|
|
10
|
+
ws2.on('open', () => {
|
|
11
|
+
ws2.send(JSON.stringify({ type: "register", name: "user2" }));
|
|
12
|
+
setTimeout(() => {
|
|
13
|
+
ws2.send(JSON.stringify({ type: "chat", msg: "msg from 2" }));
|
|
14
|
+
}, 1000);
|
|
15
|
+
});
|
|
16
|
+
ws2.on('message', (d) => console.log('user2:', String(d)));
|