Skip to content

Commit 1b11778

Browse files
Copilotcommjoen
andauthored
refactor: tighten rtc signal sdp typing consistency
Agent-Logs-Url: https://github.com/commjoen/generated-game-experiment/sessions/067711ff-c6f0-4f72-abb6-78265c240876 Co-authored-by: commjoen <1457214+commjoen@users.noreply.github.com>
1 parent 4e6dcac commit 1b11778

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

src/multiplayer.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ interface PlayerPosition {
1919
}
2020

2121
type RTCSignalData =
22-
| { type: 'offer'; sdp: RTCSessionDescriptionInit | null }
23-
| { type: 'answer'; sdp: RTCSessionDescriptionInit | null }
22+
| { type: 'offer'; sdp: RTCSessionDescriptionInit }
23+
| { type: 'answer'; sdp: RTCSessionDescriptionInit }
2424
| { type: 'ice-candidate'; candidate: RTCIceCandidateInit };
2525

2626
function toPartialPlayerPosition(data: unknown): Partial<PlayerPosition> {
@@ -39,7 +39,7 @@ function isRTCSignalData(signal: unknown): signal is RTCSignalData {
3939
if (!signal || typeof signal !== 'object') return false;
4040
const parsed = signal as Record<string, unknown>;
4141
if (parsed.type === 'offer' || parsed.type === 'answer') {
42-
return parsed.sdp === null || typeof parsed.sdp === 'object';
42+
return typeof parsed.sdp === 'object' && parsed.sdp !== null;
4343
}
4444
if (parsed.type === 'ice-candidate') {
4545
return typeof parsed.candidate === 'object' && parsed.candidate !== null;
@@ -521,7 +521,6 @@ export class MultiplayerManager {
521521
const rtcSignal = signal;
522522

523523
if (rtcSignal.type === 'offer') {
524-
if (!rtcSignal.sdp) return;
525524
await this.initWebRTCConnection(fromId, false);
526525
const pc = this.peerConnections.get(fromId);
527526
if (!pc) return;
@@ -534,7 +533,6 @@ export class MultiplayerManager {
534533
signal: { type: 'answer', sdp: pc.localDescription },
535534
});
536535
} else if (rtcSignal.type === 'answer') {
537-
if (!rtcSignal.sdp) return;
538536
const pc = this.peerConnections.get(fromId);
539537
if (pc) {
540538
await pc.setRemoteDescription(

0 commit comments

Comments
 (0)