简体   繁体   English

在服务器端使用事件源-polyfill(node.js)

[英]Using event-source-polyfill on server side (node.js)

Inorder to support event streams in IE and other mobile browsers i'm attempting to use event-source-polyfill ( https://www.npmjs.com/package/event-source-polyfill ). 为了在IE和其他移动浏览器中支持事件流,我尝试使用event-source-polyfill( https://www.npmjs.com/package/event-source-polyfill )。

Can anyone please provide an example on how it could be used on a node service (or) it is just adding it via npm install and then we should be all set? 谁能提供一个示例说明如何在节点服务上使用它(或只是通过npm install添加它,然后我们就准备好了)? From the documentation it looks like there are some server side requirements ( https://www.npmjs.com/package/event-source-polyfill#server-side-requirements ) out of which the, 从文档中看,似乎有一些服务器端要求( https://www.npmjs.com/package/event-source-polyfill#server-side-requirements ),其中,

  1. Last-Event-ID is a query parameter that needs to be sent in the api end point something like /api/eventstream?lastEventId=0 Last-Event-ID是一个查询参数,需要在api端点中发送,类似于/ api / eventstream?lastEventId = 0
  2. 2 KB padding for IE which as mentioned in the example we can have this (response.write(":" + Array(2049).join(" ") + "\\n");) on the node part IE中2 KB的填充,如示例中所述,我们可以在节点部分上添加它(response.write(“:” + Array(2049).join(“”)+“ \\ n”);)
  3. You need to send "comment" messages each 15-30 seconds, these messages will be used as heartbeat to detect disconnects (what should be done for this one?) 您需要每15到30秒发送一次“评论”消息,这些消息将用作检测断开状态的心跳(对此应该做些什么?)

So after npm install event-source-polyfill and then completing the steps from 1,2 and 3 it would eventually work in IE is that a fair understanding. 因此,在npm之后安装event-source-polyfill,然后完成1,2和3中的步骤,它最终将在IE中工作是一种公平的理解。

您还需要将脚本添加到HTML:

 <script src="eventsource.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM