Methods for implementing DEP-0006: Session Data (Extension Message)


201.1.13 years ago3 years agoMinified + gzip package size for @beaker/dat-session-data-ext-msg in KB



Methods for implementing DEP-0006: Session Data (Extension Message).

const {DatSessionDataExtMsg} = require('@beaker/dat-session-data-ext-msg')
var datSessionDataExtMsg = new DatSessionDataExtMsg()

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

 * Step 2. Wire up each dat you create
datSessionDataExtMsg.watchDat(archiveOrHypercore) // can give a hyperdrive or hypercore
// datSessionDataExtMsg.unwatchDat(archiveOrHypercore) when done

 * Step 3. Listen to events
datSessionDataExtMsg.on('session-data', (archiveOrHypercore, peer, sessionData) => {
  // `peer` as set `sessionData` for `archiveOrHypercore`

 * Step 4. Use the API
datSessionDataExtMsg.hasSupport(archiveOrHypercore, peerId)
datSessionDataExtMsg.getSessionData(archiveOrHypercore, peerId)
datSessionDataExtMsg.setLocalSessionData(archiveOrHypercore, sessionData)
datSessionDataExtMsg.sendLocalSessionData(archiveOrHypercore, peerId)

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.