UNPKG

@casual-simulation/aux-common

Version:
56 lines 1.43 kB
import { Subject, NEVER, BehaviorSubject } from 'rxjs'; import { distinctUntilChanged } from 'rxjs/operators'; export class MemoryConnectionClient { get connectionState() { return this._connectionState.pipe(distinctUntilChanged()); } get isConnected() { return this._connectionState.value.connected; } get info() { return this._info; } set info(value) { this._info = value; } get indicator() { return this._indicator; } set indicator(value) { this._indicator = value; } get onError() { return this._onError; } event(name) { return this.events.get(name) || NEVER; } send(message) { this.sentMessages.push(message); } disconnect() { this._connectionState.next({ connected: false, info: null, }); } connect() { this._connectionState.next({ connected: true, info: this._info, }); } constructor(device) { this.events = new Map(); this.origin = 'http://localhost'; this._info = device; this._indicator = null; this.sentMessages = []; this._onError = new Subject(); this._connectionState = new BehaviorSubject({ connected: false, info: null, }); } } //# sourceMappingURL=MemoryConnectionClient.js.map