-export function addPeer(peerId, shouldCreateOffer) {
- return {
- peer_id: peerId,
- should_create_offer: shouldCreateOffer,
- }
+const internals = {
+ emitter(name, data, socket) {
+ socket.emit(name, data);
+ console.debug(`[${name}] ${JSON.stringify(data)}`);
+ },
+};
+
+export const types = {
+ /* Listened */
+ CONNECTION: "connection",
+ JOIN: "join",
+ DISCONNECTING: "disconnecting",
+ RELAY_ICE_CANDIDATE: "relayICECandidate",
+ RELAY_OFFER: "relayOffer",
+ RELAY_ANSWER: "relayAnswer",
+
+ /* Emitted */
+ ADD_PEER: "addPeer",
+ REMOVE_PEER: "removePeer",
+ OFFER_RECEIVED: "offerReceived",
+ ANSWER_RECEIVED: "answerReceived",
+ ICE_CANDIDATE_RECEIVED: "ICECandidateReceived",
+};
+
+export function addPeer(peerId) {
+ return internals.emitter.bind(null, types.ADD_PEER, {
+ peerId,
+ });