Skip to content

Commit

Permalink
fix: allow IEventSubSocket#register with null transport
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy committed Jul 19, 2023
1 parent 4162c8d commit 7b90791
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -370,12 +370,13 @@ private EventSubSubscription unsubscribeNoHelix(@NotNull EventSubSubscription re
return subscriptions.remove(SubscriptionWrapper.wrap(remove));
}

@Synchronized
private void onInitialConnection(final String websocketId) {
final Collection<EventSubSubscription> oldSubs = new ArrayDeque<>(subscriptions.size());
subscriptions.keySet().removeIf(oldSubs::add);

for (final EventSubSubscription old : oldSubs) {
if (StringUtils.equals(old.getTransport().getSessionId(), websocketId)) {
if (old.getTransport() != null && StringUtils.equals(old.getTransport().getSessionId(), websocketId)) {
// this branch shouldn't be hit, but is a performance optimization to avoid helix
subscriptions.putIfAbsent(SubscriptionWrapper.wrap(old), old);
} else {
Expand Down Expand Up @@ -653,11 +654,11 @@ static String getAuthToken(OAuth2Credential token) {
}

private static EventSubSubscription augmentSub(EventSubSubscription old, String newWebSocketId) {
assert old.getTransport() != null;
EventSubTransport transport = old.getTransport() != null ? old.getTransport() : EventSubTransport.builder().method(EventSubTransportMethod.WEBSOCKET).build();
return EventSubSubscription.builder()
.type(old.getType())
.condition(old.getCondition())
.transport(old.getTransport().withSessionId(newWebSocketId))
.transport(transport.withSessionId(newWebSocketId))
.isBatchingEnabled(old.isBatchingEnabled())
.rawType(old.getRawType())
.rawVersion(old.getRawVersion())
Expand Down

0 comments on commit 7b90791

Please sign in to comment.