简体   繁体   English

将数据追加到所有Socket.io客户端发出的数据

[英]Appending data to all Socket.io client-side emits

I'm working on a couple sites that share some Socket.io initialization code. 我正在几个共享一些Socket.io初始化代码的站点上工作。 Also shared is a global var. 还共享一个全局变量。 If this var has a value I need to send it over in all socket emits. 如果这个变量有一个值,我需要在所有套接字发射中发送它。

I have not been able to figure out a good way to append this variable to all outgoing emits. 我还没有找到将这个变量附加到所有传出发射的好方法。 I was hoping that Socket.io would have a method that is called whenever an emit is fired (just before sending the data), allowing you to add to the data as needed. 我希望Socket.io将有一个在发射发射时(在发送数据之前)被调用的方法,允许您根据需要添加到数据中。 But, if it exists, I could not find it. 但是,如果存在,我将找不到它。

Any suggestions? 有什么建议么?

这很丑陋,但是您可以保存现有的代码,并编写自己的emit函数来执行所需的操作,然后调用原始的emit

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

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