TwitchSystemComponent.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <AzCore/Component/TickBus.h>
  11. #include <AzCore/std/parallel/atomic.h>
  12. #include <Twitch/TwitchBus.h>
  13. #include <ITwitchREST.h>
  14. namespace Twitch
  15. {
  16. class TwitchSystemComponent
  17. : public AZ::Component
  18. , protected TwitchRequestBus::Handler
  19. , public AZ::SystemTickBus::Handler
  20. {
  21. public:
  22. AZ_COMPONENT(TwitchSystemComponent, "{8AC76E51-CE55-4D67-90DE-41D1A7756E32}");
  23. TwitchSystemComponent();
  24. virtual ~TwitchSystemComponent() {}
  25. static void Reflect(AZ::ReflectContext* context);
  26. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  27. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  28. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  29. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  30. void OnSystemTick() override;
  31. protected:
  32. ////////////////////////////////////////////////////////////////////////
  33. // TwitchRequestBus interface implementation
  34. ////////////////////////////////////////////////////////////////////////
  35. void SetApplicationID(const AZStd::string& twitchApplicationID) override;
  36. void SetUserID(ReceiptID& receipt, const AZStd::string& userId) override;
  37. void SetOAuthToken(ReceiptID& receipt, const AZStd::string& token) override;
  38. void RequestUserID(ReceiptID& receipt) override;
  39. void RequestOAuthToken(ReceiptID& receipt) override;
  40. AZStd::string GetApplicationID() const override;
  41. AZStd::string GetUserID() const override;
  42. AZStd::string GetOAuthToken() const override;
  43. AZStd::string GetSessionID() const override;
  44. void GetUser(ReceiptID& receipt) override;
  45. void ResetFriendsNotificationCount(ReceiptID & receipt, const AZStd::string& friendID) override;
  46. void GetFriendNotificationCount(ReceiptID & receipt, const AZStd::string& friendID) override;
  47. void GetFriendRecommendations(ReceiptID & receipt, const AZStd::string& friendID) override;
  48. void GetFriends(ReceiptID & receipt, const AZStd::string& friendID, const AZStd::string& cursor) override;
  49. void GetFriendStatus(ReceiptID & receipt, const AZStd::string& sourceFriendID, const AZStd::string& targetFriendID) override;
  50. void AcceptFriendRequest(ReceiptID & receipt, const AZStd::string& friendID) override;
  51. void GetFriendRequests(ReceiptID & receipt, const AZStd::string& cursor) override;
  52. void CreateFriendRequest(ReceiptID & receipt, const AZStd::string& friendID) override;
  53. void DeclineFriendRequest(ReceiptID & receipt, const AZStd::string& friendID) override;
  54. // presence
  55. void UpdatePresenceStatus(ReceiptID & receipt, PresenceAvailability availability, PresenceActivityType activityType, const AZStd::string& gameContext) override;
  56. void GetPresenceStatusofFriends(ReceiptID & receipt) override;
  57. void GetPresenceSettings(ReceiptID & receipt) override;
  58. void UpdatePresenceSettings(ReceiptID & receipt, bool isInvisible, bool shareActivity) override;
  59. // channel
  60. void GetChannel(ReceiptID& receipt) override;
  61. void GetChannelbyID(ReceiptID& receipt, const AZStd::string& channelID) override;
  62. void UpdateChannel(ReceiptID& receipt, const ChannelUpdateInfo& channelUpdateInfo) override;
  63. void GetChannelEditors(ReceiptID& receipt, const AZStd::string& channelID) override;
  64. void GetChannelFollowers(ReceiptID& receipt, const AZStd::string& channelID, const AZStd::string& cursor, AZ::u64 offset) override;
  65. void GetChannelTeams(ReceiptID& receipt, const AZStd::string& channelID) override;
  66. void GetChannelSubscribers(ReceiptID& receipt, const AZStd::string& channelID, AZ::u64 offset) override;
  67. void CheckChannelSubscriptionbyUser(ReceiptID& receipt, const AZStd::string& channelID, const AZStd::string& userID) override;
  68. void GetChannelVideos(ReceiptID& receipt, const AZStd::string& channelID, BroadCastType broadcastType, const AZStd::string& language, AZ::u64 offset) override;
  69. void StartChannelCommercial(ReceiptID& receipt, const AZStd::string& channelID, CommercialLength length) override;
  70. void ResetChannelStreamKey(ReceiptID& receipt, const AZStd::string& channelID) override;
  71. ////////////////////////////////////////////////////////////////////////
  72. // AZ::Component interface implementation
  73. void Init() override;
  74. void Activate() override;
  75. void Deactivate() override;
  76. ////////////////////////////////////////////////////////////////////////
  77. AZ::u64 GetReceipt();
  78. private:
  79. TwitchSystemComponent(const TwitchSystemComponent&) = delete;
  80. bool IsValidString(const AZStd::string& str, AZStd::size_t minLength, AZStd::size_t maxLength) const;
  81. bool IsValidFriendID(const AZStd::string& friendID) const;
  82. bool IsValidOAuthToken(const AZStd::string& oAuthToken) const;
  83. bool IsValidSyncToken(const AZStd::string& syncToken) const;
  84. bool IsValidChannelID(const AZStd::string& channelID) const { return IsValidFriendID(channelID); }
  85. bool IsValidCommunityID(const AZStd::string& communityID) const { return IsValidFriendID(communityID); }
  86. bool IsValidTwitchAppID(const AZStd::string& twitchAppID) const;
  87. private:
  88. AZStd::string m_applicationID;
  89. AZStd::string m_cachedClientID;
  90. AZStd::string m_cachedOAuthToken;
  91. AZStd::string m_cachedSessionID;
  92. AZ::u64 m_refreshTokenExpireTime;
  93. ITwitchRESTPtr m_twitchREST;
  94. AZStd::atomic<AZ::u64> m_receiptCounter;
  95. };
  96. }