UNPKG

@skyway-sdk/core

Version:

The official Next Generation JavaScript SDK for SkyWay

33 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RemoteDataStream = void 0; const common_1 = require("@skyway-sdk/common"); const data_1 = require("../local/data"); const base_1 = require("./base"); class RemoteDataStream extends base_1.RemoteStreamBase { /**@internal */ constructor(id, /**@internal */ _datachannel) { super(id, 'data'); this._datachannel = _datachannel; this._isEnabled = true; this.contentType = 'data'; this.onData = new common_1.Event(); _datachannel.onmessage = ({ data }) => { if (!this._isEnabled) { return; } if (typeof data === 'string' && data.includes(data_1.objectFlag)) { data = JSON.parse(data.slice(data_1.objectFlag.length)); } this.onData.emit(data); }; } /**@internal */ setIsEnabled(b) { this._isEnabled = b; } } exports.RemoteDataStream = RemoteDataStream; //# sourceMappingURL=data.js.map