2 * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "WebRtcState.h"
23 namespace AittWebRTCNamespace {
25 class WebRtcEventHandler {
27 // TODO Add error and state callbacks
28 void SetOnStateChangedCb(std::function<void(WebRtcState::Stream)> on_state_changed_cb)
30 on_state_changed_cb_ = on_state_changed_cb;
32 void CallOnStateChangedCb(WebRtcState::Stream state) const
34 if (on_state_changed_cb_)
35 on_state_changed_cb_(state);
37 void UnsetOnStateChangedCb(void) { on_state_changed_cb_ = nullptr; };
39 void SetOnSignalingStateNotifyCb(
40 std::function<void(WebRtcState::Signaling)> on_signaling_state_notify_cb)
42 on_signaling_state_notify_cb_ = on_signaling_state_notify_cb;
44 void CallOnSignalingStateNotifyCb(WebRtcState::Signaling state) const
46 if (on_signaling_state_notify_cb_)
47 on_signaling_state_notify_cb_(state);
49 void UnsetOnSignalingStateNotifyCb(void) { on_signaling_state_notify_cb_ = nullptr; };
51 void SetOnIceCandidateCb(std::function<void(std::string)> on_ice_candidate_cb)
53 on_ice_candidate_cb_ = on_ice_candidate_cb;
55 void CallOnIceCandidateCb(std::string candidate) const
57 if (on_ice_candidate_cb_)
58 on_ice_candidate_cb_(candidate);
60 void UnsetOnIceCandidateCb(void) { on_ice_candidate_cb_ = nullptr; };
62 void SetOnIceGatheringStateNotifyCb(
63 std::function<void(WebRtcState::IceGathering)> on_ice_gathering_state_notify_cb)
65 on_ice_gathering_state_notify_cb_ = on_ice_gathering_state_notify_cb;
67 void CallOnIceGatheringStateNotifyCb(WebRtcState::IceGathering state) const
69 if (on_ice_gathering_state_notify_cb_)
70 on_ice_gathering_state_notify_cb_(state);
72 void UnsetOnIceGatheringStateNotifyeCb(void) { on_ice_gathering_state_notify_cb_ = nullptr; };
74 void SetOnIceConnectionStateNotifyCb(
75 std::function<void(WebRtcState::IceConnection)> on_ice_connection_state_notify_cb)
77 on_ice_connection_state_notify_cb_ = on_ice_connection_state_notify_cb;
79 void CallOnIceConnectionStateNotifyCb(WebRtcState::IceConnection state) const
81 if (on_ice_connection_state_notify_cb_)
82 on_ice_connection_state_notify_cb_(state);
84 void UnsetOnIceConnectionStateNotifyeCb(void) { on_ice_connection_state_notify_cb_ = nullptr; };
86 void SetOnEncodedFrameCb(std::function<void(void)> on_encoded_frame_cb)
88 on_encoded_frame_cb_ = on_encoded_frame_cb;
90 void CallOnEncodedFrameCb(void) const
92 if (on_encoded_frame_cb_)
93 on_encoded_frame_cb_();
95 void UnsetEncodedFrameCb(void) { on_encoded_frame_cb_ = nullptr; };
97 void SetOnTrakAddedCb(std::function<void(unsigned int id)> on_track_added_cb)
99 on_track_added_cb_ = on_track_added_cb;
101 void CallOnTrakAddedCb(unsigned int id) const
103 if (on_track_added_cb_)
104 on_track_added_cb_(id);
106 void UnsetTrackAddedCb(void) { on_track_added_cb_ = nullptr; };
109 std::function<void(void)> on_negotiation_needed_cb_;
110 std::function<void(WebRtcState::Stream)> on_state_changed_cb_;
111 std::function<void(WebRtcState::Signaling)> on_signaling_state_notify_cb_;
112 std::function<void(std::string)> on_ice_candidate_cb_;
113 std::function<void(WebRtcState::IceGathering)> on_ice_gathering_state_notify_cb_;
114 std::function<void(WebRtcState::IceConnection)> on_ice_connection_state_notify_cb_;
115 std::function<void(void)> on_encoded_frame_cb_;
116 std::function<void(unsigned int id)> on_track_added_cb_;
119 } // namespace AittWebRTCNamespace