call(method, args) { return new Promise((resolve, reject) => { this.client.methodCall(method, [...args], (err, data) => { if (err) return reject(this.handleError(err)) resolve(data) }) }) }
constructor(host, port) { this._xmlrpcClient = xmlrpc.createClient({host: host, port: port}); }
constructor(endpoint, ssl) { const UA = pjson.name + ' v' + pjson.version const uri = endpoint || (ssl ? url_ssl : url) const req = URIjs(uri)._parts const secure = req.protocol === 'https' const opts = { host: req.hostname, port: req.port || (secure ? 443 : 80), path: req.path, headers: { 'User-Agent': UA } } this.client = secure ? xmlrpc.createSecureClient(opts) : xmlrpc.createClient(opts) }
const server = xmlrpc.createServer({port: xmlrpcPort}, () => { const {port} = server.httpServer.address(); this._debugLog.debug('Slave API Listening on port ' + port); this._xmlrpcPort = port; }); server.on('NotFound', (method, params) => { this._log.warn('Method ' + method + ' does not exist: ' + params); }); server.on('requestTopic', this._handleTopicRequest.bind(this)); server.on('publisherUpdate', this._handlePublisherUpdate.bind(this)); server.on('paramUpdate', this._handleParamUpdate.bind(this)); server.on('getPublications', this._handleGetPublications.bind(this)); server.on('getSubscriptions', this._handleGetSubscriptions.bind(this)); server.on('getPid', this._handleGetPid.bind(this)); server.on('shutdown', this._handleShutdown.bind(this)); server.on('getMasterUri', this._handleGetMasterUri.bind(this)); server.on('getBusInfo', this._handleGetBusInfo.bind(this)); server.on('getBusStats', this._handleGetBusStats.bind(this)); server.httpServer.on('clientError', (err, socket) => { this._log.error('XMLRPC Server socket error: %j', err); });
requestTopic(callerId, topic, protocols) { let data = [callerId, topic, protocols]; return new Promise((resolve, reject) => { this._xmlrpcClient.methodCall('requestTopic', data, (err, resp) => { if (err || resp[0] !== 1) { reject(err, resp); } else { resolve(resp); } }); }); }