-
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 xhrstreamingtransport to typescript
- Loading branch information
1 parent
2fd7cdb
commit 52f1f4e
Showing
1 changed file
with
26 additions
and
21 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,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; |