├── package.json ├── README.md ├── ConcatenateBlobs.js └── index.html /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "concatenateblobs", 3 | "preferGlobal": true, 4 | "version": "1.0.3", 5 | "author": { 6 | "name": "Muaz Khan", 7 | "email": "muazkh@gmail.com", 8 | "url": "http://www.muazkhan.com/" 9 | }, 10 | "description": "Simply pass array of blobs. This javascript library will concatenate all blobs in single Blob object.", 11 | "scripts": { 12 | "start": "node ConcatenateBlobs.js" 13 | }, 14 | "main": "./ConcatenateBlobs.js", 15 | "repository": { 16 | "type": "git", 17 | "url": "https://github.com/muaz-khan/ConcatenateBlobs.git" 18 | }, 19 | "keywords": [ 20 | "concatenateblobs", 21 | "library", 22 | "javascript", 23 | "chrome", 24 | "firefox", 25 | "opera", 26 | "ie", 27 | "internet-explorer", 28 | "android", 29 | "concatenate-blobs", 30 | "concatenateblobs.js", 31 | "mergeblobs", 32 | "merge-blobs", 33 | "javascript-library", 34 | "muaz", 35 | "muaz-khan" 36 | ], 37 | "analyze": false, 38 | "license": "MIT", 39 | "readmeFilename": "README.md", 40 | "bugs": { 41 | "url": "https://github.com/muaz-khan/ConcatenateBlobs/issues", 42 | "email": "muazkh@gmail.com" 43 | }, 44 | "homepage": "https://www.webrtc-experiment.com/ConcatenateBlobs/", 45 | "_id": "concatenateblobs@", 46 | "_from": "concatenateblobs@" 47 | } 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## [ConcatenateBlobs.js](https://github.com/muaz-khan/ConcatenateBlobs) [](https://npmjs.org/package/concatenateblobs) [](https://npmjs.org/package/concatenateblobs) 2 | 3 | Demo: https://www.WebRTC-Experiment.com/ConcatenateBlobs/ 4 | 5 | > Simply pass array of blobs. 6 | > This javascript library will concatenate all blobs in single "Blob" object. 7 | 8 | It is MIT Licenced, which means that you can use it in any commercial/non-commercial product, free of cost. 9 | 10 | ``` 11 | npm install concatenateblobs 12 | 13 | # to use in nodejs 14 | var ConcatenateBlobs = require('concatenateblobs'); 15 | ConcatenateBlobs(array_of_blobs, blob_type, function(resultingBlob) { 16 | console.log(resultingBlob); 17 | }); 18 | ``` 19 | 20 | To use it: 21 | 22 | ```htm 23 | 24 | ``` 25 | 26 | ## 1. Link The Library 27 | 28 | ``` 29 | https://cdn.webrtc-experiment.com/ConcatenateBlobs.js 30 | 31 | // or 32 | https://www.webrtc-experiment.com/ConcatenateBlobs.js 33 | ``` 34 | 35 | ## 2. Use it 36 | 37 | ```javascript 38 | // 2nd argument is type of "resulting-blob" 39 | ConcatenateBlobs([arrayOfBlobs], 'audio/wav', function(resultingBlob) { 40 | 41 | POST_to_Server(resultingBlob); 42 | 43 | // or preview locally 44 | localVideo.src = URL.createObjectURL(resultingBlob); 45 | }); 46 | ``` 47 | 48 | ## Credits 49 | 50 | * [Muaz Khan](http://www.MuazKhan.com/) 51 | 52 | ## License 53 | 54 | [ConcatenateBlobs.js](https://github.com/muaz-khan/ConcatenateBlobs) is released under [MIT licence](https://www.webrtc-experiment.com/licence/) . Copyright (c) [Muaz Khan](http://www.MuazKhan.com/). 55 | -------------------------------------------------------------------------------- /ConcatenateBlobs.js: -------------------------------------------------------------------------------- 1 | // Last time updated at May 23, 2015, 08:32:23 2 | 3 | // Latest file can be found here: https://cdn.webrtc-experiment.com/ConcatenateBlobs.js 4 | 5 | // Muaz Khan - www.MuazKhan.com 6 | // MIT License - www.WebRTC-Experiment.com/licence 7 | // Source Code - https://github.com/muaz-khan/ConcatenateBlobs 8 | // Demo - https://www.WebRTC-Experiment.com/ConcatenateBlobs/ 9 | 10 | // ___________________ 11 | // ConcatenateBlobs.js 12 | 13 | // Simply pass array of blobs. 14 | // This javascript library will concatenate all blobs in single "Blob" object. 15 | 16 | (function() { 17 | function ConcatenateBlobs (blobs, type, callback) { 18 | var buffers = []; 19 | 20 | var index = 0; 21 | 22 | function readAsArrayBuffer() { 23 | if (!blobs[index]) { 24 | return concatenateBuffers(); 25 | } 26 | var reader = new FileReader(); 27 | reader.onload = function(event) { 28 | buffers.push(event.target.result); 29 | index++; 30 | readAsArrayBuffer(); 31 | }; 32 | reader.readAsArrayBuffer(blobs[index]); 33 | } 34 | 35 | readAsArrayBuffer(); 36 | 37 | function concatenateBuffers() { 38 | var byteLength = 0; 39 | buffers.forEach(function(buffer) { 40 | byteLength += buffer.byteLength; 41 | }); 42 | 43 | var tmp = new Uint16Array(byteLength); 44 | var lastOffset = 0; 45 | buffers.forEach(function(buffer) { 46 | // BYTES_PER_ELEMENT == 2 for Uint16Array 47 | var reusableByteLength = buffer.byteLength; 48 | if (reusableByteLength % 2 != 0) { 49 | buffer = buffer.slice(0, reusableByteLength - 1) 50 | } 51 | tmp.set(new Uint16Array(buffer), lastOffset); 52 | lastOffset += reusableByteLength; 53 | }); 54 | 55 | var blob = new Blob([tmp.buffer], { 56 | type: type 57 | }); 58 | 59 | callback(blob); 60 | } 61 | } 62 | 63 | if(typeof modules !== 'undefined') { 64 | modules.export = ConcatenateBlobs; 65 | } 66 | 67 | if(typeof window !== 'undefined') { 68 | window.ConcatenateBlobs = ConcatenateBlobs; 69 | } 70 | })(); 71 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 |
6 | You can record multiple blobs; then click "concatenateBlobs" button to concatenate all recorded blobs in single Blob. The resulting "single" Blob can be either played-back locally or pushed to server. 7 |8 | 9 | 51 | 52 |
57 | 0 blobs recorded. To concatenate all, click right-side button. 58 |
59 |165 | // https://cdn.webrtc-experiment.com/ConcatenateBlobs.js 166 | // or: npm install concatenateblobs 167 | 168 | // 2nd argument is type of "resulting-blob" 169 | ConcatenateBlobs([arrayOfBlobs], 'audio/wav', function(resultingBlob) { 170 | 171 | POST_to_Server(resultingBlob); 172 | 173 | // or preview locally 174 | localVideo.src = URL.createObjectURL(resultingBlob); 175 | }); 176 |177 | --------------------------------------------------------------------------------