Socket.io流在Safari上崩溃

时间:2015-03-31 09:19:23

标签: node.js sockets stream socket.io

我已设置Socket.io-stream来处理从客户端到服务器的视频上传,如下所示:

客户端:

var stream = ss.createStream();
ss(Socket).emit('beginUpload', stream, $scope.video);

var blobStream = ss.createBlobReadStream($scope.videoFile);
var size = 0;

$scope.uploading = true;

blobStream.on('data', function(chunk) {
    size += chunk.length;
    var progress = (size / $scope.videoFile.size * 100).toFixed(2);
    //console.log('progress', progress);
    if (progress != 100) {
        updateProgress(progress);
    }
});

blobStream.on('error', function(err) {
    console.log('ERROR', err);
});

blobStream.on('end', function() {
    Socket.emit('uploadComplete', $scope.video);
});

blobStream.pipe(stream);

服务器

ss(socket).on('beginUpload', function(stream, data) {

    // Save stream to file
    var filename = config.upload.tmpFolder+'/'+data.filename;

    stream.pipe(fs.createWriteStream(filename)).on('error', function(err) {
        console.log('crashed at begin upload', err);
    });
});

通过Chrome上传时一切正常,但是当我尝试使用Safari时,它有时可以工作,有时也不会。服务器上显示的错误是:

buffer.js:377
      throw new TypeError('Unknown encoding: ' + encoding);
            ^
TypeError: Unknown encoding: buffer
    at Buffer.write (buffer.js:377:13)
    at new Buffer (buffer.js:215:28)
    at IOStream.Readable.push (_stream_readable.js:122:15)
    at push (/home/user/www/node_modules/socket.io-stream/lib/iostream.js:147:20)
    at IOStream._onwrite (/home/user/www/node_modules/socket.io-stream/lib/iostream.js:153:5)
    at Socket._onwrite (/home/user/www/node_modules/socket.io-stream/lib/socket.js:231:10)
    at Socket.<anonymous> (/home/user/www/node_modules/socket.io-stream/node_modules/component-bind/index.js:21:15)
    at Socket.EventEmitter.emit (events.js:106:17)
    at Socket.onevent (/home/user/www/node_modules/socket.io/lib/socket.js:327:8)
    at Socket.onpacket (/home/user/www/node_modules/socket.io/lib/socket.js:287:12)

有人能告诉我什么是错的吗?非常感谢任何帮助。

谢谢!

0 个答案:

没有答案