UNPKG

@berish/rfp

Version:

Binary secure transport organization protocol for peer communication using function fingerprints

58 lines 2.4 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ServiceChannel = void 0; const const_1 = require("../const"); class ServiceChannel { constructor(peer) { this._peer = null; if (!peer) throw new TypeError('PeerServiceChannel peer is null'); this._peer = peer; } get peer() { return this._peer; } send(moduleName, commandName, data, options) { return __awaiter(this, void 0, void 0, function* () { options = options || {}; const commandData = { moduleName, commandName, data, }; const response = yield this.peer.send(Object.assign({ path: const_1.magicalDictionary.serviceChannel, body: commandData }, options)); const responseCommandData = { moduleName, commandName, data: response.body, }; return responseCommandData; }); } receive(moduleName, commandName, listener) { return this.peer.receive(const_1.magicalDictionary.serviceChannel, ({ chunk, peer }, next) => { const { body } = chunk; if (!body.moduleName || !body.commandName) return next(); if (body.moduleName !== moduleName) return next(); if (body.commandName !== commandName) return next(); return listener({ chunk, peer, serviceData: body.data }, next); }); } unreceive(receiveHash) { this.peer.unreceive(receiveHash); } } exports.ServiceChannel = ServiceChannel; //# sourceMappingURL=serviceChannel.js.map