Last active
August 29, 2015 14:16
-
-
Save hpcslag/91bbabfd73f675adb0e4 to your computer and use it in GitHub Desktop.
WebRTC_Stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Hello World</title> | |
<script type="text/javascript" src="./socket.io/socket.io.js" ></script> | |
<script> | |
var socket = io('http://localhost'); | |
socket.on('connect',function(){ | |
console.log("Hello World"); | |
socket.emit('event',15); | |
}); | |
socket.on('event',function(data){ | |
console.log(data); | |
}); | |
socket.on('disconnect',function(){}); | |
</script> | |
</head> | |
<body> | |
Hello World | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm install express && npm install socket.io | |
var express = require('express') | |
var app = express() | |
var io = require('socket.io')(app); | |
app.configure(function() { | |
app.set('views', __dirname + '/'); //views engine path (.ejs file) 使用ejs模板引擎(簡單的說寫法跟html一樣) | |
app.set('view engine', 'ejs'); | |
app.use(app.router); //open routers | |
}); | |
app.get('/', function (req, res) { | |
res.rander('index');//渲染前端接收模板 | |
}) | |
io.on('connection',function(socket){ //create connection listener 進入連線事件 | |
socket.on('event',function(data){ | |
//data transfer to client use rander('index', {stream: data}) 將這個資料轉送到連線端 | |
}) | |
}) | |
app.listen(3000); | |
io.listen(app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment