]> git.r.bdr.sh - rbdr/junction/blame_incremental - server/events.js
Format extension
[rbdr/junction] / server / events.js
... / ...
CommitLineData
1const internals = {
2 emitter(name, data, socket) {
3 socket.emit(name, data);
4 console.debug(`[${name}] ${JSON.stringify(data)}`);
5 },
6};
7
8export 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
25export function addPeer(peerId) {
26 return internals.emitter.bind(null, types.ADD_PEER, {
27 peerId,
28 });
29}
30
31export function removePeer(peerId) {
32 return internals.emitter.bind(null, types.REMOVE_PEER, {
33 peerId,
34 });
35}
36
37export function ICECandidateReceived(peerId, candidate) {
38 return internals.emitter.bind(null, types.ICE_CANDIDATE_RECEIVED, {
39 peerId,
40 candidate,
41 });
42}
43
44export function offerReceived(peerId, offer) {
45 return internals.emitter.bind(null, types.OFFER_RECEIVED, {
46 peerId,
47 offer,
48 });
49}
50
51export function answerReceived(peerId, answer) {
52 return internals.emitter.bind(null, types.ANSWER_RECEIVED, {
53 peerId,
54 answer,
55 });
56}