mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
272566950d
Former-commit-id: a98a80996d7d95fa947e72c71803407682229fa7
36 lines
935 B
JavaScript
36 lines
935 B
JavaScript
const neffos = require('neffos.js');
|
|
const stdin = process.openStdin();
|
|
|
|
const wsURL = "ws://localhost:8080/echo";
|
|
|
|
async function runExample() {
|
|
try {
|
|
const conn = await neffos.dial(wsURL, {
|
|
default: { // "default" namespace.
|
|
_OnNamespaceConnected: function (nsConn, msg) {
|
|
console.log("connected to namespace: " + msg.Namespace);
|
|
},
|
|
_OnNamespaceDisconnect: function (nsConn, msg) {
|
|
console.log("disconnected from namespace: " + msg.Namespace);
|
|
},
|
|
chat: function (nsConn, msg) { // "chat" event.
|
|
console.log(msg.Body);
|
|
}
|
|
}
|
|
});
|
|
|
|
const nsConn = await conn.connect("default");
|
|
nsConn.emit("chat", "Hello from Nodejs client side!");
|
|
|
|
stdin.addListener("data", function (data) {
|
|
const text = data.toString().trim();
|
|
nsConn.emit("chat", text);
|
|
});
|
|
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
}
|
|
|
|
runExample();
|