aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/static/transport.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/transport.js')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/transport.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/transport.js b/packages/meshbay-hub/src/meshbay_hub/static/transport.js
index 011c33e..1dc1ded 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/transport.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/transport.js
@@ -27,11 +27,17 @@ class MeshBayTransport {
this._recvBuf = new Uint8Array(0);
this._connected = false;
this._onChat = null;
+ this._onStreamInit = null;
+ this._onStreamData = null;
+ this._onStreamEnd = null;
}
get connected() { return this._connected; }
set onChat(fn) { this._onChat = fn; }
+ set onStreamInit(fn) { this._onStreamInit = fn; }
+ set onStreamData(fn) { this._onStreamData = fn; }
+ set onStreamEnd(fn) { this._onStreamEnd = fn; }
async connect(nodeId, jwtToken, groupId) {
this._pc = new RTCPeerConnection({
@@ -186,6 +192,10 @@ class MeshBayTransport {
return msg;
}
+ requestStream(fileId) {
+ this._send({ type: 'stream_req', v: '0.1', file_id: fileId });
+ }
+
async uploadChunk(filename, chunkIndex, totalChunks, data) {
const msg = await this._sendAndWait({
type: 'file_upload',
@@ -259,6 +269,18 @@ class MeshBayTransport {
this._onChat(msg);
return;
}
+ if (msg.type === 'stream_init' && this._onStreamInit) {
+ this._onStreamInit(msg);
+ return;
+ }
+ if (msg.type === 'stream_data' && this._onStreamData) {
+ this._onStreamData(msg);
+ return;
+ }
+ if (msg.type === 'stream_end' && this._onStreamEnd) {
+ this._onStreamEnd(msg);
+ return;
+ }
const oldest = this._pending.entries().next();
if (!oldest.done) {