Package com.github.twitch4j.pubsub
Class TwitchPubSub
java.lang.Object
com.github.twitch4j.pubsub.TwitchPubSub
- All Implemented Interfaces:
ITwitchPubSub
,AutoCloseable
Twitch PubSub
-
Field Summary
Modifier and TypeFieldDescriptionprotected final BlockingQueue<String>
Command Queueprotected final Future<?>
Heartbeat Threadprotected boolean
is Closed?protected long
Last Ping send (1 minute delay before sending the first ping)protected long
Last Pong receivedprotected final Future<?>
Command Queue Threadstatic final int
protected final Set<PubSubRequest>
Holds the subscribed topics in case we need to reconnectprotected final ScheduledExecutorService
Thread Pool Executor -
Constructor Summary
ConstructorDescriptionTwitchPubSub
(WebsocketConnection websocketConnection, com.github.philippheuer.events4j.core.EventManager eventManager, ScheduledThreadPoolExecutor taskExecutor, ProxyConfig proxyConfig, Collection<String> botOwnerIds, int wsPingPeriod, IBackoffStrategy connectionBackoffStrategy, int wsCloseDelay, Consumer<PubSubResponsePayload> fallbackTopicHandler) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closevoid
connect()
Connecting to IRC-WSvoid
Disconnecting from WebSocketcom.github.philippheuer.events4j.core.EventManager
EventManagerlong
listenOnTopic
(PubSubRequest request) Send WS Message to subscribe to a topicprotected void
protected void
protected void
onTextMessage
(String text) void
Reconnecting to WebSocketboolean
unsubscribeFromTopic
(PubSubSubscription subscription) Unsubscribe from a topic.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.github.twitch4j.pubsub.ITwitchPubSub
listenForAdPropertyRefreshEvents, listenForAdsEvents, listenForAdsManagerEvents, listenForAutomodLevelsModificationEvents, listenForAutomodQueueEvents, listenForBitsBadgeEvents, listenForBountyBoardEvents, listenForBroadcastSettingUpdateEvents, listenForCelebrationEvents, listenForChannelBitsLeaderboardAllTimeEvents, listenForChannelBitsLeaderboardEvents, listenForChannelBitsLeaderboardEvents, listenForChannelBitsLeaderboardMonthlyEvents, listenForChannelChatroomEvents, listenForChannelDropEvents, listenForChannelExtensionEvents, listenForChannelPointsRedemptionEvents, listenForChannelPredictionsEvents, listenForChannelPrimeGiftStatusEvents, listenForChannelSquadEvents, listenForChannelSubGiftsEvents, listenForChannelSubLeaderboardAllTimeEvents, listenForChannelSubLeaderboardEvents, listenForChannelSubLeaderboardEvents, listenForChannelSubLeaderboardMonthlyEvents, listenForChannelUnbanRequestEvents, listenForCharityCampaignEvents, listenForChatHighlightEvents, listenForCheerEvents, listenForCommerceEvents, listenForCommunityBoostEvents, listenForCreatorGoalsEvents, listenForCrowdChantEvents, listenForDashboardActivityFeedEvents, listenForExtensionControlEvents, listenForFollowingEvents, listenForFollows, listenForFriendshipEvents, listenForHypeTrainEvents, listenForHypeTrainRewardEvents, listenForLeaderboardAllTimeEvents, listenForLeaderboardEvents, listenForLeaderboardEvents, listenForLeaderboardMonthlyEvents, listenForLowTrustUsersEvents, listenForModerationEvents, listenForModerationEvents, listenForOnsiteNotificationEvents, listenForPinnedChatEvents, listenForPollEvents, listenForPresenceEvents, listenForPublicBitEvents, listenForPublicCheerEvents, listenForRadioEvents, listenForRaidEvents, listenForShieldModeEvents, listenForShoutoutEvents, 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:
-
queueTask
Command Queue Thread -
heartbeatTask
Heartbeat Thread -
isClosed
protected volatile boolean isClosedis Closed? -
commandQueue
Command 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
Thread Pool Executor
-
-
Constructor Details
-
TwitchPubSub
public TwitchPubSub(WebsocketConnection websocketConnection, com.github.philippheuer.events4j.core.EventManager eventManager, ScheduledThreadPoolExecutor taskExecutor, ProxyConfig proxyConfig, Collection<String> botOwnerIds, int wsPingPeriod, IBackoffStrategy connectionBackoffStrategy, int wsCloseDelay, Consumer<PubSubResponsePayload> fallbackTopicHandler) Constructor- Parameters:
websocketConnection
- WebsocketConnectioneventManager
- EventManagertaskExecutor
- ScheduledThreadPoolExecutorproxyConfig
- ProxyConfigbotOwnerIds
- Bot Owner IDswsPingPeriod
- WebSocket Ping PeriodconnectionBackoffStrategy
- WebSocket Connection Backoff StrategywsCloseDelay
- Websocket Close DelayfallbackTopicHandler
- Fallback Topic Handler
-
-
Method Details
-
connect
public void connect()Connecting to IRC-WS -
disconnect
public void disconnect()Disconnecting from WebSocket -
reconnect
public void reconnect()Reconnecting to WebSocket -
onPreConnect
protected void onPreConnect() -
onConnected
protected void onConnected() -
onTextMessage
-
listenOnTopic
Description copied from interface:ITwitchPubSub
Send WS Message to subscribe to a topic- Specified by:
listenOnTopic
in interfaceITwitchPubSub
- Parameters:
request
- Topic- Returns:
- PubSubSubscription to be listened to
-
unsubscribeFromTopic
Description copied from interface:ITwitchPubSub
Unsubscribe from a topic. Usage example:PubSubSubscription subscription = twitchPubSub.listenForCheerEvents(...); // ... twitchPubSub.unsubscribeFromTopic(subscription);
- Specified by:
unsubscribeFromTopic
in interfaceITwitchPubSub
- Parameters:
subscription
- PubSubSubscription to be unlistened from- Returns:
- whether the subscription was previously subscribed to
-
getLatency
public long getLatency()- Specified by:
getLatency
in interfaceITwitchPubSub
- Returns:
- the most recently measured round-trip latency for the socket(s) in milliseconds, or -1 if unknown
-
close
public void close()Close- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceITwitchPubSub
-
getEventManager
public com.github.philippheuer.events4j.core.EventManager getEventManager()EventManager- Specified by:
getEventManager
in interfaceITwitchPubSub
-