It stablish a connection between two nodes.
Function
Any time dop needs to send something to the other node will call this function with a message as an argument.
Function
OptionalAn optional function that will be sent to the other side to start the communication.
Function
The entryFunction
of the other side.
// Server
const { createNode } = require('dop')
const WebSocket = require('ws')
const wss = new WebSocket.Server({ port: 8080 })
function serverEntryFunction() {
return {
login,
register,
logout
}
}
wss.on('connection', ws => {
const client = createNode()
client.open(ws.send, serverEntryFunction)
//...
})
// Client (Browser)
import { createNode } from 'dop'
const ws = new WebSocket('ws://localhost:8080')
const server = createNode()
ws.onopen = async () => {
const serverEntryFunction = server.open(ws.send)
// ...
}
Client is not passing an entryFunction as second argument. But both can do it.
// Server
const clientEntryFunction = client.open(
ws.send,
function serverEntryFunction() {
// do some stuff
}
)
// Client (Browser)
const serverEntryFunction = server.open(
ws.send,
function clientEntryFunction() {
// do some stuff
}
)