network socket emulation for development purpose
In local-socket
, no real network connections are established so no Web servers are needed, meaning applications using local-socket
can run entirely in a browser. It can make your life easier:
- you can forget about restarting the server on changes
- you can debug using the dev tools provided by browsers
import { MuServer, MuClient } from 'mudb'
import { createLocalSocketServer, createLocalSocket } from 'mudb/socket/local'
const socketServer = createLocalSocketServer()
const server = new MuServer(socketServer)
const socket = createLocalSocket({
sessionId: Math.random().toString(16).substring(2),
server: socketServer,
})
const client = new MuClient(socket)
Use the factory functions instead of the constructors.
Creates a pseudo socket server.
createLocalSocketServer(spec?:{
scheduler?:MuScheduler,
}) : MuLocalSocketServer
scheduler
can be set to aMuMockScheduler
for testing
Creates a "connection" to the socket server passed in, and returns the socket.
createLocalSocket(spec:{
sessionId:string,
server:MuLocalSocketServer,
scheduler?:MuScheduler,
}) : MuLocalSocket
sessionId
a user-generated session idserver
the server returned bycreateLocalSocketServer()
scheduler
can be set to aMuMockScheduler
for testing
implements MuSocketServer
A pseudo socket server.
implements MuSocket
A pseudo socket.