// 먼저 OpenAPI 인증을 완료한 클라이언트를 준비합니다.
ChzzkOauthLoginAdapter adapter = new ChzzkOauthLoginAdapter("localhost", 포트);
ChzzkClient client = new ChzzkClientBuilder("API_CLIENT_ID", "API_SECRET")
.withDebugMode()
.withLoginAdapter(adapter)
.build();
client.loginAsync().join();
// ...
ChzzkUserSession session = new ChzzkSessionBuilder(client)
// chzzk4j는 서버측에서 세션의 연결을 끊었을 때 자동으로 세션을 다시 생성합니다.
// 기본적으로는 이 기능이 활성화되어 있으나, 만약 비활성화하길 원한다면 Builder에서 withAutoRecreate를 false로 설정할 수 있습니다.
//.withAutoRecreate(false)
.buildUserSession();
// 원한다면 Client Session을 이용할 수도 있습니다만..
// 현재로서는 되도록이면 User Session을 활용해야 합니다.
//.buildClientSession();
session.on(SessionConnectedEvent.class, (event) -> {
System.out.println("Connected!");
});
session.createAndConnectAsync().join();