Commit 3aefba32 authored by JC Brand's avatar JC Brand

Change ping plugin to not have to use overrides.

Had to add a `reconnect` event to core.
parent 82aa9fec
......@@ -862,12 +862,14 @@ When keepalive=true but there aren't any stored prebind tokens.
``converse.listen.on('noResumeableSession', function (event) { ... });``
reconnect
~~~~~~~~~
reconnected
~~~~~~~~~~~
After the connection has dropped. Converse.js will attempt to reconnect when not in prebind mode.
After the connection has dropped and converse.js has reconnected.
Any Strophe stanza handlers (as registered via `converse.listen.stanza`) will
have to be registered anew.
``converse.listen.on('reconnect', function (event) { ... });``
``converse.listen.on('reconnected', function (event) { ... });``
roomInviteSent
~~~~~~~~~~~~~~
......
......@@ -2,28 +2,34 @@
(function (root, factory) {
define([
"jquery",
"mock",
"test_utils",
"converse-ping"
], function ($, mock, test_utils) {
return factory($, mock, test_utils);
], function ($) {
return factory($);
}
);
} (this, function ($, mock, test_utils) {
} (this, function ($) {
"use strict";
describe("XMPP Ping", $.proxy(function (mock, test_utils) {
describe("Ping and pong handlers", $.proxy(function (mock, test_utils) {
it("are registered when converse.js is initialized", $.proxy(function () {
describe("XMPP Ping", function () {
describe("Ping and pong handlers", function () {
it("are registered when converse.js is connected", function () {
spyOn(converse, 'registerPingHandler').andCallThrough();
spyOn(converse, 'registerPongHandler').andCallThrough();
converse._initialize();
converse.emit('connected');
expect(converse.registerPingHandler).toHaveBeenCalled();
expect(converse.registerPongHandler).toHaveBeenCalled();
}, converse, mock, test_utils));
}));
});
it("are registered when converse.js reconnected", function () {
spyOn(converse, 'registerPingHandler').andCallThrough();
spyOn(converse, 'registerPongHandler').andCallThrough();
converse.emit('reconnected');
expect(converse.registerPingHandler).toHaveBeenCalled();
expect(converse.registerPongHandler).toHaveBeenCalled();
});
});
describe("An IQ stanza", $.proxy(function (mock, test_utils) {
describe("An IQ stanza", function () {
it("is sent out when converse.js pings a server", function () {
var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ;
......@@ -37,6 +43,6 @@
"<ping xmlns='urn:xmpp:ping'/>"+
"</iq>");
});
}));
}, converse, mock, test_utils));
});
});
}));
......@@ -626,6 +626,7 @@
this.afterReconnected();
deferred.resolve();
}.bind(this));
converse.emit('reconnected');
return deferred.promise();
};
......
......@@ -24,27 +24,6 @@
converse_api.plugins.add('ping', {
overrides: {
// Overrides mentioned here will be picked up by converse.js's
// plugin architecture they will replace existing methods on the
// relevant objects or classes.
//
// New functions which don't exist yet can also be added.
onConnected: function () {
var promise = this._super.onConnected();
promise.done(converse.registerPingHandler);
return promise;
},
onReconnected: function () {
// We need to re-register the ping event handler on the newly
// created connection.
var promise = this._super.onReconnected();
promise.done(converse.registerPingHandler);
return promise;
}
},
initialize: function () {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
......@@ -118,6 +97,13 @@
converse.ping(jid);
}
});
var onConnected = function () {
// Wrapper so that we can spy on registerPingHandler in tests
converse.registerPingHandler();
};
converse.on('connected', onConnected);
converse.on('reconnected', onConnected);
}
});
}));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment