Skip to content

Commit

Permalink
Combine Client implementation
Browse files Browse the repository at this point in the history
Closes: #202

PR-URL: #203
  • Loading branch information
tshemsedinov committed Jun 22, 2021
1 parent e8a1dc9 commit 2d37779
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Update Metacom exports
- Throw errors on wrong configs
- Update Client implementation in /distr

## [1.7.3][] - 2021-06-08

Expand Down
23 changes: 22 additions & 1 deletion dist/metacom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
}
}

Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 2d37779

Please sign in to comment.