传递给JS客户端reconnectionStrategy的原因不明的参数

Joh*_*wby 5 push-diffusion

我正在研究Diffusion JS API的一些代码示例,但我不了解重新连接的示例.reconnectionStrategy有哪些start和哪些abort参数?

// Create a reconnection strategy that applies an exponential back-off
var reconnectionStrategy = (function() {
    return function(start, abort) {
        var wait = Math.min(Math.pow(2, attempts++) * 100, maximumAttemptInterval);

        // Wait and then try to start the reconnection attempt
        setTimeout(start, wait);
    };
})();

// Connect to the server.
diffusion.connect({
    host : 'diffusion.example.com',
    port : 443,
    secure : true,
    principal : 'control',
    credentials : 'password',
    reconnect : {
        timeout : maximumTimeoutDuration,
        strategy : reconnectionStrategy
    }
}).then(function(session) {
Run Code Online (Sandbox Code Playgroud)

取自https://github.com/pushtechnology/diffusion-examples/blob/master/js/examples/reconnect.js

Mar*_*wie 4

这两个参数在手册中被描述为reconnect和,都是可以使用的函数。abort

  • start/ reconnect- 将发起重新连接尝试。指示客户端尝试另一个连接。

  • abort- 可能会被调用来中止重新连接,在这种情况下客户端将被关闭。如果您认为进一步的尝试将毫无结果或有其他不良后果,请调用此选项。

通过这种理解,我们看到该示例尝试在等待之间重新连接,等待时间呈指数增长(100 毫秒、200 毫秒、400 毫秒等),最多可达 60 秒。如果重连尝试失败,则再次调用重连策略函数。