mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-30 19:09:38 +00:00
Added signaling state to tests
This commit is contained in:
@ -34,6 +34,7 @@ static void sleep(unsigned int secs) { Sleep(secs * 1000); }
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
rtcState state;
|
rtcState state;
|
||||||
rtcGatheringState gatheringState;
|
rtcGatheringState gatheringState;
|
||||||
|
rtcSignalingState signalingState;
|
||||||
int pc;
|
int pc;
|
||||||
int dc;
|
int dc;
|
||||||
bool connected;
|
bool connected;
|
||||||
@ -68,6 +69,12 @@ static void gatheringStateCallback(int pc, rtcGatheringState state, void *ptr) {
|
|||||||
printf("Gathering state %d: %d\n", peer == peer1 ? 1 : 2, (int)state);
|
printf("Gathering state %d: %d\n", peer == peer1 ? 1 : 2, (int)state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void signalingStateCallback(int pc, rtcSignalingState state, void *ptr) {
|
||||||
|
Peer *peer = (Peer *)ptr;
|
||||||
|
peer->signalingState = state;
|
||||||
|
printf("Signaling state %d: %d\n", peer == peer1 ? 1 : 2, (int)state);
|
||||||
|
}
|
||||||
|
|
||||||
static void openCallback(int id, void *ptr) {
|
static void openCallback(int id, void *ptr) {
|
||||||
Peer *peer = (Peer *)ptr;
|
Peer *peer = (Peer *)ptr;
|
||||||
peer->connected = true;
|
peer->connected = true;
|
||||||
@ -180,6 +187,12 @@ int test_capi_connectivity_main() {
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (peer1->signalingState != RTC_SIGNALING_STABLE ||
|
||||||
|
peer2->signalingState != RTC_SIGNALING_STABLE) {
|
||||||
|
fprintf(stderr, "Signaling state is not stable\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (!peer1->connected || !peer2->connected) {
|
if (!peer1->connected || !peer2->connected) {
|
||||||
fprintf(stderr, "DataChannel is not connected\n");
|
fprintf(stderr, "DataChannel is not connected\n");
|
||||||
goto error;
|
goto error;
|
||||||
@ -236,7 +249,6 @@ int test_capi_connectivity_main() {
|
|||||||
}
|
}
|
||||||
printf("Remote address 2: %s\n", buffer);
|
printf("Remote address 2: %s\n", buffer);
|
||||||
|
|
||||||
|
|
||||||
if (rtcGetSelectedCandidatePair(peer1->pc, buffer, BUFFER_SIZE, buffer2, BUFFER_SIZE) < 0) {
|
if (rtcGetSelectedCandidatePair(peer1->pc, buffer, BUFFER_SIZE, buffer2, BUFFER_SIZE) < 0) {
|
||||||
fprintf(stderr, "rtcGetSelectedCandidatePair failed\n");
|
fprintf(stderr, "rtcGetSelectedCandidatePair failed\n");
|
||||||
goto error;
|
goto error;
|
||||||
@ -251,7 +263,6 @@ int test_capi_connectivity_main() {
|
|||||||
printf("Local candidate 2: %s\n", buffer);
|
printf("Local candidate 2: %s\n", buffer);
|
||||||
printf("Remote candidate 2: %s\n", buffer2);
|
printf("Remote candidate 2: %s\n", buffer2);
|
||||||
|
|
||||||
|
|
||||||
deletePeer(peer1);
|
deletePeer(peer1);
|
||||||
sleep(1);
|
sleep(1);
|
||||||
deletePeer(peer2);
|
deletePeer(peer2);
|
||||||
|
@ -69,6 +69,10 @@ void test_connectivity() {
|
|||||||
cout << "Gathering state 1: " << state << endl;
|
cout << "Gathering state 1: " << state << endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pc1->onSignalingStateChange([](PeerConnection::SignalingState state) {
|
||||||
|
cout << "Signaling state 1: " << state << endl;
|
||||||
|
});
|
||||||
|
|
||||||
pc2->onLocalDescription([wpc1 = make_weak_ptr(pc1)](Description sdp) {
|
pc2->onLocalDescription([wpc1 = make_weak_ptr(pc1)](Description sdp) {
|
||||||
auto pc1 = wpc1.lock();
|
auto pc1 = wpc1.lock();
|
||||||
if (!pc1)
|
if (!pc1)
|
||||||
@ -91,6 +95,10 @@ void test_connectivity() {
|
|||||||
cout << "Gathering state 2: " << state << endl;
|
cout << "Gathering state 2: " << state << endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pc2->onSignalingStateChange([](PeerConnection::SignalingState state) {
|
||||||
|
cout << "Signaling state 2: " << state << endl;
|
||||||
|
});
|
||||||
|
|
||||||
shared_ptr<DataChannel> dc2;
|
shared_ptr<DataChannel> dc2;
|
||||||
pc2->onDataChannel([&dc2](shared_ptr<DataChannel> dc) {
|
pc2->onDataChannel([&dc2](shared_ptr<DataChannel> dc) {
|
||||||
cout << "DataChannel 2: Received with label \"" << dc->label() << "\"" << endl;
|
cout << "DataChannel 2: Received with label \"" << dc->label() << "\"" << endl;
|
||||||
|
Reference in New Issue
Block a user