0

目前,我有一个点击事件,当点击一个按钮时运行 Boomerang 带宽指标,但我有一个问题,它只会在第一次运行,直到我刷新我的页面。它无法多次运行,还是我错过了什么?

我只想记录网络指标,没有别的。

这是 REPO/文档的链接: https ://akamai.github.io/boomerang/BOOMR.plugins.BW.html

这是点击事件:

$('#boomerangTest').on('click', function (event) {
        debugger
        //var pathname = window.location.pathname;
        //var url = window.location.href;
        //var origin = window.location.origin;
        //var imageURL = origin + '';

        var loc = window.location.pathname;
        var dir = loc.substring(0, loc.lastIndexOf('/'));
        var imageURL = dir + "/assets/images/boomr/"

        var data = {
            UserName: cb.Win.FindHandleID('#spanUserName').html().replace('Logged in as: ', '')
        };

        data.UserName = data.UserName.substr(0, data.UserName.indexOf('(')).trim();

        if (data.UserName === '') {
            cb.Win.ErrDialog('Network Metrics', 'Please Login before running a network test');
        }
        else {
            $('#main_content').cbAjaxLoader('big');
            BOOMR.init({
                beacon_url: '',
                 BW: {
                     base_url: imageURL,
                     block_beacon: true,
                     cookie: "AK_BW"
                 },
                 RT: {
                     enabled: true,
                     clearOnBeacon: true
                 }
             });

            BOOMR.subscribe('before_beacon', function (o) {
                debugger
                var html = "",
                    t_name,
                    t_other,
                    others = [],
                    bandwidthMetrics = {};

                if (!o.t_other) o.t_other = "";

                for (var k in o) {
                    if (!k.match(/^(t_done|t_other|bw|lat|bw_err|lat_err|u|r2?)$/)) {
                        if (k.match(/^t_/)) {
                            o.t_other += "," + k + "|" + o[k];
                        }
                        else {
                            others.push(k + " = " + o[k]);
                        }
                    }
                }

                if (o.t_done) {
                    html += "This page took " + o.t_done + " ms to load<br>";
                    bandwidthMetrics.LoadDuration = o.t_done;
                }

                if (o.bw) {
                    html += "Your bandwidth to this server is " + parseInt(o.bw / 1024) + " kbps (&#x00b1;" + parseInt(o.bw_err * 100 / o.bw) + "%)<br>";
                    bandwidthMetrics.DownSpeed = parseInt(o.bw / 1024);
                }

                if (o.lat) {
                    html += "Your latency to this server is " + parseInt(o.lat) + " ms (&#x00b1;" + parseInt(o.lat_err * 100 / o.lat) + "%)<br>";
                    bandwidthMetrics.Latency = parseInt(o.lat);
                }

                cb.Win.ErrDialog('Network Metric Results', html, 'main_content');
                $('#main_content').cbAjaxLoaderRemove();

            });

            $('#main_content').cbAjaxLoaderRemove();
        }
    });
4

1 回答 1

0

Boomerang 将结果存储在 cookie 中,7 天内不会在同一网络上重新运行测试。如果您需要它来重新运行测试,请禁用 BW cookie。

请注意,boomerang 团队很少监控 Stackoverflow,您可以通过直接发布到 github 问题列表来获得更快的响应。

于 2020-09-18T17:25:21.207 回答