Benjamin Wright | 728b9b5 | 2018-07-03 13:28:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | package org.webrtc; |
| 12 | |
Byoungchan Lee | 02334e0 | 2021-08-14 11:41:59 +0900 | [diff] [blame] | 13 | import androidx.annotation.Nullable; |
Benjamin Wright | 728b9b5 | 2018-07-03 13:28:34 -0700 | [diff] [blame] | 14 | |
| 15 | /** |
| 16 | * PeerConnectionDependencies holds all PeerConnection dependencies that are |
| 17 | * applied per PeerConnection. A dependency is distinct from a configuration |
| 18 | * as it defines significant executable code that can be provided by a user of |
| 19 | * the API. |
| 20 | */ |
| 21 | public final class PeerConnectionDependencies { |
| 22 | // Mandatory dependencies. |
Benjamin Wright | 8cf3040 | 2018-07-20 15:08:03 -0700 | [diff] [blame] | 23 | private final PeerConnection.Observer observer; |
| 24 | |
| 25 | // Optional fields. |
| 26 | private final SSLCertificateVerifier sslCertificateVerifier; |
Benjamin Wright | 728b9b5 | 2018-07-03 13:28:34 -0700 | [diff] [blame] | 27 | |
| 28 | public static class Builder { |
| 29 | private PeerConnection.Observer observer; |
Benjamin Wright | 8cf3040 | 2018-07-20 15:08:03 -0700 | [diff] [blame] | 30 | private SSLCertificateVerifier sslCertificateVerifier; |
Benjamin Wright | 728b9b5 | 2018-07-03 13:28:34 -0700 | [diff] [blame] | 31 | |
| 32 | private Builder(PeerConnection.Observer observer) { |
| 33 | this.observer = observer; |
| 34 | } |
| 35 | |
Benjamin Wright | 8cf3040 | 2018-07-20 15:08:03 -0700 | [diff] [blame] | 36 | public Builder setSSLCertificateVerifier(SSLCertificateVerifier sslCertificateVerifier) { |
| 37 | this.sslCertificateVerifier = sslCertificateVerifier; |
| 38 | return this; |
| 39 | } |
| 40 | |
Benjamin Wright | 728b9b5 | 2018-07-03 13:28:34 -0700 | [diff] [blame] | 41 | // Observer is a required dependency and so is forced in the construction of the object. |
| 42 | public PeerConnectionDependencies createPeerConnectionDependencies() { |
Benjamin Wright | 8cf3040 | 2018-07-20 15:08:03 -0700 | [diff] [blame] | 43 | return new PeerConnectionDependencies(observer, sslCertificateVerifier); |
Benjamin Wright | 728b9b5 | 2018-07-03 13:28:34 -0700 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
| 47 | public static Builder builder(PeerConnection.Observer observer) { |
| 48 | return new Builder(observer); |
| 49 | } |
| 50 | |
| 51 | PeerConnection.Observer getObserver() { |
| 52 | return observer; |
| 53 | } |
| 54 | |
Benjamin Wright | 8cf3040 | 2018-07-20 15:08:03 -0700 | [diff] [blame] | 55 | @Nullable |
| 56 | SSLCertificateVerifier getSSLCertificateVerifier() { |
| 57 | return sslCertificateVerifier; |
| 58 | } |
| 59 | |
| 60 | private PeerConnectionDependencies( |
| 61 | PeerConnection.Observer observer, SSLCertificateVerifier sslCertificateVerifier) { |
Benjamin Wright | 728b9b5 | 2018-07-03 13:28:34 -0700 | [diff] [blame] | 62 | this.observer = observer; |
Benjamin Wright | 8cf3040 | 2018-07-20 15:08:03 -0700 | [diff] [blame] | 63 | this.sslCertificateVerifier = sslCertificateVerifier; |
Benjamin Wright | 728b9b5 | 2018-07-03 13:28:34 -0700 | [diff] [blame] | 64 | } |
| 65 | } |