diff --git a/CHANGELOG.md b/CHANGELOG.md index cbafd473..40ef4237 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Update Metacom exports - Throw errors on wrong configs +- Update Client implementation in /distr ## [1.7.3][] - 2021-06-08 diff --git a/dist/metacom.js b/dist/metacom.js index 44ee5be4..cc4a9648 100644 --- a/dist/metacom.js +++ b/dist/metacom.js @@ -45,6 +45,7 @@ export class Metacom extends EventEmitter { this.api = {}; this.callId = 0; this.calls = new Map(); + this.streams = new Map(); this.active = false; this.connected = false; this.lastActivity = new Date().getTime(); @@ -89,6 +90,23 @@ export class Metacom extends EventEmitter { const metacomInterface = this.api[interfaceName]; metacomInterface.emit(eventName, args); } + if (callType === 'stream') { + const { name, size, status } = packet; + if (name) { + const stream = { name, size, chunks: [], received: 0 }; + this.streams.set(callId, stream); + return; + } + const stream = this.streams.get(callId); + if (status) { + this.streams.delete(callId); + const blob = new Blob(stream.chunks); + blob.text().then((text) => { + console.log({ text }); + }); + return; + } + } } } @@ -140,7 +158,10 @@ class WebsocketTransport extends Metacom { connections.add(this); socket.addEventListener('message', ({ data }) => { - this.message(data); + if (typeof data === 'string') { + this.message(data); + return; + } }); socket.addEventListener('close', () => {