From 5198fb709f31031822724bb309fe178d712c5a8b Mon Sep 17 00:00:00 2001 From: Hitesh Mishra Date: Fri, 2 Feb 2024 11:32:34 +0530 Subject: [PATCH] QT-9589: Added Web socket check in test-rtc --- .eslintrc | 1 + Gruntfile.js | 3 ++- src/js/call.js | 4 ++++ src/js/conntest.js | 42 ++++++++++++++++++++++++++++++++++++++++++ src/js/testcasename.js | 3 ++- 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index 3d8418e4..03748986 100644 --- a/.eslintrc +++ b/.eslintrc @@ -65,6 +65,7 @@ "arrayMax": true, "arrayMin": true, "TURN_URL": true, + "WEBSOCKET_URL": true, "Ssim": true, "VideoFrameChecker": true, "StatisticsAggregate": true, diff --git a/Gruntfile.js b/Gruntfile.js index 1aed858a..020bdbfc 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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, }, diff --git a/src/js/call.js b/src/js/call.js index 66114c5c..f1c7e100 100644 --- a/src/js/call.js +++ b/src/js/call.js @@ -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; }; diff --git a/src/js/conntest.js b/src/js/conntest.js index 0ce89b9e..5da1018a 100644 --- a/src/js/conntest.js +++ b/src/js/conntest.js @@ -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; @@ -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])) { diff --git a/src/js/testcasename.js b/src/js/testcasename.js index fbbb07be..d84ed787 100644 --- a/src/js/testcasename.js +++ b/src/js/testcasename.js @@ -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; }