StreamnoteManager

The StreamnoteManager is a simple store for Streamnote instances. It simplifies the use of Streamnote behind an API and/or when dealing with multiple streams.

Example of use:

import  {Streamnote, StreamnoteManager} from  "blocknote"

// Create a new Streamnote instance and save it into the store.
// Returns the UUID of the stored Streamnote instance & its payload_transaction_id
app.post('/create-new-stream', async (req, res) => {
    
    const options                = req.body?.options; // title, compression, encryption ...
    options.onFinish             = (result) => {
        //Do something with the result when stream ends.
    }
    options.onError              = (error) => {
        //Do something when an error happened.
    }
    const sender_mnemonic        = "gorilla shiver hood theory letter absorb arctic ...";
    const stream                 = new Streamnote(sender_mnemonic, options);
    const uuid                   = StreamnoteManager.store(stream);
    const payload_transaction_id = await StreamnoteManager.getPayloadTransactionId(uuid);
    
    res.send({uuid, payload_transaction_id});
});

// Send data on the given stream identified by the UUID.
app.post('/send/:uuid', (req, res) => {
    
    const uuid = req.params.uuid;
    const data = req.body.data;
   
    StreamnoteManager.send(uuid, data);
   
    res.send(true);
});

// Stop the stream identified by the UUID.
app.post('/stop/:uuid', (req, res) => {
    
    const uuid = req.params.uuid;
    
    StreamnoteManager.stop(uuid);
   
    res.send(true);
});

// List all the stored Streamnote instance(s).
app.get('/list', async (req, res) => {
            
    const list = await StreamnoteManager.list();
   
    res.send(list);
});

Methods

store

Parameters

Name
Description
Type

streamnote_instance

An instance of Streamnote

Streamnote

Return

A UUID that uniquely identifies the Streamnote instance in the store.

get

Parameters

Name
Description
Type

uuid

The UUID of the stored Streamnote instance

string

Return

The Streamnote instance stored under this UUID.


send

Parameters

Name
Description
Type

uuid

The UUID of the stored Streamnote instance

string

data

The data to send on the stream

string, Uint8Array, Buffer

Return

null


stop

Parameters

Name
Description
Type

uuid

The UUID of the stored Streamnote instance

string

Return

null, triggers the onFinish() callback of the Streamnote instance.

Last updated