终止由img ng-src导致的未使用的http连接 [英] Terminating unused http connections that are a result of img ng-src

查看:283
本文介绍了终止由img ng-src导致的未使用的http连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发iOS和Android应用程序(使用离子/角度)

I am developing an iOS and Android app (using ionic/angular)

我有以下情况:

我认为基本上是这样的:

I have a view that basically does this:

<div ng-repeat="monitor in monitors">
  <img ng-src = 'http://myserver.com/cgi-bin/videoFeed?id={{monitor}}' />
</div>

每台显示器实际上都是一台IP摄像机,我们在这里做的是将实时馈送作为连续的JPG图像传输(多部分/ MIME)。

Each monitor is actually an IP camera and what we are doing here is transmitting live feed as continuous JPG images (multipart/mime).

因此,img标签不断显示新图像,使其看起来像实时视频

What therefore happens is the img tag keeps showing new images continuously making it look like a live video feed

我面临的问题是当我们退出视图时,看起来像angular仍然保持HTTP连接打开,服务器因此保持连接打开。服务器每个连接启动一个'videoFeed'实例,我可以看到实例在退出视图后很长时间(15-20分钟)不会消失。

The problem I am facing is when we exit the view, it looks like angular still keeps the HTTP connection open and the server keeps the connection open on its side as a result. The server launches an instance of 'videoFeed' per connection, and I can see the instances don't go away even long after (15-20 minutes) I exit the view.

有没有办法从客户端强行清除这些连接?

Is there any possible way to clear out these connections forcibly from the client?

我在SO中搜索了其他类似的问题,他们都讨论了HTTP超时 - 这与我的情况无关,因为这是一个不断更新的图片Feed,只有一张图片标记和唯一需要中止的时间是我们退出视图。

I searched in SO for other such questions and they all talk about HTTP timeouts - which is not relevant in my case, as this is a continuously updating image feed with one image tag and the only time it needs to abort is when we exit the view.

谢谢

推荐答案

我有一个理论,但不知道它是否有效。我猜你的网址指向图像并且图像正在更新,连接将保持打开状态,或者在图像更改时重新打开。那么当用户离开状态时,如何使用ng-if从dom中删除列表。

I have a theory but no idea if it will work. I am guessing as long your url is pointed at image and that image is being updated the connection will stay open, or re-open when the image changes. So how about when the user leaves the state you remove the list from the dom using ng-if.

所以这是如何实现的。

so here is how that is achieved.

在控制器中:

$scope.$on('$ionicView.beforeEnter', function(){
    $scope.inView = true;
})

$scope.$on('$ionicView.beforeLeave', function(){
    $scope.inView = false;
})

在HTML:

<div ng-repeat="monitor in monitors" ng-if="inView">
  <img ng-src = 'http://myserver.com/cgi-bin/videoFeed?id={{monitor}}' />
</div>

你可以尝试一下,让我知道会发生什么。

can you give that a try and let me know what happens.

这篇关于终止由img ng-src导致的未使用的http连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