Skip to content

Commit

Permalink
refactor: convert xhrpollingtransport.ts to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
owenpearson committed Jul 7, 2023
1 parent dbc3dbe commit 2fd7cdb
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/platform/web/lib/transport/xhrpollingtransport.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
import * as Utils from '../../../../common/lib/util/utils';
import Platform from '../../../../common/platform';
import CometTransport from '../../../../common/lib/transport/comettransport';
import XHRRequest from './xhrrequest';

var XHRPollingTransport = function (connectionManager) {
var shortName = 'xhr_polling';

function XHRPollingTransport(connectionManager, auth, params) {
import ConnectionManager, { TransportParams } from 'common/lib/transport/connectionmanager';
import Auth from 'common/lib/client/auth';
import { RequestParams } from 'common/types/http';

var shortName = 'xhr_polling';
class XHRPollingTransport extends CometTransport {
shortName = shortName;
constructor(connectionManager: ConnectionManager, auth: Auth, params: TransportParams) {
super(connectionManager, auth, params);
params.stream = false;
CometTransport.call(this, connectionManager, auth, params);
this.shortName = shortName;
}
Utils.inherits(XHRPollingTransport, CometTransport);

XHRPollingTransport.isAvailable = function () {
static isAvailable() {
return Platform.Config.xhrSupported && Platform.Config.allowComet;
};
}

XHRPollingTransport.prototype.toString = function () {
toString() {
return 'XHRPollingTransport; uri=' + this.baseUri + '; isConnected=' + this.isConnected;
};
}

XHRPollingTransport.prototype.createRequest = function (uri, headers, params, body, requestMode) {
createRequest(
uri: string,
headers: Record<string, string>,
params: RequestParams,
body: unknown,
requestMode: number
) {
return XHRRequest.createRequest(uri, headers, params, body, requestMode, this.timeouts);
};

if (typeof connectionManager !== 'undefined' && XHRPollingTransport.isAvailable()) {
connectionManager.supportedTransports[shortName] = XHRPollingTransport;
}
}

function initialiseTransport(connectionManager: any): typeof XHRPollingTransport {
if (XHRPollingTransport.isAvailable()) connectionManager.supportedTransports[shortName] = XHRPollingTransport;

return XHRPollingTransport;
};
}

export default XHRPollingTransport;
export default initialiseTransport;

0 comments on commit 2fd7cdb

Please sign in to comment.