StreamElements / widgets

283 stars 119 forks source link

Expose provider name #45

Open sebastien-p opened 1 year ago

sebastien-p commented 1 year ago

Hello

I would like to access the provider name (twitch, youtube, …) and found out that this information is stored in the AngularJS code of the parent frame but don’t seem to be exposed to the custom code one. Or maybe it is somehow? Only the provider ID seems to be available but I sadly can’t do much with it.

Thanks 😊

c4ldas commented 1 year ago

You cannot get it directly, but you can obtain the account ID and then fetch an endpoint that will show with platform that user is from:

window.addEventListener('onWidgetLoad', async (obj) => {
  const accountId = obj.detail.channel.id

  const accountFetch = await fetch(`https://api.streamelements.com/kappa/v2/channels/${accountId}`)
  const account = await accountFetch.json()

  console.log(account.provider) // twitch / youtube / trovo / etc
})
sebastien-p commented 1 year ago

You cannot get it directly, but you can obtain the account ID and then fetch an endpoint that will show with platform that user is from:

window.addEventListener('onWidgetLoad', async (obj) => {
  const accountId = obj.detail.channel.id

  const accountFetch = await fetch(`https://api.streamelements.com/kappa/v2/channels/${accountId}`)
  const account = await accountFetch.json()

  console.log(account.provider) // twitch / youtube / trovo / etc
})

Ok but I feel like sending an HTTP request to fetch an information that already is present in memory is a bad idea and this would introduce potential errors and latency for no reason.

c4ldas commented 1 year ago

Other than that, only on onEventReceived, like a chat message, for example. It will show in obj.detail.event.service

sebastien-p commented 1 year ago

Other than that, only on onEventReceived, like a chat message, for example. It will show in obj.detail.event.service

Yes but I am implementing a solution for multi streaming so I need to know the source/provider for every event being onWidgetLoad, onEventReceived or onSessionUpdate.

c4ldas commented 1 year ago

Unfortunately, there is no way. The only place you will have that information is either from onEventReceived or fetching the endpoint.

sebastien-p commented 1 year ago

Unfortunately, there is no way. The only place you will have that information is either from onEventReceived or fetching the endpoint.

Well the provider won’t change so we can assume having this info once in onWidgetLoad would be enough. But what we have instead is an ID forcing us to send an HTTP request to exchange it for the provider name, I’m not sure how that would be useful. Why not just also expose the provider name alongside the ID since the parent frame already has it?

c4ldas commented 1 year ago

Why not just also expose the provider name alongside the ID since the parent frame already has it?

That's an excellent question that we will never know the answer. I also wouldn't expect that will be changed soon, given how hard is to reach SE devs or have good suggestions rolled out.

sebastien-p commented 1 year ago

Why not just also expose the provider name alongside the ID since the parent frame already has it?

That's an excellent question that we will never know the answer. I also wouldn't expect that will be changed soon, given how hard is to reach SE devs or have good suggestions rolled out.

Fingers crossed 🤞