Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@beaker/dat-ephemeral-ext-msg

Package Overview
Dependencies
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@beaker/dat-ephemeral-ext-msg

Methods for implementing DEP-0000: Ephemeral Messages (Extension Message)

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

dat-ephemeral-ext-msg

Methods for implementing ephemeral messages as extension messages over Dat. Read the spec here.

const {DatEphemeralExtMsg} = require('@beaker/dat-ephemeral-ext-msg')
var datEphemeralExtMsg = new DatEphemeralExtMsg()

/**
 * Step 1. Register the 'ephemeral' extension in the protocol streams
 */
var mySwarm = discoverySwarm(swarmDefaults({
  stream (info) {
    // add to the the protocol stream
    var stream = hypercoreProtocol({
      extensions: ['ephemeral']
    })
    // ...
    return stream
  }
}))

/**
 * Step 2. Wire up each dat you create
 */
datEphemeralExtMsg.watchDat(dat) // can pass a hypercore, hyperdb, or hyperdrive reference as the dat
// datEphemeralExtMsg.unwatchDat(dat) when done

/**
 * Step 3. Listen to events
 */
datEphemeralExtMsg.on('message', (dat, peer, {contentType, payload}) => {
  // `peer` has sent `payload` of mimetype `contentType` for `dat`
})
datEphemeralExtMsg.on('received-bad-message', (err, dat, peer, messageBuffer) => {
  // there was an error parsing a received message
})

/**
 * Step 4. Use the API
 */
datEphemeralExtMsg.hasSupport(dat, peerId)
datEphemeralExtMsg.broadcast(dat, {contentType, payload})
datEphemeralExtMsg.send(dat, peerId, {contentType, payload})

Keywords

FAQs

Package last updated on 10 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc