Skip to content

Distributed live object messaging for NodeJS and the browser (core)

License

Notifications You must be signed in to change notification settings

msg-fabric/msg-fabric-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

msg-fabric-core

msg-fabric-core is a uniform messaging API for writing distributed (network) actors.

In a browser environment, use msg-fabric-core to communicate in the main context, an IFrame, a Web Worker, over an RTCDataChannel, or over a WebSocket.

In a NodeJS environment, communciate over TCP, TLS, duplex Streams, WebSockets, or use a plugin to bridge over NATS or MQTT.

Sent packets are synchronously cloned, thereby preventing accidental mutation. Furthermore, packets are only encoded to bytes when needed to transmit across a stream-oriented connection — WebSocket, RTCDataChannel, TCP/TLS, or similar stream.

A collection of ES6 modules are published for both NodeJS and Web platforms, as well as all the core plugins, to allow crafting a build including only is required to solve the problem at hand.

Inspired by:

Documentation

See reference docs and examples

Examples

import MsgFabric from 'msg-fabric-core' 
const hub = MsgFabric.create()
Add a Target
const tgt_addr = hub.local.addTarget(null, pkt => {
  console.log('pkt target received pkt:', pkt)

  if (pkt.body.id_reply) {
    console.log('replying to:', pkt.body.id_reply)
    hub.send( pkt.body.id_reply, { ts: new Date, echo: pkt.body })
  }
})
Send a message and await a reply
const reply = hub.local.addOnce()
hub.send(tgt_addr,
  { msg: 'hello readme example with reply',
    id_reply: reply.id
  })

let ans = await reply.promise
console.log('Received reply', ans) 

Connections and Platforms

Web Browser connections

Works out of the box with Web APIs like:

See plugins/web

NodeJS connections

Works out of the box with NodeJS APIs like:

See plugins/net

License

2-Clause BSD

About

Distributed live object messaging for NodeJS and the browser (core)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published