Skip to content

Commit

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

var XHRStreamingTransport = function (connectionManager) {
var shortName = 'xhr_streaming';

/* public constructor */
function XHRStreamingTransport(connectionManager, auth, params) {
CometTransport.call(this, connectionManager, auth, params);
this.shortName = shortName;
import ConnectionManager, { TransportParams } from 'common/lib/transport/connectionmanager';
import Auth from 'common/lib/client/auth';
import { RequestParams } from 'common/types/http';

const shortName = 'xhr_streaming';
class XHRStreamingTransport extends CometTransport {
shortName = shortName;
constructor(connectionManager: ConnectionManager, auth: Auth, params: TransportParams) {
super(connectionManager, auth, params);
}
Utils.inherits(XHRStreamingTransport, CometTransport);

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

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

XHRStreamingTransport.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' && XHRStreamingTransport.isAvailable()) {
connectionManager.supportedTransports[shortName] = XHRStreamingTransport;
}
}

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

return XHRStreamingTransport;
};
}

export default XHRStreamingTransport;
export default initialiseTransport;

0 comments on commit 52f1f4e

Please sign in to comment.