/** * We extend the definition of send() to allow Node Buffer. However * ArrayBufferView and Blob do not exist in Node. */ send(data) { if (this._readyState !== 'open') throw new errors_1.InvalidStateError('not open'); if (typeof data === 'string') { this._channel.notify('datachannel.send', this._internal, data); } else if (data instanceof ArrayBuffer) { const buffer = Buffer.from(data); this._channel.notify('datachannel.sendBinary', this._internal, buffer.toString('base64')); } else if (data instanceof Buffer) { this._channel.notify('datachannel.sendBinary', this._internal, data.toString('base64')); } else { throw new TypeError('invalid data type'); } }
logger.debug('request() [method:%s, id:%s]', method, id); if (this._closed) throw new errors_1.InvalidStateError('Channel closed'); const request = { id, method, internal, data }; const ns = netstring.nsWrite(JSON.stringify(request)); close: () => { clearTimeout(sent.timer); pReject(new errors_1.InvalidStateError('Channel closed'));