【发布时间】:2014-11-26 10:15:19
【问题描述】:
您好,我正在尝试将同步视频客户端作为一种爱好,让我们不要深入研究使客户端实际工作,因为我有点想自己弄清楚,您如何能够帮助我我当前的问题。
好的,我从 socket.io 网站上的“hello world”介绍开始,作为学习如何传递消息的一种方式,在那里我处理了用户如何连接以及如何以相同的方式为他们提供 HTML。用户连接到 index.js 并将 HTML 交给他们。 html 所做的只是向他们展示视频并在用户暂停时进行监听。
这里是 JS
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendfile('index.html');
});
io.on('connection', function(socket){
console.log('a user connected');
socket.on('disconnect', function(){
console.log('user disconnected');
});
});
io.on('connection', function(socket){
socket.on('message', function(msg){
console.log('message: ' + msg);
});
});
io.on('connection', function(socket){
socket.on('message', function(msg){
io.emit('message', msg);
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
here is the html
<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
</head>
<body>
<center> <p><video src="test.mp4" controls></video></p> </center>
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
var socket = io();
var video = $_("video");
video.addEventListener("timeupdate", function() {
socket.emit('message', "pause");
}, true);
</script>
</body>
</html>
如果我连接到 js 指定的目标,则找不到视频。如果我只是在浏览器中打开 HTML,视频会很好
我必须把视频放在哪里让 js 找到它?我必须指定完整路径吗?
【问题讨论】:
-
如果你只是在玩这一切,我会建议使用 WebRTC 和 websockets 进行媒体流。它是专门为此目的而制作的。为集中式消息处理或类似操作保留套接字。