Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
QT-9589: Added Web socket check in test-rtc
Browse files Browse the repository at this point in the history
  • Loading branch information
HiteshMishra22 committed Feb 2, 2024
1 parent 2913570 commit 5198fb7
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"arrayMax": true,
"arrayMin": true,
"TURN_URL": true,
"WEBSOCKET_URL": true,
"Ssim": true,
"VideoFrameChecker": true,
"StatisticsAggregate": true,
Expand Down
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ module.exports = function(grunt) {
compress: {
global_defs: {
'API_KEY': process.env.API_KEY,
'TURN_URL': 'https://test-api.pod.ai/api/external/testrtc/turn-credentials/'
'TURN_URL': 'https://test-api.pod.ai/api/external/testrtc/turn-credentials/',
'WEBSOCKET_URL': 'wss://test-api.pod.ai/api/web-socket-session/',
},
dead_code: true,
},
Expand Down
4 changes: 4 additions & 0 deletions src/js/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ Call.isHost = function(candidate) {
return candidate.type === 'host';
};

Call.isWebSocket = function(candidate) {
return candidate.type === 'web socket';
};

Call.isIpv6 = function(candidate) {
return candidate.address.indexOf(':') !== -1;
};
Expand Down
42 changes: 42 additions & 0 deletions src/js/conntest.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ addTest(
runConnectivityTest.start();
});

// Set up a websocket connection between two peers and verify data can be
// transmitted and received
addTest(
testSuiteName.CONNECTIVITY, testCaseName.WEBSOCKETCONNECTIVITY,
function(test) {
var runConnectivityTest = new RunConnectivityTest(test, Call.isWebSocket);
runConnectivityTest.checkWSConnection();
});

function RunConnectivityTest(test, iceCandidateFilter) {
this.test = test;
this.iceCandidateFilter = iceCandidateFilter;
Expand Down Expand Up @@ -94,6 +103,39 @@ RunConnectivityTest.prototype = {
this.timeout = setTimeout(this.hangup.bind(this, 'Timed out'), 5000);
},

// It creates a websocket connection with backnd server and check that data
// can be sent and received successfully
checkWSConnection: function(config) {
this.call = new Call(config, this.test);
this.call.setIceCandidateFilter(this.iceCandidateFilter);

this.timeout = setTimeout(
this.hangup.bind(this,'Websocket connection timed out'),
5000
);
var socket = new WebSocket(WEBSOCKET_URL);

socket.addEventListener('open', function() {
socket.send('ping');
});

socket.addEventListener('error', function() {
socket.close();
this.hangup('Web socket connection error');
}.bind(this));

socket.addEventListener('message', function(event) {
var receivedMessage = event.data;
if (receivedMessage === 'pong') {
this.test.reportSuccess('Data transmitted successfully');
} else {
this.test.reportError('Invalid data received.');
}
socket.close();
this.hangup();
}.bind(this));
},

findParsedCandidateOfSpecifiedType: function(candidateTypeMethod) {
for (var candidate in this.parsedCandidates) {
if (candidateTypeMethod(this.parsedCandidates[candidate])) {
Expand Down
3 changes: 2 additions & 1 deletion src/js/testcasename.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ function TestCaseNames() {
VIDEOBANDWIDTH: 'Video bandwidth',
RELAYCONNECTIVITY: 'Relay connectivity',
REFLEXIVECONNECTIVITY: 'Reflexive connectivity',
HOSTCONNECTIVITY: 'Host connectivity'
HOSTCONNECTIVITY: 'Host connectivity',
WEBSOCKETCONNECTIVITY: 'Web socket connectivity'
};
return this.testCases;
}
Expand Down

0 comments on commit 5198fb7

Please sign in to comment.