@berish/rfp
Version:
Binary secure transport organization protocol for peer communication using function fingerprints
46 lines • 1.41 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PeerConnection = void 0;
const peer_1 = require("../peer");
class PeerConnection {
constructor(peer, transport) {
this._transport = null;
this._peer = null;
this._connectionId = null;
this._isEnabled = false;
if (!peer)
throw new TypeError('PeerConnection peer is null');
if (!transport)
throw new TypeError('PeerConnection transport is null');
this._transport = transport;
this._peer = peer;
}
get transport() {
return this._transport;
}
get peer() {
return this._peer;
}
get isEnabled() {
return !!this._connectionId;
}
transportConnect() {
if (!this.isEnabled)
this._connectionId = this._transport.subscribe(this.peer, (data) => {
const request = peer_1.createRequest(this.peer, data);
peer_1.emit(request);
});
}
transportDisconnect() {
if (this.isEnabled) {
this._transport.unsubscribe(this._connectionId);
this._connectionId = null;
}
}
static create(transport, peer) {
const connection = new PeerConnection(peer, transport);
return connection;
}
}
exports.PeerConnection = PeerConnection;
//# sourceMappingURL=connection.js.map