0.9.8 • Published 2 years ago

msg-fabric-core v0.9.8

Weekly downloads
1
License
BSD-2-Clause
Repository
github
Last release
2 years ago

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

0.9.8

2 years ago

0.9.7

2 years ago

0.9.4

2 years ago

0.9.6

2 years ago

0.9.5

2 years ago

0.9.3

2 years ago

0.9.0-14

2 years ago

0.9.0-13

2 years ago

0.9.0

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.9.0-12

2 years ago

0.9.0-10

2 years ago

0.9.0-9

2 years ago

0.9.0-11

2 years ago

0.9.0-8

2 years ago

0.9.0-7

3 years ago

0.9.0-6

3 years ago

0.9.0-4

3 years ago

0.9.0-3

3 years ago

0.9.0-2

3 years ago

0.9.0-1

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.6

5 years ago

0.7.5

5 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.5.17

6 years ago

0.5.16

6 years ago

0.5.15

6 years ago

0.5.14

6 years ago

0.5.13

6 years ago

0.5.12

6 years ago

0.5.10

6 years ago

0.5.9

6 years ago

0.5.8

6 years ago

0.5.7

6 years ago

0.5.6

6 years ago

0.5.4

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.2.0

7 years ago