I
hate tothink, therefore I am.
-
👋 I'm a student developer from Incheon, South Korea
-
📝 Currently studying in middle school
-
For more information, visit here please.
-
⚡ Fun fact HTML is not a programming language
Unofficial Java API library of CHZZK (치지직, the video streaming service of Naver)
License: MIT License
I
hate tothink, therefore I am.
👋 I'm a student developer from Incheon, South Korea
📝 Currently studying in middle school
For more information, visit here please.
⚡ Fun fact HTML is not a programming language
안녕하세요. 글이 길어질거 같아 이곳에 작성해 봅니다.
채팅이 많이 올라오지 않는 채널에서 1분 후 채팅 커넥션이 끊기는 문제
해당 현상이 일어나고부터 혹시 api에 변경점이 있나 싶어 크롬 DevTools에서 chat 웹 소켓 통신 기록을 보니
채팅이 없는 경우(?) 클라이언트에서 한 번씩 특정 패턴으로 생존 확인용 핑 {"ver": "2","cmd": 0} 을 보내는 것을 확인했습니다.
그래서 테스트로 라이브러리 코드를 받아 치지직 채팅이 연결된 시점에서 20초 간격으로 핑 데이터를 보내게 수정하여 적용한 결과
약 20분 넘게 커넥션이 살아있는 것을 확인했습니다.
1분이상 채팅이 없거나 핑이 없는 경우 커넥션이 끊어짐 << 현재 상황
public class ChatWebsocketClient extends WebSocketClient {
private ChzzkChat chat;
private Gson gson;
private String sid;
private ScheduledExecutorService executor; //[수정]
public ChatWebsocketClient(ChzzkChat chat, URI websocketUri) {
super(websocketUri);
this.chat = chat;
this.gson = new Gson()
.newBuilder()
.disableHtmlEscaping()
.create();
this.executor = Executors.newSingleThreadScheduledExecutor(); //[수정]
}
/*...........생략...........*/
@Override
public void onMessage(String message) {
try {
if (chat.chzzk.isDebug) System.out.println("Message: " + message);
JsonObject parsedMessage = JsonParser.parseString(message)
.getAsJsonObject();
var cmdId = parsedMessage
.get("cmd")
.getAsInt();
var messageClass = getClientboundMessageClass(cmdId);
if (messageClass == WsMessageClientboundConnected.class) {
// handle connected message
WsMessageClientboundConnected msg = gson.fromJson(parsedMessage, WsMessageClientboundConnected.class);
if (msg.retCode == 0) {
if (chat.chzzk.isDebug) System.out.println("Successfully connected!");
sid = msg.bdy.sid;
for (ChatEventListener listener : chat.listeners) {
listener.onConnect(chat, chat.reconnecting);
}
Runnable task = () -> { //[수정]
System.out.println("작업 실행: " + System.currentTimeMillis() / 1000);
this.send(gson.toJson(new WsMessageServerboundPing()));
};
executor.scheduleAtFixedRate(task, 0, 20, TimeUnit.SECONDS); //[수정]
} else {
throw new ChatFailedConnectException(msg.retCode, msg.retMsg);
}
} else if (cmdId == WsMessageTypes.Commands.PING) {
/*...........생략...........*/
20초마다 코드를 실행하는 부분은 테스트 목적으로 chatGPT에 도움을 받아 끼워 맞춘 거라.... 더 좋은 방법이 있을 거라 생각됩니다......
글을 잘 못쓰기도하고 졸면서 작성한 글이라 엉망인점 죄송합니다......
Expected BEGIN_ARRAY but was BEGIN_OBJECT at path $.bdy
상황 : 현재 자체 제작중인 플러그인으로 치지직 채팅과 마인크래프트를 연동하려고 했지만, chat.connectFromChannelId 부분에서 연결에 실패했다라고 계속 나오고 있는 상황입니다.
스택 : JAVA 17, Gradle, Spigot 1.20.4
@EventHandler
public void sendChat() {
String CHANNEL_ID = config.getString("Chzzk_ID");
Chzzk chzzk = new ChzzkBuilder().build();
chat = chzzk.chat();
try {
chat.connectFromChannelId("be9d985008b754af059468dc15c52342");
//// chat.addListener(new ChatEventListener() {
//// @Override
//// public void onConnect() {
//// getLogger().info("치지직 서버와 연동에 성공하였습니다.");
//// chat.requestRecentChat(50);
//// }
////
//// @Override
//// public void onChat(ChatMessage msg) {
//// getServer().broadcastMessage("[채팅] " + msg.getProfile().getNickname() + ": " + msg.getContent());
//// }
////
//// @Override
//// public void onDonationChat(ChatMessage msg) {
//// getServer().broadcastMessage("[도네이션] " + msg.getProfile().getNickname() + ": " + msg.getContent() + " [" + msg.getExtras().getPayAmount() + "원]");
//// }
////
//// @Override
//// public void onConnectionClosed(int code, String reason, boolean remote) {
//// getLogger().warning("연결에 실패하였습니다.");
//// Bukkit.getPluginManager().disablePlugins();
//// }
// });
} catch (IOException e) {
getLogger().warning("연결에 실패하였습니다.");
throw new RuntimeException(e);
}
}
solution
temporary solution
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.