0.4.0-beta-19 • Published 7 months ago

@wishcore/wish-sdk v0.4.0-beta-19

Weekly downloads
52
License
Apache-2.0
Repository
github
Last release
7 months ago

Wish Api

A library for building Wish applications.

Install

npm install @wishcore/wish-sdk

Example

const { App } = require('@wishcore/wish-sdk');

const app = new App({
    name: process.env.SID || 'MyApp',
    corePort: parseInt(process.env.CORE, 10) || 9094,
    protocols: ['chat'] });

app.on('ready', (ready) => {
    app.request('identity.create', ['John Doe'], (err, data) => {
        if (err && data.code === 304) { return console.log('Using existing identity'); }
        console.log('Identity created:', err, data);
    });
});

app.on('online', (peer) => {
    app.request('services.send', [peer, Buffer.from('Permissionless innovation!')], (err, data) => {
        // sent or not?
    });
});

app.on('frame', (peer, data) => {
    app.request('identity.get', [peer.ruid], function(err, user) {
        console.log(user.alias, 'says:', data.toString());
    });
});