Package com.github.twitch4j.pubsub
Class TwitchPubSub
java.lang.Object
com.github.twitch4j.pubsub.TwitchPubSub
- All Implemented Interfaces:
ITwitchPubSub,AutoCloseable
Twitch PubSub
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final BlockingQueue<String>Command Queueprotected final Future<?>Heartbeat Threadprotected booleanis Closed?protected longLast Ping send (1 minute delay before sending the first ping)protected longLast Pong receivedprotected final Future<?>Command Queue Threadstatic final intprotected final Set<PubSubRequest>Holds the subscribed topics in case we need to reconnectprotected final ScheduledExecutorServiceThread Pool Executor -
Constructor Summary
ConstructorsConstructorDescriptionTwitchPubSub(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) Deprecated.Twitch will decommission PubSub on April 14, 2025, with shutdown windows starting in February. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closevoidconnect()Connecting to IRC-WSvoidDisconnecting from WebSocketcom.github.philippheuer.events4j.core.EventManagerEventManagerlonglistenOnTopic(PubSubRequest request) Send WS Message to subscribe to a topicprotected voidprotected voidprotected voidonTextMessage(String text) voidReconnecting 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, 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, listenForSharedChatEvents, 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
@Deprecated @ScheduledForRemoval(inVersion="2.0.0") 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) Deprecated.Twitch will decommission PubSub on April 14, 2025, with shutdown windows starting in February.Constructor- Parameters:
websocketConnection- WebsocketConnectioneventManager- EventManagertaskExecutor- ScheduledThreadPoolExecutorproxyConfig- ProxyConfigbotOwnerIds- Bot Owner IDswsPingPeriod- WebSocket Ping PeriodconnectionBackoffStrategy- WebSocket Connection Backoff StrategywsCloseDelay- Websocket Close DelayfallbackTopicHandler- Fallback Topic Handler- See Also:
-
-
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: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
-
getLatency
public long getLatency()- Specified by:
getLatencyin 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceITwitchPubSub
-
getEventManager
public com.github.philippheuer.events4j.core.EventManager getEventManager()EventManager- Specified by:
getEventManagerin interfaceITwitchPubSub
-