feat: add setter and getter apis to specify udp port range for webrtc (#39046)

* feat:Add setter and getter apis to specify udp port range for webrtc (issue#9042)

* lint error fix for PR#39046

* feat: add setter and getter apis to specify udp port range for webrtc (issue#9042) , changed for codereview

* fix lint error

* fix lint errors in file api-web-contents-spec.ts

* feat: add setter and getter apis to specify udp port range for webrtc (issue#9042) , changed for review from itsananderson

* feat: add setter and getter apis to specify udp port range for webrtc (issue#9042) , changed for review from jkleinsc

* fix lint error

* feat: add setter and getter apis to specify udp port range for webrtc (issue#9042) , changed for review from codebyter
This commit is contained in:
wanted002 2023-08-25 05:21:22 +08:00 committed by GitHub
parent 33000c4b42
commit e14964ccd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 109 additions and 0 deletions

View file

@ -2552,6 +2552,52 @@ void WebContents::SetWebRTCIPHandlingPolicy(
web_contents()->SyncRendererPrefs();
}
v8::Local<v8::Value> WebContents::GetWebRTCUDPPortRange(
v8::Isolate* isolate) const {
auto* prefs = web_contents()->GetMutableRendererPrefs();
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
dict.Set("min", static_cast<uint32_t>(prefs->webrtc_udp_min_port));
dict.Set("max", static_cast<uint32_t>(prefs->webrtc_udp_max_port));
return dict.GetHandle();
}
void WebContents::SetWebRTCUDPPortRange(gin::Arguments* args) {
uint32_t min = 0, max = 0;
gin_helper::Dictionary range;
if (!args->GetNext(&range) || !range.Get("min", &min) ||
!range.Get("max", &max)) {
gin_helper::ErrorThrower(args->isolate())
.ThrowError("'min' and 'max' are both required");
return;
}
if ((0 == min && 0 != max) || max > UINT16_MAX) {
gin_helper::ErrorThrower(args->isolate())
.ThrowError(
"'min' and 'max' must be in the (0, 65535] range or [0, 0]");
return;
}
if (min > max) {
gin_helper::ErrorThrower(args->isolate())
.ThrowError("'max' must be greater than or equal to 'min'");
return;
}
auto* prefs = web_contents()->GetMutableRendererPrefs();
if (prefs->webrtc_udp_min_port == static_cast<uint16_t>(min) &&
prefs->webrtc_udp_max_port == static_cast<uint16_t>(max)) {
return;
}
prefs->webrtc_udp_min_port = min;
prefs->webrtc_udp_max_port = max;
web_contents()->SyncRendererPrefs();
}
std::string WebContents::GetMediaSourceID(
content::WebContents* request_web_contents) {
auto* frame_host = web_contents()->GetPrimaryMainFrame();
@ -4319,9 +4365,11 @@ void WebContents::FillObjectTemplate(v8::Isolate* isolate,
.SetMethod("isBeingCaptured", &WebContents::IsBeingCaptured)
.SetMethod("setWebRTCIPHandlingPolicy",
&WebContents::SetWebRTCIPHandlingPolicy)
.SetMethod("setWebRTCUDPPortRange", &WebContents::SetWebRTCUDPPortRange)
.SetMethod("getMediaSourceId", &WebContents::GetMediaSourceID)
.SetMethod("getWebRTCIPHandlingPolicy",
&WebContents::GetWebRTCIPHandlingPolicy)
.SetMethod("getWebRTCUDPPortRange", &WebContents::GetWebRTCUDPPortRange)
.SetMethod("takeHeapSnapshot", &WebContents::TakeHeapSnapshot)
.SetMethod("setImageAnimationPolicy",
&WebContents::SetImageAnimationPolicy)