|
Twitch SDK (Internal)
|
#include <pubsubclient.h>
Classes | |
| class | ConnectionListener |
| struct | ConnectionPreference |
| class | IListener |
| class | ITopicListener |
| struct | SubscribeState |
| struct | Topic |
| struct | TopicState |
Public Types | |
| typedef std::function< void(PubSubClient *source, TTV_ErrorCode ec)> | SendMessageCallback |
| enum | State { State::Uninitialized, State::Initialized, State::ShuttingDown, State::Inert } |
Public Member Functions | |
| PubSubClient (std::shared_ptr< User > user) | |
| virtual | ~PubSubClient () |
| std::shared_ptr< User > | GetUser () |
| PubSubState | GetConnectionState () const |
| void | AddListener (std::shared_ptr< IListener > listener) |
| void | RemoveListener (std::shared_ptr< IListener > listener) |
| TTV_ErrorCode | Initialize () override |
| virtual TTV_ErrorCode | Connect () |
| TTV_ErrorCode | Disconnect () |
| TTV_ErrorCode | SetConnectionPreference (ConnectionPreference::Enum preference) |
| TTV_ErrorCode | SendMessage (const json::Value &jMessage, SendMessageCallback callback) |
| TTV_ErrorCode | AddTopicListener (const std::string &topic, std::shared_ptr< ITopicListener > listener) |
| TTV_ErrorCode | RemoveTopicListener (const std::string &topic, std::shared_ptr< ITopicListener > listener) |
| TTV_ErrorCode | Shutdown () override |
| virtual void | Update () override |
| virtual std::string | GetLoggerName () const override |
| virtual void | SetTaskRunner (std::shared_ptr< TaskRunner > taskRunner) |
| std::shared_ptr< TaskRunner > | GetTaskRunner () |
| virtual State | GetState () const override |
Static Public Member Functions | |
| static std::string | GetComponentName () |
Protected Member Functions | |
| virtual void | OnUserLogInComplete (TTV_ErrorCode ec) |
| virtual void | OnUserLogOutComplete (TTV_ErrorCode ec) |
| virtual void | OnUserInfoFetchComplete (TTV_ErrorCode ec) |
| virtual void | OnUserAuthenticationIssue (std::shared_ptr< const OAuthToken > oauthToken, TTV_ErrorCode ec) |
| void | Log (TTV_MessageLevel level, const char *format,...) |
| TTV_ErrorCode | StartTask (std::shared_ptr< Task > task) |
| void | CompleteTask (Task *task) |
| bool | IsTaskRunning (Task *task) const |
| virtual void | SetState (State state) |
| virtual void | SetClientState (State state) |
| virtual void | SetServerState (State state) |
Protected Attributes | |
| std::weak_ptr< User > | mUser |
| bool | mOAuthIssue |
| Whether or not the internal updates of the component are on hold because of an issue with the OAuth token. More... | |
| ClientServerValue< State > | mState |
| std::shared_ptr< TaskRunner > | mTaskRunner |
| std::vector< std::shared_ptr< Task > > | mRunningTasks |
| std::mutex | mTaskMutex |
| uint64_t | mShutdownTimeMilliseconds |
Private Attributes | |
| ConcurrentQueue< std::shared_ptr< pubsub::ClientMessage > > | mIncomingQueue |
| ConcurrentQueue< std::shared_ptr< pubsub::ServerMessage > > | mOutgoingQueue |
| std::map< std::string, std::shared_ptr< Topic > > | mTopics |
| std::shared_ptr< IThread > | mThread |
| std::shared_ptr< ConnectionListener > | mConnectionListener |
| std::shared_ptr< PubSubClientConnection > | mConnection |
| The active connection. More... | |
| std::shared_ptr< PubSubClientConnection > | mDyingConnection |
| The connection that might be alive for a short time after a RECONNECT is received from the server. More... | |
| EventSource< IListener > | mListeners |
| json::FastWriter | mJsonWriter |
| RetryTimer | mConnectionRetryTimer |
| ClientServerValue< PubSubState > | mConnectionState |
| ConnectionPreference::Enum | mConnectionPreference |
| bool | mConnectionDesired |
| Whether or not the client has called Connect(). More... | |
Manages the pubsub connection for a user.
Features
Setup 1) Initialize() 2) Connect() and wait for stat callback indicating success.
Listening 1) Subscribe to a topic via AddTopicListener() and wait for a ITopicListener::OnTopicSubscribeStateChanged event with SubscribeState::Subscribed and TTV_EC_SUCCESS. 2) Once subscribed ITopicListener::OnTopicMessageReceived will fire events as they are received for that topic.
Unlistening 1) Unsubscribe from a topic via RemoveTopicListener() and wait for ITopicListener::OnTopicSubscribeStateChanged event with SubscribeState::Unsubscribed and TTV_EC_SUCCESS.
Sending messages 1) SendMessage() with the desired JSON data and an optional callback function. 2) Wait for the callback function for the result.
Disconnections When the connection to pubsub is dropped unexpecedly then all IListeners will be notified via IListener::OnStateChanged. If automatic connection retries are happening then the state will be TTV_CORE_PUBSUB_STATE_CONNECTING. Otherwise, it will be TTV_CORE_PUBSUB_STATE_DISCONNECTED.
Registered topic listeners will be notified via ITopicListener::OnTopicSubscribeStateChanged. If a connection retry attempt is underway then the subscription state reported will be Subscribing, otherwise it will be Unsubscribed. Topic listeners are not removed from the subscription of a topic until they receive ITopicListener::OnTopicSubscribeStateChanged event with SubscribeState::Unsubscribed and TTV_EC_SUCCESS. Any other error code means that it was an issue with the connection and retries will occur automatically.
| typedef std::function<void(PubSubClient* source, TTV_ErrorCode ec)> ttv::PubSubClient::SendMessageCallback |
|
stronginherited |
| ttv::PubSubClient::PubSubClient | ( | std::shared_ptr< User > | user | ) |
|
virtual |
| void ttv::PubSubClient::AddListener | ( | std::shared_ptr< IListener > | listener | ) |
| TTV_ErrorCode ttv::PubSubClient::AddTopicListener | ( | const std::string & | topic, |
| std::shared_ptr< ITopicListener > | listener | ||
| ) |
|
private |
|
private |
|
overrideprivatevirtual |
Reimplemented from ttv::Component.
|
overrideprivatevirtual |
Reimplemented from ttv::UserComponent.
|
protectedinherited |
|
virtual |
| TTV_ErrorCode ttv::PubSubClient::Disconnect | ( | ) |
|
inlinestatic |
|
inline |
|
private |
|
overridevirtual |
Implements ttv::Component.
|
overridevirtualinherited |
Implements ttv::IComponent.
|
inlineinherited |
| std::shared_ptr<User> ttv::PubSubClient::GetUser | ( | ) |
|
overridevirtual |
Reimplemented from ttv::UserComponent.
|
protectedinherited |
|
protectedinherited |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
protectedvirtualinherited |
|
protectedvirtualinherited |
Reimplemented in ttv::social::FriendList, ttv::social::Presence, and ttv::chat::ChatUserThreads.
|
protectedvirtualinherited |
|
protectedvirtualinherited |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
| void ttv::PubSubClient::RemoveListener | ( | std::shared_ptr< IListener > | listener | ) |
| TTV_ErrorCode ttv::PubSubClient::RemoveTopicListener | ( | const std::string & | topic, |
| std::shared_ptr< ITopicListener > | listener | ||
| ) |
|
private |
| TTV_ErrorCode ttv::PubSubClient::SendMessage | ( | const json::Value & | jMessage, |
| SendMessageCallback | callback | ||
| ) |
|
protectedvirtualinherited |
| TTV_ErrorCode ttv::PubSubClient::SetConnectionPreference | ( | ConnectionPreference::Enum | preference | ) |
|
private |
|
protectedvirtualinherited |
|
protectedvirtualinherited |
|
virtualinherited |
Reimplemented in ttv::broadcast::Streamer, and ttv::social::FriendList.
|
overridevirtual |
Reimplemented from ttv::Component.
|
protectedinherited |
|
private |
|
private |
|
overridevirtual |
Reimplemented from ttv::Component.
|
private |
|
private |
The active connection.
|
private |
Whether or not the client has called Connect().
|
private |
|
private |
|
private |
|
private |
|
private |
The connection that might be alive for a short time after a RECONNECT is received from the server.
|
private |
|
private |
|
private |
|
protectedinherited |
Whether or not the internal updates of the component are on hold because of an issue with the OAuth token.
|
private |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
mutableprotectedinherited |
|
protectedinherited |
|
private |
|
private |
|
protectedinherited |
1.8.13