Files
Cloud-book/node_modules/shoe/node_modules/sockjs-client/lib/trans-polling.js
2025-08-27 17:10:05 +08:00

45 lines
1.1 KiB
JavaScript

/*
* ***** BEGIN LICENSE BLOCK *****
* Copyright (c) 2011-2012 VMware, Inc.
*
* For the license see COPYING.
* ***** END LICENSE BLOCK *****
*/
var Polling = function(ri, Receiver, recv_url, AjaxObject) {
var that = this;
that.ri = ri;
that.Receiver = Receiver;
that.recv_url = recv_url;
that.AjaxObject = AjaxObject;
that._scheduleRecv();
};
Polling.prototype._scheduleRecv = function() {
var that = this;
var poll = that.poll = new that.Receiver(that.recv_url, that.AjaxObject);
var msg_counter = 0;
poll.onmessage = function(e) {
msg_counter += 1;
that.ri._didMessage(e.data);
};
poll.onclose = function(e) {
that.poll = poll = poll.onmessage = poll.onclose = null;
if (!that.poll_is_closing) {
if (e.reason === 'permanent') {
that.ri._didClose(1006, 'Polling error (' + e.reason + ')');
} else {
that._scheduleRecv();
}
}
};
};
Polling.prototype.abort = function() {
var that = this;
that.poll_is_closing = true;
if (that.poll) {
that.poll.abort();
}
};