muworker-socket
Web Worker made available to mudb
. Suitable for creating games with a single-player mode by running the server in a separate thread to allow better user experience.
example
Both browserify
and webworkify
are required to run the example.
worker.js
const createWorkerSocketServer = const MuServer = // source of worker should go into `module.exports`module { const socketServer = const muServer = socketServer socketServer muServerstart/* listeners */}
client.js
// `webworkify` enables workers to `require()`const work = const createWorkerSocket = const MuClient = const serverWorker = const socket = const muClient = socket muClientstart/* listeners */
table of contents
1 install
npm i muworker-socket
2 api
2.1 interfaces
Purely instructive types used to describe the API:
SessionId
:string
2.2 createWorkerSocketServer()
A factory returning a new instance of MuWorkerSocketServer
.
2.3 createWorkerSocket(spec)
A factory returning a new instance of MuWorkerSocket
.
spec:object
sessionId:SessionId
: a unique session id used to identify a clientserverWorker:Worker
: the worker in which the server is running
2.4 MuWorkerSocketServer
A MuWorkerSocketServer
is a pseudo socket server that can be used to instantiate a MuServer
.
2.4.1 listen()
Starts the socket server listening for connections.
2.5 MuWorkerSocket
A MuLocalSocket
is a pseudo client-side socket that can be used to instantiate a MuClient
.
credits
Copyright (c) 2018 He Diyi, Shenzhen Dianmao Technology Company Limited