Not being used, DEPRECATED IN FAVOR OF peer-base
Peerpad core API
$ npm install peerpad-core --save
const PeerpadBackend = require('peerpad-core')
Returns a random pad name (string).
Generates a set of read and write random keys.
Returns a promise that resolves to:
{
"read": "base58-encoded string",
"write": "base58-encoded string",
}
Creates a Peerpad backend.
const backend = PeerpadBackend(options)
Options:
ipfs
: IPFS (version 0.27 or higher) node that is already created (optional). If not passed in, one will be created for you.
The IPFS node.
Starts the backend. Returns a promise that resolves once the backend has started.
Stops the backend.
Returns a boolean, true
if the IPFS node has started.
Emitted once the IPFS node starts. If you passed in an IPFS node that is already started (via options.ipfs
), this event doesn't get emitted.
const options = {
name: 'name of the pad',
type: 'richtext',
readKey: 'gobelegook',
writeKey: 'moregobelegook'
}
const document = backend.createDocument(options)
name
: string that uniquely identifies thistype
: string that identifies type of document. Currently supportstext
,richtext
ormath
.readKey
: string containing the read keywriteKey
: string containing the write key (optional)peerAlias
: string identifying the current author. Defaults to the IPFS peerId
Returns an array of peers:
document.peers.all()
// returns:
[
{
id: 'QmHashHash1',
permissions: {
admin: false,
write: true,
read: true
}
},
{
id: 'QmHashHash2',
permissions: {
admin: false,
write: false,
read: true
}
}
]
Emitted when there is a change in the peer list:
document.peers.on('change', () => {
console.log('peers changed and now are', peerpad.peers.all())
})
Sets the current peer alias. peerAlias
must be a string.
Bind CodeMirror editor (for pad of type markdown
or text
) or Quill editor (for pad of type richtext
).
Two-way bind to a editor. Example for Quill:
import Quill from 'quill'
const editor = new Quill('#editor')
document.bindEditor(editor)
Example for CodeMirror:
import Codemirror from 'codemirror'
const editor = CodeMirror.fromTextArea(myTextArea)
document.bindEditor(editor)
Unbinds editor.
Bind the document title to an editing element (like a textarea or a text input field).
Unbind the document title from an editing element.
Converts markdown to HTML.
Emitted when the document changes. fn
is called with the arguments:
peer
(a Peer object)operation
(object of type Operation, see further down)
Returns a promise
peerpad.snapshots.take().then((hash) => {
console.log('snapshot hash: ', hash)
})
Returns an Event Emitter that emits the following events:
const emitter = document.network.observe()
emitter.on('received message', (fromPeer, message) => {
console.log('received message from %s: %j', fromPeer, message)
})
const emitter = document.network.observe()
emitter.on('sent message', (toPeer, message) => {
console.log('sent message to %s: %j', toPeer, message)
})
const emitter = document.network.observe()
emitter.on('peer joined', (peer) => {
console.log('peer %s joined room', peer)
})
const emitter = document.network.observe()
emitter.on('peer left', (peer) => {
console.log('peer %s left room', peer)
})
Stop observing events. No network events get emitted after calling this.
MIT