简体   繁体   English

在Polymer Web应用程序中实现WebSocket的最佳方法

[英]Best way to implement websockets in Polymer web app

I am currently developping a single view application in Polymer/js. 我目前正在Polymer / js中开发一个单视图应用程序。

Some of my custom-elements will need to be connected to the server via websocket, to get refreshed. 我的一些自定义元素将需要通过websocket连接到服务器,以进行刷新。 After some search on the internet I saw that there are quite a few existing websocket-elements. 在互联网上进行一些搜索后,我发现现有的websocket元素已经很多。 Is it a good practice? 这是一个好习惯吗?

I am new to Polymer and web development, and for me the best way would be to have a WebSocket singleton object or something lile that, and then all the elements in need would reuse it. 我不熟悉Polymer和Web开发,对我而言,最好的方法是拥有一个WebSocket单例对象或类似的东西,然后所有需要的元素都可以重用它。 Here it's impossible, and I don't know how to implement this the right way. 在这里是不可能的,而且我不知道如何以正确的方式实现这一目标。 Any feedback appreciated 任何反馈表示赞赏

Polymer seems to be a wrapper for specific Javascript and html features related to WebComponents . Polymer似乎是与WebComponents相关的特定Javascript和html功能的包装。

I think a regular javascript Websocket would work perfectly, allowing you to access Polymer API within it's callbacks. 我认为常规的javascript Websocket可以完美运行,从而允许您在其回调中访问Polymer API。

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

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