Skip to content

Commit

Permalink
Reliable-Signaler, ConcatenateBlobs, RecordRTC,RTCMultiConnection and…
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Nov 21, 2014
1 parent a382abf commit a71ee26
Show file tree
Hide file tree
Showing 139 changed files with 27,085 additions and 59,071 deletions.
11 changes: 6 additions & 5 deletions ConcatenateBlobs/ConcatenateBlobs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated at Sep 15, 2014, 08:32:23
// Last time updated at Nov 18, 2014, 08:32:23

// Latest file can be found here: https://cdn.webrtc-experiment.com/ConcatenateBlobs.js

Expand Down Expand Up @@ -39,16 +39,17 @@
buffers.forEach(function(buffer) {
byteLength += buffer.byteLength;
});

var tmp = new Uint16Array(byteLength);

var lastOffset = 0;
buffers.forEach(function(buffer) {
// BYTES_PER_ELEMENT == 2 for Uint16Array
if (buffer.byteLength % 2 != 0) {
delete buffer[byteLength - 1];
var reusableByteLength = buffer.byteLength;
if (reusableByteLength % 2 != 0) {
buffer = buffer.slice(0, reusableByteLength - 1)
}
tmp.set(new Uint16Array(buffer), lastOffset);
lastOffset += buffer.byteLength;
lastOffset += reusableByteLength;
});

var blob = new Blob([tmp.buffer], {
Expand Down
11 changes: 4 additions & 7 deletions ConcatenateBlobs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ To use it:

```
https://cdn.webrtc-experiment.com/ConcatenateBlobs.js
// or
https://www.webrtc-experiment.com/ConcatenateBlobs.js
```

## 2. Use it
Expand All @@ -38,13 +41,7 @@ ConcatenateBlobs([arrayOfBlobs], 'audio/wav', function(resultingBlob) {

## Credits

[Muaz Khan](https://github.com/muaz-khan):

1. Personal Webpage: http://www.muazkhan.com
2. Email: [email protected]
3. Twitter: https://twitter.com/muazkh and https://twitter.com/WebRTCWeb
4. Google+: https://plus.google.com/+WebRTC-Experiment
5. Facebook: https://www.facebook.com/WebRTC
* [Muaz Khan](http://www.MuazKhan.com/)

## License

Expand Down
58 changes: 45 additions & 13 deletions ConcatenateBlobs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h1>ConcatenateBlobs | JavaScript - <a href="https://github.com/muaz-khan/Concat
</blockquote>

<style>
button {
button, select {
font-family: Myriad, Arial, Verdana;
font-weight: normal;
border-top-left-radius: 3px;
Expand All @@ -23,10 +23,16 @@ <h1>ConcatenateBlobs | JavaScript - <a href="https://github.com/muaz-khan/Concat
background: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(0.05, rgb(241, 241, 241)), to(rgb(230, 230, 230)));
font-size: 20px;
border: 1px solid red;
outline:none;
}
button[disabled] {
background: rgba(216, 205, 205, 0.2);
border: 1px solid rgb(233, 224, 224);
button:active, button:focus, select:active {
background: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(5%, rgb(221, 221, 221)), to(rgb(250, 250, 250)));
border: 1px solid rgb(142, 142, 142);
}
button[disabled], select[disabled] {
background: rgb(249, 249, 249);
border: 1px solid rgb(218, 207, 207);
color: rgb(197, 189, 189);
}
blockquote {
font-size: 20px;
Expand All @@ -52,13 +58,17 @@ <h1>ConcatenateBlobs | JavaScript - <a href="https://github.com/muaz-khan/Concat
</p>
<hr />

<audio controls></audio>
<select>
<option>Audio</option>
<option>Video</option>
</select><br><br>
<audio controls data-type="audio/wav"></audio>

<script src="https://cdn.webrtc-experiment.com/RecordRTC.js" autoplay> </script>
<script src="https://cdn.webrtc-experiment.com/ConcatenateBlobs.js" autoplay> </script>

<script>
var audio = document.querySelector('audio');
var mediaElement = document.querySelector('audio');

var recordRTC;
var allBlobs = [];
Expand All @@ -68,14 +78,18 @@ <h1>ConcatenateBlobs | JavaScript - <a href="https://github.com/muaz-khan/Concat
document.querySelector('#concatenateBlobs').disabled = true;

navigator.getUserMedia({
audio: true
audio: mediaElement.getAttribute('data-type') == 'audio/wav',
video: mediaElement.getAttribute('data-type') == 'video/webm'
}, function(stream) {
localMediaStream = stream;

audio.src = URL.createObjectURL(stream);
audio.play();
mediaElement.src = URL.createObjectURL(stream);
mediaElement.play();

recordRTC = RecordRTC(stream);
recordRTC = RecordRTC(stream, {
type: mediaElement.getAttribute('data-type') == 'audio/wav' ? 'audio' : 'video',
video: mediaElement
});
recordRTC.startRecording();

document.querySelector('#stopRecording').disabled = false;
Expand Down Expand Up @@ -108,11 +122,11 @@ <h1>ConcatenateBlobs | JavaScript - <a href="https://github.com/muaz-khan/Concat

var parent = output.parentNode;
parent.innerHTML = 'Concatenating ' + allBlobs.length + ' blobs.';
ConcatenateBlobs(allBlobs, 'audio/wav', function(resultingBlob) {
ConcatenateBlobs(allBlobs, mediaElement.getAttribute('data-type'), function(resultingBlob) {
parent.innerHTML = 'Concatenated. Resulting blob size: <span>' + bytesToSize(resultingBlob.size) + '</span>. Playing-back locally in &lt;audio&gt; tag.';

audio.src = URL.createObjectURL(resultingBlob);
audio.play();
mediaElement.src = URL.createObjectURL(resultingBlob);
mediaElement.play();
});
};

Expand All @@ -126,6 +140,24 @@ <h1>ConcatenateBlobs | JavaScript - <a href="https://github.com/muaz-khan/Concat
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(k)), 10);
return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
}

document.querySelector('select').onchange = function() {
if(this.value == 'Video') {
var video = document.createElement('video');
video.setAttribute('data-type', 'video/webm');
video.setAttribute('controls', 'true');
mediaElement.parentNode.replaceChild(video, mediaElement);
mediaElement = video;
}

if(this.value == 'Audio') {
var video = document.createElement('audio');
video.setAttribute('data-type', 'audio/wav');
video.setAttribute('controls', 'true');
mediaElement.parentNode.replaceChild(video, mediaElement);
mediaElement = video;
}
};
</script>

<h2>How to use?</h2>
Expand Down
4 changes: 2 additions & 2 deletions ConcatenateBlobs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "concatenateblobs",
"preferGlobal": true,
"version": "1.0.0",
"version": "1.0.2",
"author": {
"name": "Muaz Khan",
"email": "[email protected]",
Expand Down Expand Up @@ -42,6 +42,6 @@
"email": "[email protected]"
},
"homepage": "https://www.webrtc-experiment.com/ConcatenateBlobs/",
"_id": "concatenateblobs@1.0.0",
"_id": "concatenateblobs@",
"_from": "concatenateblobs@"
}
9 changes: 4 additions & 5 deletions DataChannel/DataChannel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated at May 21, 2014, 08:32:23
// Last time updated at Nov 21, 2014, 08:32:23

// Muaz Khan - www.MuazKhan.com
// MIT License - www.WebRTC-Experiment.com/licence
Expand Down Expand Up @@ -172,7 +172,7 @@

prepareInit(function () {
init();
if (IsDataChannelSupported) dataConnector.createRoom();
if (IsDataChannelSupported) dataConnector.createRoom(_channel);
});
};

Expand Down Expand Up @@ -536,7 +536,6 @@
var defaultSocket = root.openSignalingChannel({
onmessage: function (response) {
if (response.userToken == self.userToken) return;

if (isGetNewRoom && response.roomToken && response.broadcaster) config.ondatachannel(response);

if (response.newParticipant) onNewParticipant(response.newParticipant);
Expand All @@ -558,8 +557,8 @@
});

return {
createRoom: function () {
self.roomToken = uniqueToken();
createRoom: function (roomToken) {
self.roomToken = roomToken || uniqueToken();

isbroadcaster = true;
isGetNewRoom = false;
Expand Down
Loading

0 comments on commit a71ee26

Please sign in to comment.