简体   繁体   English

实时(node / socket.io)的“管道”如何工作?

[英]How does the “plumbing” of real-time (node/socket.io) work?

I'm currently building a real-time web application that utilizes the MEAN stack (Mongo,Express,Angular,Node). 我目前正在构建一个利用MEAN堆栈(Mongo,Express,Angular,Node)的实时Web应用程序。 My question relates to how Node (and more specifically Socket.io) work in a real-time app which makes calls to an API (in this case Instagram). 我的问题与Node(尤其是Socket.io)在实时应用程序中的工作方式有关,该应用程序调用API(在本例中为Instagram)。

I'm subscribing to several locations (lat/lon coordinates) with the Instagram API. 我正在使用Instagram API订阅多个位置(纬度/经度坐标)。 I want my web app to automatically add photos as they are taken (and geo-tagged) around these locations. 我希望我的网络应用在这些位置周围拍摄(并带有地理标签)时自动添加照片。

How I THINK this will work: 我如何认为这将起作用:

  • Subscribe to several locations through the Instagram API 通过Instagram API订阅多个位置
  • Instagram sends me a GET request to my callback URL when data at API endpoint changes 当API端点处的数据发生更改时,Instagram向我的回调URL发送GET请求
  • Fire off a GET request TO Instagram in response, based on which endpoint changed 根据更改的端点向Instagram发送GET请求以响应
  • Save the new photo(s) to Mongo database using my own API 使用我自己的API将新照片保存到Mongo数据库
  • Emit an event from server to client using Socket.io, containing new photo(s) data 使用Socket.io从服务器向客户端发送事件,其中包含新的照片数据
  • 'Capture' this event with a Socket.io listener on client side and display new photo(s) 在客户端使用Socket.io侦听器“捕获”此事件并显示新照片

Does this seem reasonable at a detailed level or am I missing (even some tiny) steps? 从详细的角度看,这似乎合理吗?还是我错过了(甚至是很小的)步骤?

  1. Emit an event from server to client using Socket.io 使用Socket.io从服务器向客户端发送事件
  2. 'Capture' this event with a Socket.io listener on client side 在客户端使用Socket.io侦听器“捕获”此事件
  3. Fire off a GET request to my API to pull the new photo(s) from Mongo database 向我的API发出GET请求,以从Mongo数据库中提取新照片

This can be reduced to a single step: 这可以简化为一个步骤:

  1. Emit an event from server and send the photo as data-uri. 从服务器发送事件,并将照片作为data-uri发送。

You may need to watch out for the amount of data that can be sent via sockets. 您可能需要注意可以通过套接字发送的数据量。

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

相关问题 如何设置socket.io以获取实时数据 - How to setup socket.io for getting data real-time 如何在react-native中使用node.js和Socket.io实现实时聊天? - How to Implement real-time chatting using node.js and Socket.io in react-native? 如何使用 node.js、socket.io 和 mysql 显示实时数据? - how to show real-time data using node.js, socket.io and mysql? 设计实时Web应用程序(Node.js和socket.io) - Designing real-time web application (Node.js and socket.io) Node.js:实时应用需要Socket.io + Express吗? - Node.js: Socket.io + Express needed for real-time apps? 使用Node / Socket.io + PHP的现场实时小部件 - On-Site real-time widget using Node/Socket.io + PHP 使用Socket.IO实时更新数据? - Use Socket.IO to update data in real-time? 关于so​​cket.io实时文本显示的问题 - Issue about socket.io real-time text display 如何保护Redis和Socket.IO实时服务器的安全,以便只有经过身份验证的用户才能收听? - How to secure Redis & Socket.IO real-time server so only authenticated users can listen? 带有PubSub的Socket.io:刷新多页后几乎不显示实时数据 - Socket.io with PubSub : Less to no real-time data displayed after multiple page refresh
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM