let nisper = require("nisper").default
// ******* Server ********
var server = nisper({
wsOptions: { port: 8080 },
sandbox: {
// Define a function so that clients can call it remotely.
'+': (a, b) => a + b
},
onOpen: (ws) => {
server.callx(ws)`(- 2 1)` // subtract(2, 1)
.then(res => {
console.log(`server res: ${res}`)
})
}
})
// ******* Client ********
var client = nisper({
url: `ws://127.0.0.1:8080`,
sandbox: {
// Define a function so that the server can call it remotely.
'-': (a, b) => a - b
}
})
client.callx`(+ 1 (+ 1 1))` // add(1, add(1, 1))
.then(res => {
console.log(`server res: ${res}`)
})