Package com.github.twitch4j.pubsub
Class TwitchPubSub
java.lang.Object
com.github.twitch4j.pubsub.TwitchPubSub
- All Implemented Interfaces:
ITwitchPubSub,java.lang.AutoCloseable
public class TwitchPubSub extends java.lang.Object implements ITwitchPubSub
Twitch PubSub
-
Field Summary
Fields Modifier and Type Field Description protected com.github.twitch4j.common.util.ExponentialBackoffStrategybackoffHelper class to compute delays between connection retries.protected java.util.concurrent.BlockingQueue<java.lang.String>commandQueueCommand Queueprotected java.util.concurrent.Future<?>heartbeatTaskHeartbeat Threadprotected booleanisClosedis Closed?protected longlastPingLast Ping send (1 minute delay before sending the first ping)protected longlastPongLast Pong receivedprotected java.util.concurrent.Future<?>queueTaskCommand Queue Threadstatic intREQUIRED_THREAD_COUNTprotected java.util.Set<PubSubRequest>subscribedTopicsHolds the subscribed topics in case we need to reconnectprotected java.util.concurrent.ScheduledExecutorServicetaskExecutorThread Pool Executorprotected com.neovisionaries.ws.client.WebSocketFactorywebSocketFactoryWebSocket Factory -
Constructor Summary
Constructors Constructor Description TwitchPubSub(com.github.philippheuer.events4j.core.EventManager eventManager, java.util.concurrent.ScheduledThreadPoolExecutor taskExecutor, com.github.twitch4j.common.config.ProxyConfig proxyConfig, java.util.Collection<java.lang.String> botOwnerIds)Constructor -
Method Summary
Modifier and Type Method Description voidclose()Closevoidconnect()Connecting to IRC-WSvoiddisconnect()Disconnecting from WebSocketcom.github.philippheuer.events4j.core.EventManagergetEventManager()EventManagerPubSubSubscriptionlistenOnTopic(PubSubRequest request)Send WS Message to subscribe to a topicvoidreconnect()Reconnecting to WebSocketbooleanunsubscribeFromTopic(PubSubSubscription subscription)Unsubscribe from a topic.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.github.twitch4j.pubsub.ITwitchPubSub
listenForAdPropertyRefreshEvents, listenForAdsEvents, listenForAutomodLevelsModificationEvents, listenForAutomodQueueEvents, listenForBitsBadgeEvents, listenForBountyBoardEvents, listenForBroadcastSettingUpdateEvents, listenForCelebrationEvents, listenForChannelBitsLeaderboardEvents, listenForChannelBitsLeaderboardEvents, listenForChannelBitsLeaderboardMonthlyEvents, listenForChannelChatroomEvents, listenForChannelDropEvents, listenForChannelExtensionEvents, listenForChannelPointsRedemptionEvents, listenForChannelPredictionsEvents, listenForChannelPrimeGiftStatusEvents, listenForChannelSquadEvents, listenForChannelSubGiftsEvents, listenForChannelSubLeaderboardEvents, listenForChannelSubLeaderboardEvents, listenForChannelSubLeaderboardMonthlyEvents, listenForChannelUnbanRequestEvents, listenForCheerEvents, listenForCommerceEvents, listenForCommunityBoostEvents, listenForCrowdChantEvents, listenForDashboardActivityFeedEvents, listenForExtensionControlEvents, listenForFollowingEvents, listenForFriendshipEvents, listenForHypeTrainEvents, listenForHypeTrainRewardEvents, listenForLeaderboardEvents, listenForLeaderboardEvents, listenForLeaderboardMonthlyEvents, listenForModerationEvents, listenForModerationEvents, listenForOnsiteNotificationEvents, listenForPollEvents, listenForPresenceEvents, listenForPublicBitEvents, listenForPublicCheerEvents, listenForRadioEvents, listenForRaidEvents, listenForStreamChangeEvents, listenForStreamChatRoomEvents, listenForSubscriptionEvents, listenForUserBitsUpdateEvents, listenForUserCampaignEvents, listenForUserChannelPointsEvents, listenForUserChatroomEvents, listenForUserDropEvents, listenForUserImageUpdateEvents, listenForUserModerationNotificationEvents, listenForUserPredictionsEvents, listenForUserPropertiesUpdateEvents, listenForUserSubscribeEvents, listenForUserUnbanRequestEvents, listenForVideoPlaybackByNameEvents, listenForVideoPlaybackEvents, listenForWatchPartyEvents, listenForWhisperEvents, listenOnTopic, listenOnTopic, listenOnTopic
-
Field Details
-
REQUIRED_THREAD_COUNT
public static final int REQUIRED_THREAD_COUNT- See Also:
- Constant Field Values
-
queueTask
protected final java.util.concurrent.Future<?> queueTaskCommand Queue Thread -
heartbeatTask
protected final java.util.concurrent.Future<?> heartbeatTaskHeartbeat Thread -
isClosed
protected volatile boolean isClosedis Closed? -
commandQueue
protected final java.util.concurrent.BlockingQueue<java.lang.String> commandQueueCommand Queue -
subscribedTopics
Holds the subscribed topics in case we need to reconnect -
lastPing
protected volatile long lastPingLast Ping send (1 minute delay before sending the first ping) -
lastPong
protected volatile long lastPongLast Pong received -
taskExecutor
protected final java.util.concurrent.ScheduledExecutorService taskExecutorThread Pool Executor -
webSocketFactory
protected final com.neovisionaries.ws.client.WebSocketFactory webSocketFactoryWebSocket Factory -
backoff
protected final com.github.twitch4j.common.util.ExponentialBackoffStrategy backoffHelper class to compute delays between connection retries.Configured to (approximately) emulate first-party clients:
- initially waits one second
- plus a small random jitter
- doubles the backoff period on subsequent failures
- up to a maximum backoff threshold of 2 minutes
-
-
Constructor Details
-
TwitchPubSub
public TwitchPubSub(com.github.philippheuer.events4j.core.EventManager eventManager, java.util.concurrent.ScheduledThreadPoolExecutor taskExecutor, com.github.twitch4j.common.config.ProxyConfig proxyConfig, java.util.Collection<java.lang.String> botOwnerIds)Constructor- Parameters:
eventManager- EventManagertaskExecutor- ScheduledThreadPoolExecutorproxyConfig- ProxyConfigbotOwnerIds- Bot Owner IDs
-
-
Method Details
-
connect
public void connect()Connecting to IRC-WS -
disconnect
public void disconnect()Disconnecting from WebSocket -
reconnect
public void reconnect()Reconnecting to WebSocket -
listenOnTopic
Description copied from interface:ITwitchPubSubSend WS Message to subscribe to a topic- Specified by:
listenOnTopicin interfaceITwitchPubSub- Parameters:
request- Topic- Returns:
- PubSubSubscription to be listened to
-
unsubscribeFromTopic
Description copied from interface:ITwitchPubSubUnsubscribe from a topic. Usage example:PubSubSubscription subscription = twitchPubSub.listenForCheerEvents(...); // ... twitchPubSub.unsubscribeFromTopic(subscription);- Specified by:
unsubscribeFromTopicin interfaceITwitchPubSub- Parameters:
subscription- PubSubSubscription to be unlistened from- Returns:
- whether the subscription was previously subscribed to
-
close
public void close()Close- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceITwitchPubSub
-
getEventManager
public com.github.philippheuer.events4j.core.EventManager getEventManager()EventManager- Specified by:
getEventManagerin interfaceITwitchPubSub
-