Skip to content

Commit

Permalink
fixed #271 added "recordrtc-socketio@1.0.6"
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Jun 2, 2017
1 parent 926136e commit 56e466b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 171 deletions.
42 changes: 19 additions & 23 deletions RecordRTC-over-Socketio/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#### [RecordRTC over Socket.io](https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC/RecordRTC-over-Socketio) [![npm](https://img.shields.io/npm/v/recordrtc-socketio.svg)](https://npmjs.org/package/recordrtc-socketio) [![downloads](https://img.shields.io/npm/dm/recordrtc-socketio.svg)](https://npmjs.org/package/recordrtc-socketio)
# [RecordRTC over Socket.io](https://github.com/muaz-khan/RecordRTC/tree/master/RecordRTC-over-Socketio)

[![npm](https://img.shields.io/npm/v/recordrtc-socketio.svg)](https://npmjs.org/package/recordrtc-socketio) [![downloads](https://img.shields.io/npm/dm/recordrtc-socketio.svg)](https://npmjs.org/package/recordrtc-socketio)

<a href="https://nodei.co/npm/recordrtc-socketio/">
<img src="https://nodei.co/npm/recordrtc-socketio.png">
</a>

```
```sh
npm install recordrtc-socketio

// to run it!
node ./node_modules/recordrtc-socketio/server.js
cd ./node_modules/recordrtc-socketio/

# to run it!
node server.js

# now open: http://localhost:9001
```

There are some other NPM packages regarding RecordRTC:
Expand Down Expand Up @@ -73,34 +79,28 @@ socketio.on('merged', function (fileName) {
});
```

=

##### Windows Batch File (`merger.bat`)
# Windows Batch File (`merger.bat`)

`merger.bat` file is executed to invoke ffmpeg functionalities on windows:

```
```sh
@echo off
"C:\ffmpeg\bin\ffmpeg.exe" -i %1 -i %2 %3
```

**It is assumed that you already have installed ffmpeg on your system.** Though, EXE file is hard-coded to "C:\ffmpeg\bin\ffmpeg.exe" however you can easily edit it according to your own installations.

=

##### `.sh` file
# `.sh` file

`merger.sh` file is executed to invoke ffmpeg functionalities on Mac/Linux/etc.

```
```sh
ffmpeg -i video-file.webm -i audio-file.wav -map 0:0 -map 1:0 output-file-name.webm
```

Using Linux; ffmpeg installation is super-easy! You can install DEVEL packages as well.

=

##### How to install ffmpeg on windows?
# How to install ffmpeg on windows?

1. Download ffmpeg and extract ZIP file
2. Rename extracted directory to "ffmpeg"
Expand All @@ -113,22 +113,18 @@ Using Linux; ffmpeg installation is super-easy! You can install DEVEL packages a

http://www.wikihow.com/Install-FFmpeg-on-Windows

=

##### How to install ffmpeg on Mac OSX?
# How to install ffmpeg on Mac OSX?

Make sure you have **homebrew** installed. Then run following command:

```
brew install ffmpeg --with-libvpx --with-theora --whit-libogg --with-libvorbis
```

##### How to test?

In the node.js command prompt window; type `node server`. It will run socket.io server at port 8888. Then you can open index.html file on any webserver.
# How to test?

=
In the node.js command prompt window; type `node server`. It will run socket.io server at port `9001`. Then you can open index.html file on any webserver.

##### License
# License

[RecordRTC](https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC) is released under [MIT licence](https://www.webrtc-experiment.com/licence/) . Copyright (c) [Muaz Khan](https://plus.google.com/+MuazKhan).
2 changes: 1 addition & 1 deletion RecordRTC-over-Socketio/ffmpeg-output/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#### [RecordRTC over Socket.io](https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC/RecordRTC-over-Socketio)
#### [RecordRTC over Socket.io](https://github.com/muaz-khan/RecordRTC/tree/master/RecordRTC-over-Socketio)

# This directory is used for ffmpeg progress output.
32 changes: 18 additions & 14 deletions RecordRTC-over-Socketio/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<!--
// Muaz Khan - www.MuazKhan.com
// MIT License - www.WebRTC-Experiment.com/licence
// Experiments - github.com/muaz-khan/WebRTC-Experiment
// RecordRTC - github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC
// RecordRTC - github.com/muaz-khan/RecordRTC
// RecordRTC over
// Socket.io - github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC/RecordRTC-over-Socketio
// Socket.io - https://github.com/muaz-khan/RecordRTC/tree/master/RecordRTC-over-Socketio
-->

<!DOCTYPE html>
Expand All @@ -23,7 +22,7 @@
<link rel="author" type="text/html" href="https://plus.google.com/+MuazKhan">
<meta name="author" content="Muaz Khan">

<script src="https://www.webrtc-experiment.com/RecordRTC.js">
<script src="/node_modules/recordrtc/RecordRTC.js">
</script>
<script src="/socket.io/socket.io.js">
</script>
Expand Down Expand Up @@ -62,7 +61,7 @@
</head>

<body>
<h1><a href="https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC">RecordRTC</a> <a href="https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC/RecordRTC-over-Socketio">over Socket.io</a>
<h1><a href="https://github.com/muaz-khan/RecordRTC">RecordRTC</a> <a href="https://github.com/muaz-khan/RecordRTC/tree/master/RecordRTC-over-Socketio">over Socket.io</a>
</h1>
<p>
<video id="camera-preview" style="border: 1px solid rgb(15, 158, 238); width: 94%;"></video>
Expand All @@ -80,10 +79,7 @@ <h1><a href="https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRT
</div>

<script>
// you can set it equal to "false" to record only audio
var recordVideoSeparately = !!navigator.webkitGetUserMedia;

if (!!navigator.webkitGetUserMedia && !recordVideoSeparately) {
if (false /* for Microsoft Edge */) {
var cameraPreview = document.getElementById('camera-preview');
cameraPreview.parentNode.innerHTML = '<audio id="camera-preview" controls style="border: 1px solid rgb(15, 158, 238); width: 94%;"></audio> ';
}
Expand Down Expand Up @@ -113,8 +109,10 @@ <h1><a href="https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRT
mediaStream = stream;

recordAudio = RecordRTC(stream, {
type: 'audio',
recorderType: StereoAudioRecorder,
onAudioProcessStarted: function() {
recordVideoSeparately && recordVideo.startRecording();
recordVideo.startRecording();

cameraPreview.src = window.URL.createObjectURL(stream);
cameraPreview.play();
Expand All @@ -124,8 +122,14 @@ <h1><a href="https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRT
}
});

recordVideo = RecordRTC(stream, {
type: 'video'
var videoOnlyStream = new MediaStream();
stream.getVideoTracks().forEach(function(track) {
videoOnlyStream.addTrack(track);
});

recordVideo = RecordRTC(videoOnlyStream, {
type: 'video',
recorderType: !!navigator.mozGetUserMedia ? MediaStreamRecorder : WhammyRecorder
});

recordAudio.startRecording();
Expand All @@ -141,7 +145,7 @@ <h1><a href="https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRT
stopRecording.disabled = true;

// stop audio recorder
recordVideoSeparately && recordAudio.stopRecording(function() {
recordAudio.stopRecording(function() {
// stop video recorder
recordVideo.stopRecording(function() {

Expand Down Expand Up @@ -176,7 +180,7 @@ <h1><a href="https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRT

// if firefox or if you want to record only audio
// stop audio recorder
!recordVideoSeparately && recordAudio.stopRecording(function() {
recordAudio.stopRecording(function() {
// get audio data-URL
recordAudio.getDataURL(function(audioDataURL) {
var files = {
Expand Down
11 changes: 6 additions & 5 deletions RecordRTC-over-Socketio/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "recordrtc-socketio",
"preferGlobal": true,
"version": "1.0.5",
"version": "1.0.6",
"author": {
"name": "Muaz Khan",
"email": "muazkh@gmail.com"
Expand All @@ -19,7 +19,7 @@
"main": "./server.js",
"repository": {
"type": "git",
"url": "https://github.com/muaz-khan/WebRTC-Experiment.git"
"url": "https://github.com/muaz-khan/RecordRTC.git"
},
"keywords": [
"webrtc",
Expand All @@ -42,15 +42,16 @@
"node": ">=0.6"
},
"dependencies": {
"recordrtc": "latest",
"socket.io": "^1.0.6",
"fluent-ffmpeg": "^1.7.2",
"node-uuid": "^1.4.1"
},
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/muaz-khan/WebRTC-Experiment/issues"
"url": "https://github.com/muaz-khan/RecordRTC/issues"
},
"homepage": "https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC/RecordRTC-to-Nodejs",
"_id": "recordrtc-socketio@1.0.5",
"homepage": "https://github.com/muaz-khan/RecordRTC/tree/master/RecordRTC-over-Socketio",
"_id": "recordrtc-socketio@",
"_from": "recordrtc-socketio@"
}
16 changes: 8 additions & 8 deletions RecordRTC-over-Socketio/server.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
// Last time updated at July 07, 2014, 19:21:23
// Last time updated at June 02, 2017

// Muaz Khan - www.MuazKhan.com
// MIT License - www.WebRTC-Experiment.com/licence
// Experiments - github.com/muaz-khan/WebRTC-Experiment
// RecordRTC - github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC
// RecordRTC - github.com/muaz-khan/RecordRTC

// RecordRTC over Socket.io - github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC/RecordRTC-over-Socketio
// RecordRTC over Socket.io - https://github.com/muaz-khan/RecordRTC/tree/master/RecordRTC-over-Socketio
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs"),
uuid = require('node-uuid'),
port = process.argv[2] || 8888;
port = process.argv[2] || 9001;

console.log('http://localhost:' + port);

var app = http.createServer(function (request, response) {

var uri = url.parse(request.url).pathname,
filename = path.join(process.cwd(), uri);

path.exists(filename, function (exists) {
fs.exists(filename, function (exists) {
if (!exists) {
response.writeHead(404, {
"Content-Type": "text/plain"
Expand Down Expand Up @@ -47,8 +48,7 @@ var app = http.createServer(function (request, response) {
});
}).listen(parseInt(port, 10));

var sys = require('sys'),
path = require('path'),
var path = require('path'),
exec = require('child_process').exec;

var io = require('socket.io').listen(app);
Expand Down
120 changes: 0 additions & 120 deletions RecordRTC-over-Socketio/uploads/README.md
Original file line number Diff line number Diff line change
@@ -1,121 +1 @@
Your wav/webm files will be saved in this directory.

#### [RecordRTC over Socket.io](https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC/RecordRTC-over-Socketio)

This experiment:

1. Records audio/video separately as wav/webm
2. Emits both files using socket.io
3. Socket.io server end receives emitted data; and writes wav/web files to disk
4. Node.js code invokes ffmpeg to merge wav/webm in single "webm" file
5. Socket.io server emits `merged` event; and passes-back the URL of the merged file

Client side stuff:

```javascript
var socketio = io.connect('http://localhost:8888/');

var files = {
audio: {
name: fileName + '.wav',
type: 'audio/wav',
dataURL: dataURL.audio
},
video: {
name: fileName + '.webm',
type: 'video/webm',
dataURL: dataURL.video
}
};

socketio.emit('message', files);
```

Server side code that captures above data:

```javascript
io.sockets.on('connection', function(socket) {
socket.on('message', function(data) {
console.log('writing to disk');
writeToDisk(data.audio.dataURL, data.audio.name);
writeToDisk(data.video.dataURL, data.video.name);

merge(socket, data.audio.name, data.video.name);
});
});
```

After merging; server side code that passes back the URL of the merged file:

```javascript
socket.emit('merged', audioName.split('.')[0] + '-merged.webm');
```

Client-side code that receives merged-file URL:

```javascript
socketio.on('merged', function (fileName) {
cameraPreview.src = location.href + '/uploads/' + fileName;
cameraPreview.play();
});
```

=

##### Windows Batch File (`merger.bat`)

`merger.bat` file is executed to invoke ffmpeg functionalities on windows:

```
@echo off
"C:\ffmpeg\bin\ffmpeg.exe" -i %1 -i %2 %3
```

**It is assumed that you already have installed ffmpeg on your system.** Though, EXE file is hard-coded to "C:\ffmpeg\bin\ffmpeg.exe" however you can easily edit it according to your own installations.

=

##### `.sh` file

`merger.sh` file is executed to invoke ffmpeg functionalities on Mac/Linux/etc.

```
ffmpeg -i video-file.webm -i audio-file.wav -map 0:0 -map 1:0 output-file-name.webm
```

Using Linux; ffmpeg installation is super-easy! You can install DEVEL packages as well.

=

##### How to install ffmpeg on windows?

1. Download ffmpeg and extract ZIP file
2. Rename extracted directory to "ffmpeg"
3. Right click over "My Computer" icon and select "Properties" context-menu option
4. Select "Advance system settings" from top-left section
5. Click "Environment Variables..." button from "Advanced" tab
6. Click "New..." button and in the "Variable name" box, enter "Path".
7. In the "Variable value" box, enter extracted directory full URI e.g. "C:\ffmpeg"
8. Click "OK" and done!

http://www.wikihow.com/Install-FFmpeg-on-Windows

=

##### How to install ffmpeg on Mac OSX?

Make sure you have **homebrew** installed. Then run following command:

```
brew install ffmpeg --with-libvpx --with-theora --whit-libogg --with-libvorbis
```

##### How to test?

In the node.js command prompt window; type `node server`. It will run socket.io server at port 8888. Then you can open index.html file on any webserver.

=

##### License

[RecordRTC](https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC) is released under [MIT licence](https://www.webrtc-experiment.com/licence/) . Copyright (c) [Muaz Khan](https://plus.google.com/+MuazKhan).

0 comments on commit 56e466b

Please sign in to comment.