Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sdp m line index to ICE Candidates #22667

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/components/ha-web-rtc-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class HaWebRtcPlayer extends LitElement {

private _sessionId?: string;

private _candidatesList: string[] = [];
private _candidatesList: RTCIceCandidate[] = [];

protected override render(): TemplateResult {
if (this._error) {
Expand Down Expand Up @@ -248,11 +248,13 @@ class HaWebRtcPlayer extends LitElement {
if (event.type === "session") {
this._sessionId = event.session_id;
this._candidatesList.forEach((candidate) =>
// sdpMLineIndex is always populated
addWebRtcCandidate(
this.hass,
this.entityid!,
event.session_id,
candidate
candidate.candidate,
candidate?.sdpMLineIndex || 0
sdb9696 marked this conversation as resolved.
Show resolved Hide resolved
)
);
this._candidatesList = [];
Expand All @@ -267,7 +269,10 @@ class HaWebRtcPlayer extends LitElement {

try {
await this._peerConnection?.addIceCandidate(
new RTCIceCandidate({ candidate: event.candidate, sdpMid: "0" })
new RTCIceCandidate({
candidate: event.candidate,
sdpMLineIndex: event.sdp_m_line_index,
})
);
} catch (err: any) {
// eslint-disable-next-line no-console
Expand All @@ -285,17 +290,24 @@ class HaWebRtcPlayer extends LitElement {
return;
}

this._logEvent("local ice candidate", event.candidate?.candidate);
this._logEvent(
"local ice candidate",
event.candidate?.candidate,
event.candidate?.sdpMLineIndex
);

if (this._sessionId) {
// sdpMLineIndex is always populated
const sdpMLineIndex = event.candidate?.sdpMLineIndex || 0;
addWebRtcCandidate(
this.hass,
this.entityid,
this._sessionId,
event.candidate?.candidate
event.candidate?.candidate,
sdpMLineIndex
);
} else {
this._candidatesList.push(event.candidate?.candidate);
this._candidatesList.push(event.candidate);
}
};

Expand Down
7 changes: 5 additions & 2 deletions src/data/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface WebRtcAnswer {
export interface WebRtcCandidate {
type: "candidate";
candidate: string;
sdp_m_line_index: number;
}

export interface WebRtcError {
Expand Down Expand Up @@ -139,13 +140,15 @@ export const addWebRtcCandidate = (
hass: HomeAssistant,
entity_id: string,
session_id: string,
candidate: string
candidate: string,
sdpMLineIndex: number
) =>
hass.callWS({
type: "camera/webrtc/candidate",
entity_id,
session_id,
candidate,
candidate: candidate,
sdp_m_line_index: sdpMLineIndex,
});

export const fetchCameraPrefs = (hass: HomeAssistant, entityId: string) =>
Expand Down
Loading