Repository: syncthing/syncthing
File: gui/default/syncthing/core/syncthingController.js (JavaScript)

Code before:
                    data.total.outbps = Math.max(0, (data.total.outBytesTotal - $scope.connectionsTotal.outBytesTotal) / td);
                } catch (e) {
                    data.total.inbps = 0;
                    data.total.outbps = 0;
                }
                $scope.connectionsTotal = data.total;

                data = data.connections;
                var currentAddresses = [];
                for (id in data) {
                    if (!data.hasOwnProperty(id)) {
                        continue;
                    }
                    if (!(id in $scope.devices)) {
                        // Avoid errors when called before first updateLocalConfig()
                        continue;
                    }
                    if (!(id in $scope.idToRemoteGUI)) {
                        $scope.idToRemoteGUI[id] = "";
                    }
                    var port = $scope.devices[id].remoteGUIPort;
                    var isNotRelayConnection = !data[id].type.includes("relay");
                    if ($scope.showRemoteGUI && data[id].address != "" && isNotRelayConnection && port > 0) {
                        var newAddress = "http://" + replaceAddressPort(data[id].address, port);
                        currentAddresses.push(newAddress);
                        if (!(newAddress in $scope.remoteGUICache)) {
                            // No cached result, trigger a new port probing asynchronously
                            $scope.probeRemoteGUIAddress(id, newAddress);
                        }
                    }
                    try {
                        data[id].inbps = Math.max(0, (data[id].inBytesTotal - $scope.connections[id].inBytesTotal) / td);
                        data[id].outbps = Math.max(0, (data[id].outBytesTotal - $scope.connections[id].outBytesTotal) / td);
                    } catch (e) {
                        data[id].inbps = 0;
                        data[id].outbps = 0;
                    }
                }
                // Clean out stale addresses from probing results
                for (var address in $scope.remoteGUICache) {
                    if (!currentAddresses.includes(address)) {
                        delete $scope.remoteGUICache[address];
                    }
                }
                $scope.connections = data;
                console.log("refreshConnections", data);
            }).error($scope.emitHTTPError);
        }

        function refreshErrors() {
            $http.get(urlbase + '/system/error').success(function (data) {

Review comment (suggestion):
While it won't ever work for both devices, it's possible that two devices behind the same NAT, thus same IP, and are both configured with 8384. Then the result of the existing lookup should be applied to `idToRemoteGUI`.

Code after:
                    data.total.outbps = Math.max(0, (data.total.outBytesTotal - $scope.connectionsTotal.outBytesTotal) / td);
                } catch (e) {
                    data.total.inbps = 0;
                    data.total.outbps = 0;
                }
                $scope.connectionsTotal = data.total;

                data = data.connections;
                for (id in data) {
                    if (!data.hasOwnProperty(id)) {
                        continue;
                    }
                    try {
                        data[id].inbps = Math.max(0, (data[id].inBytesTotal - $scope.connections[id].inBytesTotal) / td);
                        data[id].outbps = Math.max(0, (data[id].outBytesTotal - $scope.connections[id].outBytesTotal) / td);
                    } catch (e) {
                        data[id].inbps = 0;
                        data[id].outbps = 0;
                    }
                }
                $scope.connections = data;
                console.log("refreshConnections", data);

                refreshRemoteGUI(data);
            }).error($scope.emitHTTPError);
        }

        function refreshRemoteGUI(connections) {
            if (!$scope.showRemoteGUI) {
                $scope.idToRemoteGUI = {}
                return
            }
            var newCache = {};
            for (var id in connections) {
                if (!(id in $scope.devices)) {
                    // Avoid errors when called before first updateLocalConfig()
                    continue;
                }
                var port = $scope.devices[id].remoteGUIPort;
                if (port <= 0
                    || !connections[id].address
                    || connections[id].type.includes("relay")) {
                    // Relay connections never work as desired here, nor incomplete addresses
                    $scope.idToRemoteGUI[id] = "";
                    continue;
                }
                var newAddress = "http://" + replaceAddressPort(connections[id].address, port);
                if (!(newAddress in $scope.remoteGUICache)) {
                    // No cached result, trigger a new port probing asynchronously
                    $scope.probeRemoteGUIAddress(id, newAddress);
                } else {