|
1 | 1 | import { WebRTCAdaptor } from '../../main/js/webrtc_adaptor.js'; |
2 | 2 | import { MediaManager } from "../../main/js/media_manager.js"; |
3 | 3 | import { PeerStats } from "../../main/js/peer_stats.js"; |
| 4 | +import { WebSocketAdaptor } from '../../main/js/websocket_adaptor.js'; |
4 | 5 |
|
| 6 | +// Add this before the ICE ServerConfig debug logging test to mock Logger |
| 7 | +window.Logger = { debug: () => {} }; |
5 | 8 |
|
6 | 9 | describe("WebRTCAdaptor", function() { |
7 | 10 |
|
@@ -2104,3 +2107,108 @@ describe("WebRTCAdaptor", function() { |
2104 | 2107 |
|
2105 | 2108 |
|
2106 | 2109 | }); |
| 2110 | + |
| 2111 | +describe("ICE Server Configuration", function() { |
| 2112 | + it("should set userDefinedIceServers to true if peerconnection_config is provided", function() { |
| 2113 | + const adaptor = new WebRTCAdaptor({ |
| 2114 | + websocketURL: "ws://example.com", |
| 2115 | + peerconnection_config: { iceServers: [{ urls: "stun:custom" }] }, |
| 2116 | + initializeComponents: false |
| 2117 | + }); |
| 2118 | + expect(adaptor.userDefinedIceServers).to.be.true; |
| 2119 | + |
| 2120 | + const adaptor2 = new WebRTCAdaptor({ |
| 2121 | + websocketURL: "ws://example.com", |
| 2122 | + peerconnection_config: { sdpSemantics: 'unified-plan' }, |
| 2123 | + initializeComponents: false |
| 2124 | + }); |
| 2125 | + expect(adaptor2.userDefinedIceServers).to.be.false; |
| 2126 | + }); |
| 2127 | + |
| 2128 | + it("should set userDefinedIceServers to false if peerconnection_config is not provided", function() { |
| 2129 | + const adaptor = new WebRTCAdaptor({ |
| 2130 | + websocketURL: "ws://example.com", |
| 2131 | + initializeComponents: false |
| 2132 | + }); |
| 2133 | + expect(adaptor.userDefinedIceServers).to.be.false; |
| 2134 | + }); |
| 2135 | + |
| 2136 | + it("getIceServerConfiguration should send getIceServerConfig if userDefinedIceServers is false", function() { |
| 2137 | + const adaptor = new WebRTCAdaptor({ |
| 2138 | + websocketURL: "ws://example.com", |
| 2139 | + initializeComponents: false |
| 2140 | + }); |
| 2141 | + adaptor.userDefinedIceServers = false; |
| 2142 | + adaptor.webSocketAdaptor = { send: sinon.fake() }; |
| 2143 | + adaptor.getIceServerConfiguration(); |
| 2144 | + expect(adaptor.webSocketAdaptor.send.calledOnce).to.be.true; |
| 2145 | + const sentArg = JSON.parse(adaptor.webSocketAdaptor.send.firstCall.args[0]); |
| 2146 | + expect(sentArg.command).to.equal("getIceServerConfig"); |
| 2147 | + }); |
| 2148 | + |
| 2149 | + it("getIceServerConfiguration should NOT send getIceServerConfig if userDefinedIceServers is true", function() { |
| 2150 | + const adaptor = new WebRTCAdaptor({ |
| 2151 | + websocketURL: "ws://example.com", |
| 2152 | + initializeComponents: false |
| 2153 | + }); |
| 2154 | + adaptor.userDefinedIceServers = true; |
| 2155 | + adaptor.webSocketAdaptor = { send: sinon.fake() }; |
| 2156 | + adaptor.getIceServerConfiguration(); |
| 2157 | + expect(adaptor.webSocketAdaptor.send.called).to.be.false; |
| 2158 | + }); |
| 2159 | +}); |
| 2160 | + |
| 2161 | +describe("WebSocketAdaptor ICE ServerConfig Integration", function() { |
| 2162 | + let originalLogger; |
| 2163 | + let originalLog; |
| 2164 | + before(function() { |
| 2165 | + // Save and mock Logger and log for debug test |
| 2166 | + originalLogger = window.Logger; |
| 2167 | + originalLog = window.log; |
| 2168 | + window.log = { debug: () => {} }; |
| 2169 | + window.Logger = window.log; |
| 2170 | + }); |
| 2171 | + after(function() { |
| 2172 | + window.Logger = originalLogger; |
| 2173 | + window.log = originalLog; |
| 2174 | + }); |
| 2175 | + |
| 2176 | + it("should update peerconnection_config.iceServers for TURN server via real onmessage", function() { |
| 2177 | + const adaptor = { peerconnection_config: { iceServers: [] } }; |
| 2178 | + const wsAdaptor = new WebSocketAdaptor({ websocket_url: "ws://example.com", webrtcadaptor: adaptor }); |
| 2179 | + wsAdaptor.debug = false; |
| 2180 | + wsAdaptor.wsConn = {}; |
| 2181 | + wsAdaptor.initWebSocketConnection(); |
| 2182 | + const event = { |
| 2183 | + data: JSON.stringify({ |
| 2184 | + command: "iceServerConfig", |
| 2185 | + stunServerUri: "turn:turn.example.com", |
| 2186 | + turnServerUsername: "user", |
| 2187 | + turnServerCredential: "pass" |
| 2188 | + }) |
| 2189 | + }; |
| 2190 | + wsAdaptor.wsConn.onmessage(event); |
| 2191 | + expect(adaptor.peerconnection_config.iceServers.length).to.equal(2); |
| 2192 | + expect(adaptor.peerconnection_config.iceServers[1].urls).to.equal("turn:turn.example.com"); |
| 2193 | + expect(adaptor.peerconnection_config.iceServers[1].username).to.equal("user"); |
| 2194 | + expect(adaptor.peerconnection_config.iceServers[1].credential).to.equal("pass"); |
| 2195 | + }); |
| 2196 | + |
| 2197 | + it("should update peerconnection_config.iceServers for STUN server via real onmessage", function() { |
| 2198 | + const adaptor = { peerconnection_config: { iceServers: [] } }; |
| 2199 | + const wsAdaptor = new WebSocketAdaptor({ websocket_url: "ws://example.com", webrtcadaptor: adaptor }); |
| 2200 | + wsAdaptor.debug = false; |
| 2201 | + wsAdaptor.wsConn = {}; |
| 2202 | + wsAdaptor.initWebSocketConnection(); |
| 2203 | + const event = { |
| 2204 | + data: JSON.stringify({ |
| 2205 | + command: "iceServerConfig", |
| 2206 | + stunServerUri: "stun:stun.example.com" |
| 2207 | + }) |
| 2208 | + }; |
| 2209 | + wsAdaptor.wsConn.onmessage(event); |
| 2210 | + expect(adaptor.peerconnection_config.iceServers.length).to.equal(1); |
| 2211 | + expect(adaptor.peerconnection_config.iceServers[0].urls).to.equal("stun:stun.example.com"); |
| 2212 | + }); |
| 2213 | + |
| 2214 | +}); |
0 commit comments