1 | /* |
2 | * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies). |
3 | * Copyright (C) 2017 Apple Inc. All rights reserved. |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
15 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
16 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
17 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
18 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
19 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
20 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | */ |
26 | |
27 | #include "config.h" |
28 | |
29 | #if ENABLE(WEB_RTC) |
30 | |
31 | #include "RTCNotifiersMock.h" |
32 | |
33 | #include "RTCDataChannelHandlerMock.h" |
34 | #include "RTCSessionDescriptionDescriptor.h" |
35 | #include "RTCSessionDescriptionRequest.h" |
36 | #include "RTCVoidRequest.h" |
37 | |
38 | namespace WebCore { |
39 | |
40 | SessionRequestNotifier::SessionRequestNotifier(RefPtr<RTCSessionDescriptionRequest>&& request, RefPtr<RTCSessionDescriptionDescriptor>&& descriptor, const String& errorName) |
41 | : m_request(WTFMove(request)) |
42 | , m_descriptor(WTFMove(descriptor)) |
43 | , m_errorName(errorName) |
44 | { |
45 | } |
46 | |
47 | void SessionRequestNotifier::fire() |
48 | { |
49 | if (m_descriptor) |
50 | m_request->requestSucceeded(*m_descriptor); |
51 | else |
52 | m_request->requestFailed(m_errorName); |
53 | } |
54 | |
55 | VoidRequestNotifier::VoidRequestNotifier(RefPtr<RTCVoidRequest>&& request, bool success, const String& errorName) |
56 | : m_request(WTFMove(request)) |
57 | , m_success(success) |
58 | , m_errorName(errorName) |
59 | { |
60 | } |
61 | |
62 | void VoidRequestNotifier::fire() |
63 | { |
64 | if (m_success) |
65 | m_request->requestSucceeded(); |
66 | else |
67 | m_request->requestFailed(m_errorName); |
68 | } |
69 | |
70 | IceConnectionNotifier::IceConnectionNotifier(RTCPeerConnectionHandlerClient* client, RTCIceConnectionState connectionState, RTCIceGatheringState gatheringState) |
71 | : m_client(client) |
72 | , m_connectionState(connectionState) |
73 | , m_gatheringState(gatheringState) |
74 | { |
75 | } |
76 | |
77 | void IceConnectionNotifier::fire() |
78 | { |
79 | m_client->didChangeIceGatheringState(m_gatheringState); |
80 | m_client->didChangeIceConnectionState(m_connectionState); |
81 | } |
82 | |
83 | SignalingStateNotifier::SignalingStateNotifier(RTCPeerConnectionHandlerClient* client, RTCSignalingState signalingState) |
84 | : m_client(client) |
85 | , m_signalingState(signalingState) |
86 | { |
87 | } |
88 | |
89 | void SignalingStateNotifier::fire() |
90 | { |
91 | m_client->didChangeSignalingState(m_signalingState); |
92 | } |
93 | |
94 | RemoteDataChannelNotifier::RemoteDataChannelNotifier(RTCPeerConnectionHandlerClient* client) |
95 | : m_client(client) |
96 | { |
97 | } |
98 | |
99 | void RemoteDataChannelNotifier::fire() |
100 | { |
101 | m_client->didAddRemoteDataChannel(std::make_unique<RTCDataChannelHandlerMock>("RTCDataChannelHandlerMock" , RTCDataChannelInit())); |
102 | } |
103 | |
104 | DataChannelStateNotifier::DataChannelStateNotifier(RTCDataChannelHandlerClient* client, RTCDataChannelState state) |
105 | : m_client(client) |
106 | , m_state(state) |
107 | { |
108 | } |
109 | |
110 | void DataChannelStateNotifier::fire() |
111 | { |
112 | m_client->didChangeReadyState(m_state); |
113 | } |
114 | |
115 | } // namespace WebCore |
116 | |
117 | #endif // ENABLE(WEB_RTC) |
118 | |