]> git.r.bdr.sh - rbdr/junction/blobdiff - server/events.js
Format and update docs
[rbdr/junction] / server / events.js
index 3ef21a9e3c69623276ab46cb8e75e398adeb2646..e8094d51c3980f7bb60d1220fc6e65932c7c8483 100644 (file)
@@ -1,51 +1,57 @@
+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, shouldCreateOffer) {
 export function addPeer(peerId, shouldCreateOffer) {
-  return {
+  return internals.emitter.bind(null, types.ADD_PEER, {
     peerId,
     shouldCreateOffer,
     peerId,
     shouldCreateOffer,
-  }
+  });
 }
 
 export function removePeer(peerId) {
 }
 
 export function removePeer(peerId) {
-    return {
-        peerId,
-    }
-}
-
-export function SessionDescriptionReceived(peerId, sessionDescription) {
-    return {
-        peerId,
-        sessionDescription,
-    }
+  return internals.emitter.bind(null, types.REMOVE_PEER, {
+    peerId,
+  });
 }
 
 export function ICECandidateReceived(peerId, candidate) {
 }
 
 export function ICECandidateReceived(peerId, candidate) {
-    return {
-        peerId,
-        candidate
-    }
+  return internals.emitter.bind(null, types.ICE_CANDIDATE_RECEIVED, {
+    peerId,
+    candidate,
+  });
 }
 
 export function offerReceived(peerId, offer) {
 }
 
 export function offerReceived(peerId, offer) {
-    return {
-        peerId,
-        offer
-    }
+  return internals.emitter.bind(null, types.OFFER_RECEIVED, {
+    peerId,
+    offer,
+  });
 }
 
 export function answerReceived(peerId, answer) {
 }
 
 export function answerReceived(peerId, answer) {
-    return {
-        peerId,
-        answer
-    }
+  return internals.emitter.bind(null, types.ANSWER_RECEIVED, {
+    peerId,
+    answer,
+  });
 }
 }
-
-export const types = {
-  ADD_PEER: 'addPeer',
-  REMOVE_PEER: 'removePeer',
-  RELAY_SESSION_DESCRIPTION: 'relaySessionDescription',
-  RELAY_ICE_CANDIDATE: 'relayICECandidate',
-       OFFER_RECEIVED: 'offerReceived',
-       ANSWER_RECEIVED: 'answerReceived',
-  ICE_CANDIDATE_RECEIVED: 'ICECandidateReceived',
-  SESSION_DESCRIPTION_RECEIVED: 'SessionDescriptionReceived',
-};