I'm trying to switch from custom WebSockets to PubNub. In my app I need user to subscribe to multiple channels at once so I thought multiplexing is the way to go. The issue is, when I want to subscribe more than 4 channels at once I'm getting endless stream of CORS errors. Subscribing one by one channel with delays in between are making no difference. I have "Stream Controller" extension enabled.
2 Answers
PubNub Presence User State Data
https://www.pubnub.com/docs/web-javascript/presence
When you subscribe to multiple channels and provide state, for example:
pubnub.subscribe({
channel: "ch1,ch2,ch3",
message: function(message) {
console.log('message', message);
},
state: {
age: 67,
username: '[email protected]',
full: 'Robert Plant',
country: 'UK',
latlong: '51.5072° N, 0.1275° W'
profile_pic: 'http://somewebsite.com/images/rplant.png'
}});
...the state is added to each channel for that user. Each channel has it’s own state per user. Above, each of the three channels is initialized with the same state data, but when you set state, for example:
pubnub.state({
channel: 'ch2',
uuid: 'rplant',
state: {'full_name' : 'Bobby Plant'},
callback: function(m){console.log(JSON.stringify(m))}
});
... you can specify a single channel (or multiple channels) and the user by their UUID that you set for them when you initialized PubNub with PUBNUB.int.
As for state size limits, there is the 32KB message limit for publishing message and this is true for presence events, too, since they are just published message on the presence channel.
But in general, you should keep state to a minimum. It is not meant for large amounts of data. And files (images) should be stored on a distributed file system and the URL passed around via PubNub.
I discovered what an issue was. State is too big, it has user details including photo thumbnail. The size of it is ~6000 characters. It's still far away from 32kb and I read nothing about different limitations for it and it happened when I subscribed to at least 5 channels. Is there some behind the scene logic that multiplies size of state per amount of channels? 5*~6000 is close to the 32k limit.

origin: 'pubsub.pubnub.com'- perhaps you can send your source code to PubNub support. - Craig Conover