kanimaru / twitcher

Full Twitch Library for Godot
MIT License
56 stars 7 forks source link

Usage of twitch's mock data server #21

Open Goutte opened 1 month ago

Goutte commented 1 month ago

We tried using the mock data server to test out subscriptions without paying every time we try.

We started the server with twitch start, as per twitch's doc :

$ twitch mock-api start

2024/08/05 13:32:29 Starting mock API server on http://localhost:8080
2024/08/05 13:32:29 Creating categories...
2024/08/05 13:32:29 Creating users...
2024/08/05 13:32:29 Creating team...
2024/08/05 13:32:29 Creating channel points rewards and redemptions, follows, blocks, mods, bans, editors, and team members...
2024/08/05 13:32:37 Creating streams...
2024/08/05 13:32:37 Creating tags...
2024/08/05 13:32:37 Creating videos, clips, and stream markers...
2024/08/05 13:32:37 User ID 97764872 has all applicable units (streams, subs, and the like) and is a partner for use with the API
2024/08/05 13:32:37 Created Client. Details:
Client-ID: 354e36cf2746427e2d7bb3357d6957
Secret: 37e73d04f445f6512760e1d36c27b1
Name: Mock API Client
2024/08/05 13:32:37 Created authorization with token 12846f460607bfe
2024/08/05 13:32:37 Finished generation.
2024/08/05 13:32:37 Mock server started

Note that the mock server provides a token (12846f460607bfe), but the auth.conf file, which I gather usually hosts this value, is encrypted and I do not know how to monkey-write in it to test further.

And this is our (test) config :

[twitch]

auth/scopes/chat=3
auth/scopes/user=12288
general/logging/enabled=2047
auth/scopes/channel=8388608

auth/broadcaster_id="97764872"
auth/client_id="354e36cf2746427e2d7bb3357d6957"
auth/client_secret="37e73d04f445f6512760e1d36c27b1"
websocket/irc/username="my_streamer_username"
general/api/api_host="http://localhost:8080/mock"
auth/api/token_host="http://localhost:8080"

We managed to connect to the "official" API and make our requests. We're now trying to connect to the mock, localhost server.

Has anyone done this ? What are we missing ?

Thanks,

kanimaru commented 1 month ago

I don't think that they mock the authentication cause its normal OAuth process maybe Testcontainers has a keycloak or something?

Goutte commented 1 month ago

Thanks @kanimaru

We don't especially need to mock the OAuth, if we can somehow skip it and use the token the mock server gives us, perhaps it will work ?

kanimaru commented 1 month ago

I never used a token for the mock server so no clue. But I only used eventsub from it so I don't know.

FortunesFavored commented 1 week ago

I was doing some digging into this today, and it seems like a lot of refactoring would need to happen to make it so that the Auth token can be retrieved from the mock data server. I also found the following thread that described how test events are used on different services, which basically describe emulating the response. https://discuss.dev.twitch.com/t/sending-test-events-to-apps/18620

Since the goal is to emulate various stream events I think we can do the following:

1: We do a minor refactor to separate out this match block into a different function. https://github.com/kanimaru/twitcher/blob/3ecd25b4799078fd54b1308e5b148fb9c23ddab7/addons/twitcher/eventsub/twitch_eventsub.gd#L153

2: Create a MockEventSubMessage class that can produce messages as we would expect to see them produced from twitch based on the documentation.

MockEventSubMessage.TwitchEventsub.match_message_type( metadata.message_type, message_payload )

Since we can use the logs to confirm were are able to consume subscription events I think having a class that can generate the various events should provide the same benifit without having to use the twitch mock data api. I am going to start working on expanding this logic as I think it would definitely help with prototyping.

kanimaru commented 1 week ago

Ok after I was talking with Fortune I think I understood know what you really want :D.

twitch event websocket start-server to start a eventsub test server.

Configure that you use the debug eventsub within twitcher:

image

Connect your signal also to

var event_sub = TwitchService.eventsub as TwitchEventsub;
if TwitchSetting.use_test_server:
    TwitchService.eventsub_debug.event.connect(_on_received)
event_sub.event.connect(_on_received);`

and send twitch event trigger channel.subscribe -f 132799162 --transport=websocket

Is it that what you are looking for?