Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 99d60ac

Browse files
authored
Add a new event OnPeerConnectionClosed for P2PClientObserver. (#655)
1 parent 61c67ea commit 99d60ac

File tree

6 files changed

+52
-10
lines changed

6 files changed

+52
-10
lines changed

build_overrides/build.gni

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,7 @@ declare_args() {
6868

6969
# Enable HEVC for WebRTC.
7070
rtc_use_h265 = false
71+
72+
# Build OWT for cloud gaming. It enables low latency features, and disables audio processing. It may break normal WebRTC features, is not intended for general use.
73+
owt_cloud_gaming = false
7174
}

talk/owt/BUILD.gn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
import("//build/config/sysroot.gni")
6+
import("//build_overrides/build.gni")
67
import("//testing/test.gni")
78
import("//third_party/webrtc/webrtc.gni")
89

@@ -223,6 +224,7 @@ static_library("owt_sdk_base") {
223224
if (rtc_use_h265) {
224225
defines += [ "WEBRTC_USE_H265" ]
225226
}
227+
226228
if (is_win || is_linux) {
227229
# Custom audio/video input and output.
228230
# When rebasing libwebrtc to a new version, custom audio/video input/output
@@ -385,6 +387,9 @@ static_library("owt_sdk_p2p") {
385387
configs -= [ "//build/config/clang:find_bad_constructs" ]
386388
}
387389
configs += [ ":owt_symbols" ]
390+
if (owt_cloud_gaming) {
391+
defines = [ "OWT_CLOUD_GAMING" ]
392+
}
388393
}
389394
static_library("owt_sdk_conf") {
390395
deps = [

talk/owt/sdk/include/cpp/owt/p2p/p2pclient.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ class OWT_EXPORT P2PClientObserver {
6363
signaling server.
6464
*/
6565
virtual void OnServerDisconnected(){}
66+
67+
#ifdef OWT_CLOUD_GAMING
68+
/**
69+
@brief This function will be invoked when a PeerConnection with remote
70+
endpoint is closed. SDK will create a new PeerConnection if publish or send
71+
is called by either side.
72+
*/
73+
virtual void OnPeerConnectionClosed(const std::string& remote_user_id) {}
74+
#endif
6675
};
6776
/// An async client for P2P WebRTC sessions
6877
class OWT_EXPORT P2PClient final

talk/owt/sdk/p2p/p2pclient.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,11 @@ void P2PClient::OnStopped(const std::string& remote_id) {
443443
const std::lock_guard<std::mutex> lock(pc_channels_mutex_);
444444
pc_channels_.erase(remote_id);
445445
}
446-
})
447-
.detach();
446+
}).detach();
447+
#ifdef OWT_CLOUD_GAMING
448+
EventTrigger::OnEvent1(observers_, event_queue_,
449+
&P2PClientObserver::OnPeerConnectionClosed, remote_id);
450+
#endif
448451
}
449452
void P2PClient::OnStreamAdded(std::shared_ptr<RemoteStream> stream) {
450453
EventTrigger::OnEvent1(

talk/owt/sdk/p2p/tests/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import("//third_party/webrtc/webrtc.gni")
2+
import("//build_overrides/build.gni")
23

34
rtc_test("p2p_e2e_test") {
45
testonly = true
@@ -18,4 +19,7 @@ rtc_test("p2p_e2e_test") {
1819
if (is_win) {
1920
libs = [ "dcomp.lib" ]
2021
}
22+
if(owt_cloud_gaming){
23+
defines = [ "OWT_CLOUD_GAMING" ]
24+
}
2125
}

talk/owt/sdk/p2p/tests/e2e_tests.cc

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class P2PClientMockObserver : public owt::p2p::P2PClientObserver {
2727
MOCK_METHOD2(OnMessageReceived, void(const std::string&, const std::string));
2828
MOCK_METHOD1(OnStreamAdded,
2929
void(std::shared_ptr<owt::base::RemoteStream> stream));
30+
#ifdef OWT_CLOUD_GAMING
31+
MOCK_METHOD1(OnPeerConnectionClosed, void(const std::string&));
32+
#endif
3033
};
3134

3235
// A sink dumps video frames in a given interval.
@@ -141,14 +144,14 @@ class EndToEndTest : public ::testing::Test {
141144
webrtc::test::RunLoop loop_;
142145
};
143146

144-
// TEST_F(EndToEndTest, SendMessgeCanBeReceived) {
145-
// task_queue_->PostTask([this] {
146-
// client1_->Send("client2", "message", nullptr, nullptr);
147-
// EXPECT_CALL(observer2_, OnMessageReceived("client1", testing::_))
148-
// .WillOnce(testing::InvokeWithoutArgs([this] { loop_.Quit(); }));
149-
// });
150-
// loop_.Run();
151-
// }
147+
TEST_F(EndToEndTest, SendMessgeCanBeReceived) {
148+
task_queue_->PostTask([this] {
149+
client1_->Send("client2", "message", nullptr, nullptr);
150+
EXPECT_CALL(observer2_, OnMessageReceived("client1", testing::_))
151+
.WillOnce(testing::InvokeWithoutArgs([this] { loop_.Quit(); }));
152+
});
153+
loop_.Run();
154+
}
152155

153156
rtc::scoped_refptr<MediaStreamInterface> CreateFakeMediaStream() {
154157
auto* pcdf = owt::base::PeerConnectionDependencyFactory::Get();
@@ -185,6 +188,21 @@ TEST_F(EndToEndTest, VideoCall) {
185188
});
186189
loop_.Run();
187190
}
191+
192+
TEST_F(EndToEndTest, OnPeerConnectionClosed) {
193+
task_queue_->PostTask([this] {
194+
client1_->Send("client2", "message", nullptr, nullptr);
195+
EXPECT_CALL(observer2_, OnMessageReceived("client1", testing::_))
196+
.WillOnce(testing::InvokeWithoutArgs([this] { loop_.Quit(); }));
197+
});
198+
loop_.Run();
199+
task_queue_->PostTask([this] {
200+
client1_->Stop("client2", nullptr, nullptr);
201+
EXPECT_CALL(observer2_, OnPeerConnectionClosed("client1"))
202+
.WillOnce(testing::InvokeWithoutArgs([this] { loop_.Quit(); }));
203+
});
204+
loop_.Run();
205+
}
188206
} // namespace test
189207
} // namespace p2p
190208
} // namespace owt

0 commit comments

Comments
 (0)