Hey,
thank you very much for you detailed explanation. In combination with your HTTP-Lib-got example and a little https-lib-post code I used in the past to get my app access token, I was able to turn your linked Get Users Refrerence into this:
Summary
const https = require('https');
const options = {
host: 'api.twitch.tv',
path: '/helix/users?login=<myLogin>',
headers: {
'Client-ID': '<myClientId>',
'Authorization': 'Bearer <myAppAccessToken>'
},
method: 'GET'
};
callback = function(response) {
let str = '';
response.on('data', function (chunk) {
str += chunk;
});
response.on('end', function () {
console.log(str);
});
};
https.request(options, callback).end();
And it worked. So now I have a template I can work with, in case I see another cURL code. That’s cool!
About the Pubsub connection:
I installed WebSocket and looked into the WebSockets Dev Docs to get a little overview about it. It helped me to understand your pubsub example a little bit more. So far I can connect to Pubsub WS. I saw in your example, that you solved the disconnect/reconnect-problem by puting it in a function, making it a loop. My version looks like this:
Summary
const WebSocket = require('ws');
connect = function() {
const twitch = new WebSocket('wss://pubsub-edge.twitch.tv');
twitch.on('open', () => {
console.log('Connected with Twitch.')
})
twitch.on('close', () => {
console.log('Disconnected from Twitch.')
connect();
})
}
connect();
So THIS is now, what I was basicly looking for in my start post. Again, that’s cool!
Unfortunately, unlike in streamlabs/socket.oi, there is still this ping/pong-problem I have to solve, so I don’t get disconnected after 5 miuntes. Btw, to my suprise I don’t get disconnected after 5 minutes (like it’s mentioned in the dev docs), but already after 1. Not sure if that means something.
Anyway, my thought is now:
If I already have a reconnection-loop, how necessary is the ping-pong-thing then? Or does a solution without ping/pong create a too big disadventage? And if the ping/pong is still really needed, how does it look like?
Because the ping doesn’t have do be send every second, I thought about a ping function I could call (in my case every minute). And you actually have some kind of function like that. But again, because it looks like you have tangled multiple functions into each other, it’s a bit hard for me to untangle your example.