mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Convert to and use LiveClientStopType enum for disconnecting websocket from magic numbers!
This commit is contained in:
@@ -24,6 +24,7 @@ package io.github.jwdeveloper.tiktok.live;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||
import io.github.jwdeveloper.tiktok.listener.ListenersManager;
|
||||
import io.github.jwdeveloper.tiktok.websocket.LiveClientStopType;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
@@ -49,16 +50,16 @@ public interface LiveClient {
|
||||
|
||||
/**
|
||||
* Disconnects the connection.
|
||||
* @param type
|
||||
* <p>0 - Normal - Initiates disconnection and returns
|
||||
* <p>1 - Disconnects blocking and returns after closure
|
||||
* <p>2 - Disconnects and kills connection to websocket
|
||||
* <p>Default {@link #disconnect()} is 0
|
||||
* @param type {@code LiveClientStopType}
|
||||
* @see LiveClientStopType
|
||||
*/
|
||||
void disconnect(int type);
|
||||
void disconnect(LiveClientStopType type);
|
||||
|
||||
/**
|
||||
* Disconnects with {@link LiveClientStopType#NORMAL}
|
||||
*/
|
||||
default void disconnect() {
|
||||
disconnect(0);
|
||||
disconnect(LiveClientStopType.NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2024 jwdeveloper jacekwoln@gmail.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok.websocket;
|
||||
|
||||
public enum LiveClientStopType
|
||||
{
|
||||
/**
|
||||
* Initiates the websocket close handshake. This method does not block<br> In oder to make sure
|
||||
* the connection is closed use {@link LiveClientStopType#CLOSE_BLOCKING}
|
||||
*/
|
||||
NORMAL,
|
||||
/**
|
||||
* Same as {@link LiveClientStopType#NORMAL} but blocks until the websocket closed or failed to do so.<br>
|
||||
*
|
||||
* @apiNote Can throw {@link InterruptedException} when/if the threads get interrupted
|
||||
*/
|
||||
CLOSE_BLOCKING,
|
||||
/**
|
||||
* This will close the connection immediately without a proper close handshake.
|
||||
* The code and the message therefore won't be transferred over the wire also they will be forwarded to onClose/onWebsocketClose. */
|
||||
DISCONNECT
|
||||
}
|
||||
@@ -27,6 +27,6 @@ import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||
|
||||
public interface LiveSocketClient {
|
||||
void start(LiveConnectionData.Response webcastResponse, LiveClient tikTokLiveClient);
|
||||
void stop(int type);
|
||||
void stop(LiveClientStopType type);
|
||||
boolean isConnected();
|
||||
}
|
||||
Reference in New Issue
Block a user