Skip to content

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

Notifications You must be signed in to change notification settings

dBrowser/dweb-ephemeral-ext-msg

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dat-ephemeral-ext-msg

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

const {DatEphemeralExtMsg} = require('dweb-epemeral-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 ddatabase, hyperdb, or dwebfs 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})

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%