wv-local-service
v0.0.72
Published
Works in conjuction with wv-local-service-broker to provide a named service within the localhost machine
Downloads
110
Readme
wv-local-service
Purpose
To provide a (localhost) service that works through wv-local-service-broker
's LocalServiceBroker
running in a separate process (or in some scenarios you may run the broker and a service it in the same process ).
Package Dependencies
- socket.io.
Brief Documentation
- From package
ws-local-service-broker
you can start a broker by callingLocalServiceBroker.start()
. - Only one
LocalServiceBroker.start()
invokation could be made in a process lifetime. LocalServiceBroker
cannot be hosted in a web page, whileLocalService
could be hosted in a web page the same exact way as in a process with two way communication supported.- The hosting machine could run only one
LocalServiceBroker
at a time on port47979
. - If a
LocalServiceBroker.start()
is invoked from one or more processes while there is an already running one, the newest one/ones keeps/keep standby and one of them compensates the running one in the case of the exit of the running one. - Each service connects to and identifies itself to the service broker through invoking
LocalService.contributeAs()
fromwv-local-service
package. The serivce identity is provided through the first argumentserviceName
. LocalService.contributeAs()
could be invoked only once in a process or a web page.- If a new service contributed later using the same service name. It replaces the old one (by design).
- A process or a web page could host only one service.
- Remote procedure calls between processes are done by instantiating an
Envelop
's subclass and callingenvelop.postAsync()
method. - Envelop is an abstract class, so you typically inherit it to provide its own schema of request and response.
How to use it
import { LocalService } from 'wv-local-service'
LocalService.contributeAs(serviceName: string, onConnectionStatusChanged?:(isConnected: boolean)=>void);
Please find the readme.md of wv-localhost-service-broker package for more info on the broker side.