简体   繁体   English

跨浏览器通讯

[英]Cross-Browser Communication

I am designing a website that requires a host and client websites. 我正在设计一个需要主机和客户端网站的网站。 The host will set something up (a session), and the clients will connect to that host using an ID specific to that session. 主机将建立一些东西(一个会话),而客户端将使用该会话专用的ID连接到该主机。

I have considered how I will facilitate that communication, and initially I was going to have both the clients and the host periodically query and update a database which holds the current states of all clients and the host to communicate new options and changes - but then I wondered if it is possible, using javascript [or something], for them to connect and communicate directly? 我已经考虑过如何促进这种交流,并且最初我将让客户端和主机这两个站点定期查询和更新一个数据库,该数据库保存着所有客户端和主机的当前状态以传达新的选项和更改。想知道是否有可能使用javascript [或其他方法]让他们直接进行连接和交流?

The communication would be very simple messages - single strings to communicate current state and stuff like that. 通讯将是非常简单的消息-传达当前状态和类似信息的单个字符串。

Im pretty proficient in javascript/html/css, but am happy to learn if there is something that would do a better job of setting this up. 我非常精通javascript / html / css,但很高兴了解是否有某些方法可以更好地进行设置。

Thanks! 谢谢! Alex 亚历克斯

You're looking for WebRTC , which is the de facto and recommended way of doing peer-to-peer connections through the web with pure Javascript: 您正在寻找WebRTC ,这是使用纯Javascript通过网络进行对等连接的事实和推荐方法:

WebRTC (Web Real-Time Communication) is an API definition drafted by the World Wide Web Consortium (W3C) that supports browser-to-browser applications for voice calling, video chat, and P2P file sharing without the need of either internal or external plugins. WebRTC(Web实时通信)是由万维网联盟(W3C)起草的API定义,它支持浏览器到浏览器的应用程序进行语音呼叫,视频聊天和P2P文件共享,而无需内部或外部插件。

And yes, before you ask, simple messages can be exchanged as well. 是的,在您询问之前,也可以交换简单的消息。

Here is the Mozilla reference explaining WebRTC. 是解释WebRTC的Mozilla参考。

Here is a nice simple tutorial to get you started with the code. 是一个很好的简单教程,可帮助您入门。

Here is a peer-to-peer chat room with video capabilities built using pure WebRTC as a demo. 是一个具有视频功能的点对点聊天室,使用纯WebRTC作为演示来构建。


Prior to WebRTC, there was no satisfactory decentralised way of doing this. 在WebRTC之前,还没有令人满意的分散方法。

As the comments indicate, Websockets would have been the right idea if you were going with a centralised system - they facilitate real-time communication between clients and a central host. 就像评论所表明的那样,如果您使用的是集中式系统,Websockets将是正确的主意-它们促进了客户端与中央主机之间的实时通信。

Decentralised systems, however, must be implemented using WebRTC - this is the only option on the cards. 但是,分散式系统必须使用WebRTC实施-这是卡上的唯一选择。

您可以尝试httprelay.io ,不需要其他库,并且可以用于简单的http客户端到客户端的通信。

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

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