// Path: src/main/java/org/nextrtc/signalingserver/api/dto/NextRTCMember.java
// public interface NextRTCMember {
//     default String getId() {
//         return getConnection().getId();
//     }
// 
//     Connection getConnection();
// }
// 
// Path: src/main/java/org/nextrtc/signalingserver/cases/ExchangeSignalsBetweenMembers.java
// @Component
// @Scope("prototype")
// public class ExchangeSignalsBetweenMembers {
// 
//     private RTCConnections connections;
//     private ConnectionContextFactory factory;
// 
//     @Inject
//     public ExchangeSignalsBetweenMembers(RTCConnections connections, ConnectionContextFactory factory) {
//         this.connections = connections;
//         this.factory = factory;
//     }
// 
//     public synchronized void begin(Member from, Member to) {
//         connections.put(from, to, factory.create(from, to));
//         connections.get(from, to).ifPresent(ConnectionContext::begin);
//     }
// 
//     public synchronized void execute(InternalMessage message) {
//         connections.get(message.getFrom(), message.getTo()).ifPresent(context -> context.process(message));
//     }
// }
// 
// Path: src/main/java/org/nextrtc/signalingserver/cases/LeftConversation.java
// @Component(Signals.LEFT_HANDLER)
// public class LeftConversation implements SignalHandler {
// 
//     private NextRTCEventBus eventBus;
//     private ConversationRepository conversations;
// 
//     @Inject
//     public LeftConversation(NextRTCEventBus eventBus, ConversationRepository conversations) {
//         this.eventBus = eventBus;
//         this.conversations = conversations;
//     }
// 
//     public void execute(InternalMessage context) {
//         final Member leaving = context.getFrom();
//         Conversation conversation = checkPrecondition(leaving.getConversation());
// 
//         conversation.left(leaving);
//     }
// 
//     public void destroy(Conversation toRemove, Member last) {
//         eventBus.post(CONVERSATION_DESTROYED.basedOn(
//                 builder()
//                         .conversation(conversations.remove(toRemove.getId()))
//                         .from(last)));
//     }
// 
//     private Conversation checkPrecondition(Optional<Conversation> conversation) {
//         if (!conversation.isPresent()) {
//             throw CONVERSATION_NOT_FOUND.exception();
//         }
//         return conversation.get();
//     }
// 
// }


import com.google.common.collect.Sets;
import org.nextrtc.signalingserver.api.dto.NextRTCMember;
import org.nextrtc.signalingserver.cases.ExchangeSignalsBetweenMembers;
import org.nextrtc.signalingserver.cases.LeftConversation;
import org.nextrtc.signalingserver.domain.*;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.io.IOException;
import java.util.Set;
            sendJoinedToBroadcaster(sender, id);
        } else {
            sendJoinedToConversation(sender, id);
            sendJoinedFrom(broadcaster, sender);
        }
    }

    private void beginSignalExchangeBetweenBroadcasterAndNewAudience(Member sender) {
        if (!sender.equals(broadcaster)) {
            sendJoinedFrom(sender, broadcaster);
            exchange.begin(broadcaster, sender);
        }
    }

    private void sendJoinedToBroadcaster(Member sender, String id) {
        messageSender.send(InternalMessage.create()//
                .to(sender)//
                .signal(Signal.CREATED)//
                .addCustom("type", "BROADCAST")
                .content(id)//
                .build()//
        );
    }

    @Override
    public void close() throws IOException {
        remove(broadcaster);
    }

    @Inject
// Path: src/main/java/org/nextrtc/signalingserver/api/dto/NextRTCMember.java
// public interface NextRTCMember {
//     default String getId() {
//         return getConnection().getId();
//     }
// 
//     Connection getConnection();
// }
// 
// Path: src/main/java/org/nextrtc/signalingserver/cases/ExchangeSignalsBetweenMembers.java
// @Component
// @Scope("prototype")
// public class ExchangeSignalsBetweenMembers {
// 
//     private RTCConnections connections;
//     private ConnectionContextFactory factory;
// 
//     @Inject
//     public ExchangeSignalsBetweenMembers(RTCConnections connections, ConnectionContextFactory factory) {
//         this.connections = connections;
//         this.factory = factory;
//     }
// 
//     public synchronized void begin(Member from, Member to) {
//         connections.put(from, to, factory.create(from, to));
//         connections.get(from, to).ifPresent(ConnectionContext::begin);
//     }
// 
//     public synchronized void execute(InternalMessage message) {
//         connections.get(message.getFrom(), message.getTo()).ifPresent(context -> context.process(message));
//     }
// }
// 
// Path: src/main/java/org/nextrtc/signalingserver/cases/LeftConversation.java
// @Component(Signals.LEFT_HANDLER)
// public class LeftConversation implements SignalHandler {
// 
//     private NextRTCEventBus eventBus;
//     private ConversationRepository conversations;
// 
//     @Inject
//     public LeftConversation(NextRTCEventBus eventBus, ConversationRepository conversations) {
//         this.eventBus = eventBus;
//         this.conversations = conversations;
//     }
// 
//     public void execute(InternalMessage context) {
//         final Member leaving = context.getFrom();
//         Conversation conversation = checkPrecondition(leaving.getConversation());
// 
//         conversation.left(leaving);
//     }
// 
//     public void destroy(Conversation toRemove, Member last) {
//         eventBus.post(CONVERSATION_DESTROYED.basedOn(
//                 builder()
//                         .conversation(conversations.remove(toRemove.getId()))
//                         .from(last)));
//     }
// 
//     private Conversation checkPrecondition(Optional<Conversation> conversation) {
//         if (!conversation.isPresent()) {
//             throw CONVERSATION_NOT_FOUND.exception();
//         }
//         return conversation.get();
//     }
// 
// }


// Path: src/main/java/org/nextrtc/signalingserver/domain/conversation/BroadcastConversation.java
import com.google.common.collect.Sets;
import org.nextrtc.signalingserver.api.dto.NextRTCMember;
import org.nextrtc.signalingserver.cases.ExchangeSignalsBetweenMembers;
import org.nextrtc.signalingserver.cases.LeftConversation;
import org.nextrtc.signalingserver.domain.*;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.io.IOException;
import java.util.Set;

            sendJoinedToBroadcaster(sender, id);
        } else {
            sendJoinedToConversation(sender, id);
            sendJoinedFrom(broadcaster, sender);
        }
    }

    private void beginSignalExchangeBetweenBroadcasterAndNewAudience(Member sender) {
        if (!sender.equals(broadcaster)) {
            sendJoinedFrom(sender, broadcaster);
            exchange.begin(broadcaster, sender);
        }
    }

    private void sendJoinedToBroadcaster(Member sender, String id) {
        messageSender.send(InternalMessage.create()//
                .to(sender)//
                .signal(Signal.CREATED)//
                .addCustom("type", "BROADCAST")
                .content(id)//
                .build()//
        );
    }

    @Override
    public void close() throws IOException {
        remove(broadcaster);
    }

    @Inject
    public void setExchange(ExchangeSignalsBetweenMembers exchange) {