================================================
FILE: misc/do-rtmpsuck.sh
================================================
#!/bin/bash
# enable internal port forwarding:
sudo sysctl -w net.inet.ip.forwarding=1
# apply the pf rules:
echo '
rdr pass log on lo0 proto tcp from en0 to any port 1935 -> 127.0.0.1
pass out on en0 route-to lo0 inet proto tcp from en0 to any port 1935 keep state user != root
' | sudo pfctl -ef -
# check the pf rules:
# sudo pfctl -s all
say "starting r-t-m-p-suck";
sudo rtmpsuck $@;
say "r-t-m-p-suck Stopped.";
# clear the pf rules:
echo ''
echo ''
echo "====== restting pfctl rules ======="
echo ''
sudo pfctl -F all -f /etc/pf.conf
================================================
FILE: misc/reloadChrome.scpt
================================================
on run {targetUrl}
tell application "Google Chrome"
activate
set theUrl to my remove_http(targetUrl)
if (count every window) = 0 then
make new window
end if
set found to false
set theTabIndex to -1
repeat with theWindow in every window
set theTabIndex to 0
repeat with theTab in every tab of theWindow
set theTabIndex to theTabIndex + 1
set theTabUrl to my remove_http(theTab's URL as string)
if (theTabUrl contains theUrl) then
set found to true
exit repeat
end if
end repeat
if found then
exit repeat
end if
end repeat
if found then
tell theTab to reload
set theWindow's active tab index to theTabIndex
set index of theWindow to 1
else
tell window 1 to make new tab with properties {URL:targetUrl}
end if
end tell
end run
on remove_http(input_url)
if (input_url contains "https://") then
return trim_line(input_url, "https://")
else
return trim_line(input_url, "http://")
end if
return input_url
end remove_http
-- Taken from: http://www.macosxautomation.com/applescript/sbrt/sbrt-06.html --
on trim_line(this_text, trim_chars)
set x to the length of the trim_chars
-- TRIM BEGINNING
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
return this_text
end trim_line
================================================
FILE: package.json
================================================
{
"name": "web-rtmp",
"version": "1.0.0",
"description": "Play rtmp video stream on the web page",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "yingDev",
"license": "ISC",
"dependencies": {
"babel-preset-es2015": "^6.16.0",
"broadway-player": "^0.1.1",
"buffer": "^5.0.0",
"simple-websocket": "^4.1.0"
},
"devDependencies": {
"babel-core": "^6.17.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.16.0",
"webpack": "^1.13.2",
"webpack-shell-plugin": "^0.4.3",
"websockify": "^0.7.1"
}
}
================================================
FILE: test.js
================================================
const WebRtmpPlayer = require('./WebRtmpPlayer');
//note: tcUrl是原始rtmp地址,不含流名称。参见rtmp spec
alert('set your rtmp params in test.js first!');
var player = new WebRtmpPlayer('ws://127.0.0.1:1999', '', '', 'rtmp:///');
player.canvas.style['height'] = '100%';
document.getElementById("vidCont").appendChild(player.canvas);
================================================
FILE: webpack.config.js
================================================
var webpack = require('webpack');
const WebpackShellPlugin = require('webpack-shell-plugin');
module.exports = {
entry: "./test.js",
output: {
path: __dirname + "/build/",
filename: "bundle.js"
},
devtool: "source-map",
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules, build)/,
loader: 'babel',
query: {
presets: ['es2015']
}
}
]
},
externals: {
"broadway": "broadway-player"
},
plugins:[
new webpack.optimize.DedupePlugin(),
new WebpackShellPlugin({
onBuildStart:[/*'say begin'*/],
onBuildEnd:[
'sed "s/{{buildTime}}/$(date)/g" index.template.html > index.html',
//'say end!'
//'say world; open "/Applications/Google Chrome.app"',
//'sleep 1; say chrome & osascript ./misc/reloadChrome.scpt "http://localhost:63342/web-rtmp/index.html"'
],
dev:false}
)
]
};