Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I add a server parameter to Solutions multiple streams #75

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
*.exe
42 changes: 42 additions & 0 deletions 1.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status

grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
tag Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
19 changes: 19 additions & 0 deletions MultipleExample/client.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>

<body>
<canvas id="canvas"></canvas>
<canvas id="canvas2"></canvas>
</body>

<script type="text/javascript" src="./js/jsmpeg.min.js"></script>
<script type="text/javascript">
player = new JSMpeg.Player('ws://localhost:9999/foo', {
canvas: document.getElementById('canvas') // Canvas should be a canvas DOM element
})

player2 = new JSMpeg.Player('ws://localhost:9999/bar', {
canvas: document.getElementById('canvas2') // Canvas should be a canvas DOM element
})
</script>

</html>
5 changes: 5 additions & 0 deletions MultipleExample/js/jsmpeg.min.js

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions MultipleExample/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var http = require('http');
var url = require('url');
var server = http.createServer();
var VideoStream;
VideoStream = require('../');
const WebSocket = require('ws');
const wss1 = new WebSocket.Server({ noServer: true });
const wss2 = new WebSocket.Server({ noServer: true });

const stream1 = new VideoStream({
name: 'name',
streamUrl: 'rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov',
Server: wss1,
ffmpegOptions: {
'-stats': '',
'-r': 30
}
})

const stream2 = new VideoStream({
name: 'name2',
streamUrl: 'rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov',
Server: wss2,
ffmpegOptions: {
'-stats': '',
'-r': 30
}
})

server.on('upgrade', function upgrade(request, socket, head) {
const pathname = url.parse(request.url).pathname;
if (pathname === '/foo') {
wss1.handleUpgrade(request, socket, head, function done(ws) {
wss1.emit('connection', ws, request);
});
} else if (pathname === '/bar') {
wss2.handleUpgrade(request, socket, head, function done(ws) {
wss2.emit('connection', ws, request);
});
} else {
socket.destroy();
}
});

server.listen(9999);
81 changes: 79 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $ npm install node-rtsp-stream
```

On server:
```
```js
Stream = require('node-rtsp-stream')
stream = new Stream({
name: 'name',
Expand All @@ -25,7 +25,7 @@ stream = new Stream({
```

On client:
```
```html
<html>
<body>
<canvas id="canvas"></canvas>
Expand All @@ -40,6 +40,83 @@ On client:
</html>
```

Multiple streaming solutions:
```js
var http = require('http');
var url = require('url');
var server = http.createServer();
var VideoStream;
VideoStream = require('../');
const WebSocket = require('ws');
const wss1 = new WebSocket.Server({ noServer: true });
const wss2 = new WebSocket.Server({ noServer: true });

const stream1 = new VideoStream({
name: 'name',
streamUrl: 'rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov',
Server: wss1,
ffmpegOptions: {
'-stats': '',
'-r': 30
}
})

const stream2 = new VideoStream({
name: 'name2',
streamUrl: 'rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov',
Server: wss2,
ffmpegOptions: {
'-stats': '',
'-r': 30
}
})

server.on('upgrade', function upgrade(request, socket, head) {
const pathname = url.parse(request.url).pathname;
if (pathname === '/foo') {
wss1.handleUpgrade(request, socket, head, function done(ws) {
wss1.emit('connection', ws, request);
});
} else if (pathname === '/bar') {
wss2.handleUpgrade(request, socket, head, function done(ws) {
wss2.emit('connection', ws, request);
});
} else {
socket.destroy();
}
});

server.listen(9999);
```

Multiple streaming on client
```html
<html>

<body>
<canvas id="canvas"></canvas>
<canvas id="canvas2"></canvas>
</body>

<script type="text/javascript" src="./js/jsmpeg.min.js"></script>
<script type="text/javascript">
player = new JSMpeg.Player('ws://localhost:9999/foo', {
canvas: document.getElementById('canvas') // Canvas should be a canvas DOM element
})

player2 = new JSMpeg.Player('ws://localhost:9999/bar', {
canvas: document.getElementById('canvas2') // Canvas2 should be a canvas DOM element
})
</script>

</html>
```

ps: you can run the MultipleExample and open \MultipleExample\client.html on your Browser.
```js
node .\MultipleExample\server.js
```

For more information on how to use jsmpeg to stream video, visit https://github.com/phoboslab/jsmpeg

Please note that framerate from cameras must be greater than or equal to 15fps for mpeg1 encoding, otherwise ffmpeg errors will prevent video encoding to occur. If you have a camera with advanced configuration options, make sure it streams video at a recommended 25fps.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"author": "David Jsa <david@jsa.me>",
"license": "MIT",
"devDependencies": {
"mocha": "^5.2.0"
"http": "^0.0.1-security",
"mocha": "^5.2.0",
"url": "^0.11.0"
},
"dependencies": {
"ws": "^7.0.0"
Expand Down
4 changes: 3 additions & 1 deletion videoStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ VideoStream = function(options) {
this.streamUrl = options.streamUrl
this.width = options.width
this.height = options.height
this.Server = options.Server
this.wsPort = options.wsPort
this.inputStreamStarted = false
this.stream = undefined
Expand Down Expand Up @@ -88,7 +89,8 @@ VideoStream.prototype.startMpeg1Stream = function() {
}

VideoStream.prototype.pipeStreamToSocketServer = function() {
this.wsServer = new ws.Server({

this.wsServer = this.Server || new ws.Server({
port: this.wsPort
})
this.wsServer.on("connection", (socket, request) => {
Expand Down