FlashChat
Engineering · WebRTC · Networking

Why video calls fail on Indian mobile networks, and how we fixed it

A browser video call is supposed to connect two phones directly. On many Indian mobile networks it cannot, because of how carriers share public addresses. This is how FlashChat gets calls through anyway: the order it tries connection paths, how it survives a network switch mid-call, and how we know every path is working before a user finds out it is not.

3connection paths tried in order: direct, our relay, a backup relay
3relay transports: UDP, TCP and TLS, for networks that block one
10 minbetween real test connections to every relay
1automatic reconnect per call when the network changes
0calls that start without both people accepting
On this page
  1. Summary
  2. The NAT problem
  3. Three paths, in order
  4. Call setup
  5. Camera and media
  6. Surviving a network switch
  7. Knowing it works
  8. On-device filters
  9. Lessons
  10. FAQ

00Summary

TL;DR

  • Carrier-grade NAT on mobile networks often stops two phones from connecting directly, so a call needs a relay (a TURN server).
  • FlashChat tries direct first, then our own relay, then a backup relay network, and offers each relay over UDP, TCP and TLS so a network that blocks one transport still gets through.
  • Relay credentials are short-lived and minted per request, fetched as soon as two people are matched so pressing “call” is instant.
  • When a phone switches networks mid-call, the call restarts its connection search without hanging up.
  • Every relay is tested with a real connection every 10 minutes, and every certificate is checked from the network, so a broken path is found by us first.

01The NAT problem

WebRTC, the standard behind browser video calls, is designed to be peer-to-peer: once the call is set up, video flows directly between the two devices. To do that, each device needs an address the other can reach.

Home broadband usually gives a router one public address, and a technique called STUN lets a device learn its public address and port so the other side can send to it. Mobile networks are different. To stretch scarce IPv4 addresses, carriers put very large numbers of phones behind a shared public address, known as carrier-grade NAT. Many of these NATs give a different external port for every destination, which makes the address learned through STUN useless to anyone else. Two phones on such networks often cannot reach each other at all.

The standard answer is TURN: a relay server both phones can reach, which forwards the media between them. The cost is that relayed video travels through a server, so relays have to be close to users and carry real bandwidth.

Why this matters in India. Most of our users are on mobile data, often with a phone hotspot or a congested tower in between. A call stack that only works on home Wi-Fi does not work for most of our users.

02Three paths, in order

How a call finds its route

The browser tests all candidate routes in parallel and keeps the best one that works.

First choice
Direct

Same network, or public addresses found via STUN. Lowest delay, no server in the middle.

Second choice
Our relay

A TURN server we run in India, offered over UDP, TCP and TLS.

Backup
Relay network

A large third-party relay network, used when our relay cannot be reached.

Browsers rank a relay higher the earlier its server appears in the list they are given, so the order of the list is the policy.
  • Three transports per relay. Some networks (offices, colleges, some hotspots) block UDP or anything that is not ordinary HTTPS. Offering the relay over UDP, TCP and TLS means at least one usually gets through.
  • A lighter profile on relayed legs. A call leg that runs through our own relay is sent at a lower video resolution and bitrate. Direct calls are not affected, and the quality difference on a phone screen is small.
  • The route is recorded, not guessed. A few seconds after a call connects, each side reports which kind of path it ended up on (local network, direct over the internet, our relay over each transport, or the backup network). That is how we know which paths actually matter.

03Call setup

Every FlashChat conversation starts as text. A call is an offer the other person must accept.

  1. One person taps the call button; the server relays a request to the partner, who sees a ring and accepts or declines.
  2. On accept, the caller creates the connection, opens the camera and sends an offer describing its media; the callee answers.
  3. Both sides exchange candidates (possible routes) through the server, and the browsers test them.

Two details keep this robust. Candidates can arrive before the offer or answer they belong to, so they are buffered (with a cap) and applied once the description is set; the same goes for an offer that arrives before the callee’s connection exists. And the server’s role is only to relay these messages between the two partners in a chat, after checking their shape; it never sees the media.

Credentials that expire

  • Minted per request. Relay usernames and passwords are generated by the server from a shared secret and a timestamp, so they expire on their own and are never stored in the app.
  • Fetched early. The app fetches credentials the moment two people are matched, so tapping “call” does not wait on a network round trip.
  • Bounded waits. Fetches time out after a few seconds and retry once on a temporary failure. Simultaneous requests share one in-flight fetch.
  • Honest failure. If no relay is available, the app says calls cannot connect right now before asking for camera permission, rather than failing silently after.

