]>
Commit | Line | Data |
---|---|---|
6a3568bc RBR |
1 | const internals = { |
2 | emitter(name, data, socket) { | |
3 | socket.emit(name, data); | |
4 | console.debug(`[${name}] ${JSON.stringify(data)}`); | |
5 | }, | |
6 | }; | |
7 | ||
8 | export const types = { | |
9 | /* Listened */ | |
10 | CONNECTION: "connection", | |
11 | JOIN: "join", | |
12 | DISCONNECTING: "disconnecting", | |
13 | RELAY_ICE_CANDIDATE: "relayICECandidate", | |
14 | RELAY_OFFER: "relayOffer", | |
15 | RELAY_ANSWER: "relayAnswer", | |
16 | ||
17 | /* Emitted */ | |
18 | ADD_PEER: "addPeer", | |
19 | REMOVE_PEER: "removePeer", | |
20 | OFFER_RECEIVED: "offerReceived", | |
21 | ANSWER_RECEIVED: "answerReceived", | |
22 | ICE_CANDIDATE_RECEIVED: "ICECandidateReceived", | |
23 | }; | |
24 | ||
3f2e36ea | 25 | export function addPeer(peerId, shouldCreateOffer) { |
6a3568bc | 26 | return internals.emitter.bind(null, types.ADD_PEER, { |
284fc661 | 27 | peerId, |
3f2e36ea | 28 | shouldCreateOffer |
6a3568bc | 29 | }); |
ed9f8fd5 | 30 | } |
31 | ||
80172072 | 32 | export function removePeer(peerId) { |
6a3568bc RBR |
33 | return internals.emitter.bind(null, types.REMOVE_PEER, { |
34 | peerId, | |
35 | }); | |
284fc661 RBR |
36 | } |
37 | ||
38 | export function ICECandidateReceived(peerId, candidate) { | |
6a3568bc RBR |
39 | return internals.emitter.bind(null, types.ICE_CANDIDATE_RECEIVED, { |
40 | peerId, | |
41 | candidate, | |
42 | }); | |
284fc661 RBR |
43 | } |
44 | ||
45 | export function offerReceived(peerId, offer) { | |
6a3568bc RBR |
46 | return internals.emitter.bind(null, types.OFFER_RECEIVED, { |
47 | peerId, | |
48 | offer, | |
49 | }); | |
ed9f8fd5 | 50 | } |
51 | ||
284fc661 | 52 | export function answerReceived(peerId, answer) { |
6a3568bc RBR |
53 | return internals.emitter.bind(null, types.ANSWER_RECEIVED, { |
54 | peerId, | |
55 | answer, | |
56 | }); | |
ed9f8fd5 | 57 | } |