admin管理员组文章数量:1024074
The push library works as below
var channel = pusher.subscribe('test_channel');
channel.bind('my_event', function(data) {
alert(data.message);
});
However: Would I be able to do this?
var channel = pusher.subscribe('test_channel');
channel.bind(['my_event1', 'my_event2'....'my_event100'], function(data) {
alert(data.message);
});
In my use case, I have one channel and there are many different events and each client might want to simulantaneously subscribe to 100s of events.
The push library works as below
var channel = pusher.subscribe('test_channel');
channel.bind('my_event', function(data) {
alert(data.message);
});
However: Would I be able to do this?
var channel = pusher.subscribe('test_channel');
channel.bind(['my_event1', 'my_event2'....'my_event100'], function(data) {
alert(data.message);
});
In my use case, I have one channel and there are many different events and each client might want to simulantaneously subscribe to 100s of events.
Share Improve this question edited Jul 28, 2024 at 23:59 Jeff Puckett 41.2k19 gold badges124 silver badges174 bronze badges asked Jan 2, 2014 at 22:04 samolsamol 20.7k33 gold badges93 silver badges132 bronze badges1 Answer
Reset to default 5The signature for the channel.bind
function is String channelName, Function callback
(pusher-js source). You can't pass in an Array
of channels`.
If you want the same function to be called then you'll need to pass a reference to the function and call bind
multiple times:
var channel = pusher.subscribe('test_channel');
var callback = function(data) {
alert(data.message);
};
var eventName;
for( var i = 0; i < 100; ++i ) {
eventName = 'my_event' + ( i + 1 );
channel.bind( eventName, callback );
}
The single-threaded nature of JS will equate to these event binding happening simultaneously.
You could of course create your own helper function to allow bind( Array eventNames, Function callback )
.
The push library works as below
var channel = pusher.subscribe('test_channel');
channel.bind('my_event', function(data) {
alert(data.message);
});
However: Would I be able to do this?
var channel = pusher.subscribe('test_channel');
channel.bind(['my_event1', 'my_event2'....'my_event100'], function(data) {
alert(data.message);
});
In my use case, I have one channel and there are many different events and each client might want to simulantaneously subscribe to 100s of events.
The push library works as below
var channel = pusher.subscribe('test_channel');
channel.bind('my_event', function(data) {
alert(data.message);
});
However: Would I be able to do this?
var channel = pusher.subscribe('test_channel');
channel.bind(['my_event1', 'my_event2'....'my_event100'], function(data) {
alert(data.message);
});
In my use case, I have one channel and there are many different events and each client might want to simulantaneously subscribe to 100s of events.
Share Improve this question edited Jul 28, 2024 at 23:59 Jeff Puckett 41.2k19 gold badges124 silver badges174 bronze badges asked Jan 2, 2014 at 22:04 samolsamol 20.7k33 gold badges93 silver badges132 bronze badges1 Answer
Reset to default 5The signature for the channel.bind
function is String channelName, Function callback
(pusher-js source). You can't pass in an Array
of channels`.
If you want the same function to be called then you'll need to pass a reference to the function and call bind
multiple times:
var channel = pusher.subscribe('test_channel');
var callback = function(data) {
alert(data.message);
};
var eventName;
for( var i = 0; i < 100; ++i ) {
eventName = 'my_event' + ( i + 1 );
channel.bind( eventName, callback );
}
The single-threaded nature of JS will equate to these event binding happening simultaneously.
You could of course create your own helper function to allow bind( Array eventNames, Function callback )
.
本文标签: javascriptPusher How to bind to 100s of eventsStack Overflow
版权声明:本文标题:javascript - Pusher: How to bind to 100s of events? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745530839a2154742.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论