Skip to content

Conversation

@RafaelPChequer
Copy link
Contributor

Description

Introduced a simple demo/test harness for verifying the v2 WebRTC restartIce() capability in the SDK. This web-based application enables inbound and outbound calls with audio/video options, includes a dedicated "Restart ICE" button to trigger ICE restarts during active calls, and supports token generation for authentication. The harness facilitates straightforward testing of ICE restart behavior, helping validate solutions for connectivity issues in network-dependent scenarios like TURN connections or session recovery.

Type of change

  • Internal refactoring
  • Bug fix (bugfix - non-breaking)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Code snippets

In case of new feature or breaking changes, please include code snippets.

// Function to restart ICE on the current call
function restartIceCall() {
  if (currentCall) {
    currentCall.peer.instance.restartIce();
    console.log("restartIce called");
  }
}
<!-- Button to trigger ICE restart -->
<button id="restartIce" class="btn btn-warning px-5 mt-4 d-none" onClick="restartIceCall()" disabled="true">Restart ICE</button>
// Handling call state updates to show/hide Restart ICE button
function handleCallUpdate(call) {
  currentCall = call;
  // ... (other state handling)
  switch (call.state) {
    case 'active': // Call has become active
      // ... (other UI updates)
      restartIce.classList.remove('d-none');
      restartIce.disabled = false;
      break;
    case 'hangup': // Call is over
      // ... (other UI updates)
      restartIce.classList.add('d-none');
      restartIce.disabled = true;
      break;
    case 'destroy': // Call has been destroyed
      // ... (other UI updates)
      restartIce.classList.add('d-none');
      restartIce.disabled = true;
      break;
    // ... (other cases)
  }
}
// Token generation for inbound call support
async function generateToken() {
  let spaceVal = document.getElementById('space').value.trim();
  const projectVal = document.getElementById('project').value.trim();
  const apiTokenVal = document.getElementById('apiToken').value.trim();
  const expiresInVal = document.getElementById('expiresIn').value;
  const resourceVal = document.getElementById('resource').value.trim();
  // ... (input validation and cleaning)
  const url = `https://${spaceVal}.signalwire.com/api/relay/rest/jwt`;
  const body = {
    expires_in: parseInt(expiresInVal),
    resource: resourceVal
  };
  const auth = btoa(`${projectVal}:${apiTokenVal}`);
  try {
    const response = await fetch(url, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Basic ${auth}`
      },
      body: JSON.stringify(body)
    });
    // ... (response handling and token population)
  } catch (error) {
    // ... (error handling)
  }
}

@RafaelPChequer RafaelPChequer self-assigned this Oct 29, 2025
@giavac
Copy link
Contributor

giavac commented Oct 30, 2025

Thanks @RafaelPChequer - can you please add a README inside the new folder, with instructions on how to configure and run?

@giavac
Copy link
Contributor

giavac commented Oct 30, 2025

If I run it on my machine with

python3 -m http.server 8080

when I try to generate a token I see:

dev.swire.io.signalw…pi/relay/rest/jwt:1 
 Failed to load resource: net::ERR_CERT_COMMON_NAME_INVALID
(index):229 Error generating token: TypeError: Failed to fetch
    at generateToken ((index):213:40)
    at HTMLButtonElement.onclick ((index):59:108)

If I create a JWT token separately and enter it, I get:

(index):270 SignalWire error: {code: -32002, message: 'Authentication service failed with status 401 Unauthorized: {}', original_request: {…}}

@giavac
Copy link
Contributor

giavac commented Oct 30, 2025

Left a couple of comments.

In addition, can you consider adding a text box in the page to show some important logging information? The purpose is to provide better feedback to the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants