// Remote 'Connection' with...에 접근하는 방법
mySession.on('streamCreated', async (event) => {
const subscriber = mySession.subscribe(event.stream, undefined);
setSubscribers((subscribers) => [...subscribers, subscriber]);
console.log('상대 아이디빼오기', event.stream.inboundStreamOpts.id);
console.log('############', subscriber.stream.streamId);
});
더 밑부분에 보면 streamId도 커넥션 아이디를 가지고 있다.
const subscriberId = subscriber.stream.streamId.slice(-14); // 상대 커넥션 아이디
위 코드를 통해 뒤에서 부터 14글자만 슬라이스해서 상대 커넥션 아이디를 빼올 수 있다.
그리고 위에서 정렬한 커넥션ID와 비교하여 내가 먼저 온 유저인지 나중에 온 유저인지 알 수 있다.
이를 기점으로 USER_ONE과 USER_TWO의 분기를 나누기 시작했고,
이후로 턴에 따라 또 USER_ONE_PLAY, USER_TWO_PLAY로 나누어 총 4가지 경우의 수로 관리를 하였다.
이로 인해 후에 녹화, AI 측정, 음소거 등을 손쉽게 적용할 수 있었다.
도움이 되었습니다.