Пример #1
0
exports.init_z2bEvents = function (req, res, next)
{
    let method = 'init_z2bEvents';
    if (bRegistered) {res.send('Already Registered');}
    else{
        bRegistered = true;
//        svc.createAlertSocket();
        let businessNetworkConnection;
        businessNetworkConnection = new BusinessNetworkConnection();
        businessNetworkConnection.setMaxListeners(50);
        //
        // v0.14
        // return businessNetworkConnection.connect(config.composer.connectionProfile, config.composer.network, config.composer.adminID, config.composer.adminPW)
        //
        // v0.15
        return businessNetworkConnection.connect(config.composer.adminCard)
        .then(() => {
            // using the businessNetworkConnection, start monitoring for events.
            // when an event is provided, call the _monitor function, passing in the al_connection, f_connection and event information
            businessNetworkConnection.on('event', (event) => {_monitor(req.app.locals, event); });
            res.send('event registration complete');
        }).catch((error) => {
            // if an error is encountered, log the error and send it back to the requestor
            console.log(method+' business network connection failed'+error.message);
            res.send(method+' business network connection failed'+error.message);
        });
    }
};