04Camera and media

  • A fallback chain for the camera. Phones try the requested camera and resolution, then any camera, then audio only. Desktop browsers never ask for a front or back camera, because many laptop webcams reject the request outright.
  • Modest resolution on purpose. Video is captured at a resolution and frame rate chosen for phone screens and mobile data, not for a large monitor.
  • A more efficient codec when available. The app prefers a modern video codec that needs noticeably less bandwidth for the same picture, and falls back silently when a browser does not support choosing.
  • Remote video that fits. On a landscape laptop screen the partner’s portrait video is shown whole with side bars, not zoomed until only a nose is visible.

05Surviving a network switch

Walking out of the house moves a phone from Wi-Fi to mobile data, which changes its address and breaks the route the call was using. Without help, the call freezes and eventually fails.

  1. The app watches the connection state. When it becomes disconnected, a temporary state, it immediately restarts the route search (an ICE restart) and sends a fresh offer.
  2. A short watchdog waits for the new route. The person sees a “Reconnecting” card instead of a frozen frame.
  3. Only one automatic restart is attempted per call. If the network is truly gone, a second restart would only delay telling the person.
  4. If the connection reaches failed anyway, a short debounce ends the call cleanly.

Group calls in private rooms use the same handling per participant, since each person in a group call has their own connection to every other.

Small signals that make calls feel solid

  • A data channel between the two phones carries mute, camera-off and away states, so the other side shows “camera off” instead of a black frame.
  • Connection statistics drive “your connection is weak” and “their connection is weak” notices, each side judging only what it sends.
  • A “you’re muted” hint appears if you start talking while muted, measured locally and never sent.
  • The screen stays awake during a call, and picture-in-picture keeps the call visible while you check another app.

06Knowing it works

A relay that stops working fails silently: calls on good networks still connect directly, and only the people who needed the relay are affected, usually without telling anyone. So we test the paths ourselves.

Every 10 minutesReal relay connections

A probe performs a real relay allocation (challenge, authentication, release) on every relay and every transport, plus an address lookup on each STUN server. Two failures in a row alert the team.

Every few hoursCertificates from the wire

Every TLS certificate is read from the network, not from disk, with warnings weeks, days and hours before expiry.

Every callOutcomes, not just starts

Requests, accepts, connections, the path each side used, and failures by reason (timed out, failed, dropped, no relay available) are counted daily.

On demandSelf-tests

An admin page runs the relay and certificate checks immediately, for after a change or when someone reports a problem.

07On-device filters

People on an anonymous platform often want to talk without showing their face or their room. FlashChat’s call filters run entirely on the phone, before the video is sent:

  • Hide face uses a small model trained to locate faces in each frame and blurs them. If no face has been seen recently, or the model has not loaded, it blurs the whole frame instead.
  • Hide room and portrait use a model trained to separate a person from the background.
  • Both models run in a background worker. The first run compiles GPU programs and can take many seconds on a cold browser cache; on the main thread that froze the call.
  • Privacy looks never fall back to the raw camera. If a hide look cannot start, the video pauses with a notice. Every path that swaps tracks (camera flip, starting a call mid-setup, closing the picker) was checked so the bare face never reaches the other side.
  • A preview before joining lets people pick a look before any video is sent.

One cross-browser surprise: a common canvas filtering feature is accepted but silently ignored by the browser engine every iPhone browser uses, so every filter was a no-op on iPhones until we rebuilt them from drawing and blending operations that work everywhere.

08Lessons

  • Test the path, not the port. A relay port that answers is not a relay that works. Our probes perform the full authenticated allocation a browser would.
  • A renewed certificate is not a loaded one. Our relay’s certificate was renewed on disk, but the relay only reads it at start-up, so the certificate on the wire expired. Renewals now restart the relay, and the certificate check reads what the network actually serves.
  • Count the call, not the click. “Calls started” looked healthy while calls on some networks never connected. Outcome and path counts are what showed the gap.
  • Fail before the permission prompt. Asking for the camera and then failing is worse than telling people up front that calls cannot connect right now.
  • Treat every browser as a different platform. Desktop webcams, iPhone canvas behaviour and background-tab rules on Android each broke something that worked elsewhere.

For the rest of the system, see how FlashChat is built. For what calls look like from the user side, see the random video chat guide.

09Frequently asked questions

Why do video calls fail on some mobile networks?

Many mobile networks put thousands of phones behind one shared public address (carrier-grade NAT). Two phones behind that kind of NAT often cannot reach each other directly, so the call needs a relay server in the middle.

Does a FlashChat video call start without my permission?

No. Every chat starts as text. Either person can offer a video or voice call, and it starts only if the other person accepts.

What happens if I switch from Wi-Fi to mobile data during a call?

The call notices the network change, looks for a new route and reconnects without hanging up. You see a short Reconnecting notice while it does.

Are video filters applied on my phone?

Yes. Face blur, background blur and other looks run on your device before the video is sent. The other person only receives the filtered video.