-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: convert xhrpollingtransport.ts to typescript
- Loading branch information
1 parent
dbc3dbe
commit 2fd7cdb
Showing
1 changed file
with
26 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |