aws-samples / amazon-ivs-player-web-sample

This project contains code samples demonstrating how to build, package, and integrate with the Amazon IVS Player Web SDK.
https://docs.aws.amazon.com/ivs/
MIT No Attribution
81 stars 32 forks source link

PlayerStateChanged event missing in type declaration. (npm amazon-ivs-player) #80

Open badrddinb opened 1 year ago

badrddinb commented 1 year ago

The IVS Player TS SDK includes the PlayerStateChanged event in its runtime, but it has not been included in the TypeScript type declarations.

johnBartos commented 1 year ago

Hey @badrddinb, I'm pretty sure that's intended, the PlayerStateChanged event is private. We make some events private by design. While we can't stop you from using them, we offer no support or guarantees that we won't break that API in future versions. The only public events are those included in the type definition file and the docs.

That being said, what's your use case for having this event?

blfunex commented 1 year ago

I work with @badrddinb, we use the event in react to detect when the player is buffering to signal it to the user in UI.

  useEffect(() => {
    if (!player) return

    const stateChangedListener = (state: unknown) => {
      setIsPlayerBuffering(state === PlayerState.BUFFERING)
    }

    // The IVS Player TS SDK includes the PlayerStateChanged event in its runtime,
    // but it has not been included in the TypeScript type declarations.
    // Reported: https://github.com/aws-samples/amazon-ivs-player-web-sample/issues/80
    const PlayerStateChanged = 'PlayerStateChanged' as PlayerEventType
    player.addEventListener(PlayerStateChanged, stateChangedListener)

    return () => {
      player.removeEventListener(PlayerStateChanged, stateChangedListener)
    }
  }, [player])