Why can there only be 1 AJAX or WebSocket object at a time?

Get help using Construct 2

Post » Wed Feb 01, 2017 9:43 am

I was attempting to use the built-in AJAX and WebSocket object types to connect a game simultaneously to multiple livestreaming sites' chats and notification systems (Twitch's chats and PubSub System, Hitbox, YouTube live comments mid-broadcast, and Discord) to allow for interactivity by reading sent messages from all platforms (i.e.- the way an IRC chat bot normally works by reading !commands), but eventually discovered that only a single object of each type of plugin can be added to a project at a time.

Is there any particular reason for this? I can figure out ways to circumvent the limitation for an AJAX-type object using global variables and setting up a pseudo function queue at the loss of speed, but ideally I'd like to be able to keep multiple concurrent WebSocket connections without having to close one and open another periodically as it appears one would have to do.
B
6
G
1
Posts: 2
Reputation: 984

Post » Wed Feb 01, 2017 10:51 am

AJAX can support multiple simultaneous requests via tags, but no ideas for WebSocket.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Wed Feb 01, 2017 6:50 pm

Regarding AJAX, while handling simultaneous requests is fine, it's still a bit of a hassle to have to set up several variables in order to save each request's .LastData from being lost. But yeah, it'd be nice if WebSockets created a connection ID parameter so as to enable the upkeep of multiple connections, especially when they have different behaviors (i.e.- Hitbox expects a "2::" response for its ping-pong structure as opposed to Twitch's "PONG"s, and Twitch's PubSub System expects the client to send "PING"s on its end around every two minutes instead, which is... unconventional).
B
6
G
1
Posts: 2
Reputation: 984

Post » Wed Feb 01, 2017 7:24 pm

For AJAX, recommend using dictionary object to store LastData, as you can use the AJAX.tag as your key. This allows you to create a single catch all event for any number of requests and tags, rather than having to create a specific event and condition for each tag/request.

If you need history or logs, you can add a for each key event (with an incrementing counter) to push to an array. An additional step would be to add a comparison to check if the current key actually updated from the last pushed data in the array before pushing whatever is in the dictionary to the array (prevent duplicates/unecessary update).

Sorry again for not having any ideas for websocket, I've never touched it and not familiar with the mechanics.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083


Return to How do I....?

Who is online

Users browsing this forum: OddConfection and 33 guests