我正在尝试实现socket.io-stream,并且在我的服务器端文件中它工作正常但在客户端:
这是clientide的首要部分,这是文件停止加载的地方,在ss.createStream()作为" ss"找不到。
var socket = io.connect();
var username = null;
var userarray = null;
var stream = ss.createStream();
var filename="profile.jpg";
ss(socket).emit('profile-image', stream, {name: filename});
fs.createReadStream(filename).pipe(stream);
它总是说ss没有定义,即使我已经将它添加到html的头部。
这是jade模板的顶部,脚本在head中定义。
doctype html
html
head
script(src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js")
script(src="/socket.io/socket.io.js", type="text/javascript")
script(src="script.js", type="text/javascript")
script(src="http://chaterix.com/node_modules/socket.io-stream/socket.io-stream.js")
script(src="char.js", type="text/javascript")
我的结构如下:
root
-public
--script.js (client side)
-node_modules
--socket.io-stream
---socket.io-stream.js (the file I am trying to use)
server.js (server side)
我也尝试使用browsify,开发人员写道:
$ npm install browserify -g
$ cd node_modules/socket.io-stream
$ browserify index.js -s ss > socket.io-stream.js
但这也没有帮助。
socket.io-stream.js: https://github.com/nkzawa/socket.io-stream/blob/master/socket.io-stream.js
这里是server.js(服务器端)的顶部
var http = require('http'),
express = require('express'),
app = express(),
jade = require('jade'),
server = http.createServer(app),
bodyParser = require('body-parser');
var io = require('socket.io');
var escape = require('escape-html');
io = io.listen(server);
var fs = require("fs");
var ss = require('socket.io-stream');
var path = require('path');
var Entities = require('html-entities').AllHtmlEntities;
entities = new Entities();
server.listen(3000);
答案 0 :(得分:0)
将socket.io-stream.js移动到您的public / js文件夹,并将此js文件包含在EJS或任何客户端视图文件中