客户端将所有图像永久存储在数据stream中

我正在实现一个节点服务器,它周期性地从networking摄像头抓取图像,并通过节点模块Delivery.js将它们发送到客户端。

但是,看看我的浏览器使用的资源(在Chrome开发工具中),似乎发送的每个映像都是由客户端(或可能由服务器?)无限期地存储的。

我使用的代码类似于Delivery.js自述文件中的“将文件推送到客户端”示例:

服务器代码

//set the camera to take a snapshot and send it for the required framerate setInterval(function(){ //take a snapshot of the current view cam.snapshot('./current_view.jpg' ,function( jpeg ) { //send this snapshot to client delivery.send({ name: 'current_view.jpg', path : './current_view.jpg' }); }) delivery.on('send.success',function(file){ //console.log('File successfully sent to client'); }); }, cameraUpdateDelay); 

客户端代码

  var delivery = new Delivery(socket); delivery.on('receive.start',function(fileUID){ //console.log('receiving a file!'); }); delivery.on('receive.success',function(file){ if (file.isImage()) { //change the src of the img tag to the new file $('img').attr('src', file.dataURL()); console.log(file); }; }); 

一旦收到下一个文件,是不可能删除每个文件的?

我只是简单地看一下客户端的源代码,并将每个接收到的图像添加到一个对象,图像的uuid是关键。 如果你想限制内存泄漏,在收到对象后删除对象可能是有意义的。 在https://github.com/liamks/Delivery.js/blob/master/lib/client/delivery.js的第140行,它被添加到对象:

 _this.receiving[file.uid] = filePackage; 

在上面,如果你修改'receive.success',看起来像:

 pubSub.subscribe('receive.success',function(filePackage){ _this.socket.emit('send.success',filePackage.uid); delete _this.receiving[filePackage.uid]; }); 

这应该修复内存泄漏。 但是,您可能需要进行一些testing,以确认它不会破坏其他任何内容。