diff options
Diffstat (limited to 'packages/meshbay-android/app/src/main/assets/bridge/meshbay-bridge.js')
| -rw-r--r-- | packages/meshbay-android/app/src/main/assets/bridge/meshbay-bridge.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/packages/meshbay-android/app/src/main/assets/bridge/meshbay-bridge.js b/packages/meshbay-android/app/src/main/assets/bridge/meshbay-bridge.js index 7ace33b..b71b5e8 100644 --- a/packages/meshbay-android/app/src/main/assets/bridge/meshbay-bridge.js +++ b/packages/meshbay-android/app/src/main/assets/bridge/meshbay-bridge.js @@ -50,6 +50,10 @@ // per 48 KB chunk). Without ArrayBuffer messages, base64 over JSON. const SAVE_WRITE = 1; const CAST_PUSH = 2; + const CAST_FILE = 3; + // A file crosses in pieces this size: big enough to be few, small enough + // that no one message is a burden to the WebView or the bridge. + const FILE_PIECE = 1024 * 1024; const bytesOf = (chunk) => (chunk instanceof Uint8Array ? chunk : ArrayBuffer.isView(chunk) ? new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength) : new Uint8Array(chunk)); @@ -151,6 +155,19 @@ push: (data) => pushSegment(data), stop: () => call('cast:stop'), subtitle: (sub) => call('cast:subtitle', sub), + // A whole file — a photo, a track — in pieces: one message the size of a + // lossless track would be the WebView's to refuse. + file: async (f) => { + const bytes = bytesOf(f.bytes); + const cover = f.cover ? { bytes: base64Of(bytesOf(f.cover.bytes)), type: f.cover.type } : null; + await call('cast:file:begin', { type: f.type, size: bytes.length, cover, + title: f.title, artist: f.artist, album: f.album }); + for (let at = 0; at < bytes.length; at += FILE_PIECE) { + const piece = bytes.subarray(at, at + FILE_PIECE); + await (BINARY ? sendBinary(CAST_FILE, 0, piece) : call('cast:file:write', base64Of(piece))); + } + return call('cast:file:end'); + }, finish: () => call('cast:finish'), status: () => call('cast:status'), scan: () => call('cast:scan'), @@ -160,6 +177,7 @@ chromecastDisconnect: () => call('cast:chromecast:disconnect'), chromecastPause: () => call('cast:chromecast:pause'), chromecastPlay: () => call('cast:chromecast:play'), + chromecastSeek: (seconds) => call('cast:chromecast:seek', seconds), } } : {}), // Music is playing: keep the process, the Wi-Fi and the page awake with |