Unify all WebRTC signaling in the API

Users, workers, and the coordinator will now send WebRTC signaling
information through a single API endpoint with a unified structure. The
payload should contain either an sdp or ice field for further processing
by the designated handlers.

Replaced API endpoints:
  - (101) WebrtcOffer -> WebrtcSignal
    Removed API endpoints:
  - WebrtcAnswer (102)
  - WebrtcIce (103)
This commit is contained in:
sergystepanov 2026-06-06 18:16:41 +03:00
parent f72202684f
commit a4b4e0458f
13 changed files with 63 additions and 69 deletions

View file

@ -4,9 +4,7 @@ const endpoints = {
LATENCY_CHECK: 3,
INIT: 4,
INIT_WEBRTC_STREAM: 100,
OFFER: 101,
ANSWER: 102,
ICE_CANDIDATE: 103,
WEBRTC_SIGNAL: 101,
GAME_START: 104,
GAME_QUIT: 105,
GAME_SAVE: 106,
@ -347,8 +345,8 @@ export const api = {
...(sdpOffer && { sdp: toJson(sdpOffer) }),
}),
sendIceCandidate: (candidate) =>
packet(endpoints.ICE_CANDIDATE, toJson(candidate)),
sendSdp: (sdp) => packet(endpoints.ANSWER, toJson(sdp)),
packet(endpoints.WEBRTC_SIGNAL, { ice: toJson(candidate) }),
sendSdp: (sdp) => packet(endpoints.WEBRTC_SIGNAL, { sdp: toJson(sdp) }),
latencyCheck: (id, list) => packet(endpoints.LATENCY_CHECK, list, id),
getWorkerList: () => packet(endpoints.GET_WORKER_LIST),
},

View file

@ -184,11 +184,17 @@ const onMessage = (m) => {
const initiator = !options.webrtcWaitOffer;
handleWebrtcStart({ data: payload, initiator });
break;
case api.endpoint.OFFER:
webrtc.answer(api.fromJson(payload));
break;
case api.endpoint.ICE_CANDIDATE:
webrtc.candidate(payload ? api.fromJson(payload) : "");
case api.endpoint.WEBRTC_SIGNAL:
const data = payload;
// it is eaither sdp or ice
if (Object.hasOwn(data, "ice")) {
webrtc.candidate(data.ice ? api.fromJson(data.ice) : "");
return;
}
if (Object.hasOwn(data, "sdp")) {
webrtc.answer(api.fromJson(data.sdp));
return;
}
break;
case api.endpoint.GAME_START:
if (payload.av) pub(APP_VIDEO_CHANGED, payload.av);