-
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.
Merge pull request #1379 from ably/xhr-transports-typescript
refactor: convert web comet transports to typescript
- Loading branch information
Showing
4 changed files
with
82 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Platform from '../../../../common/platform'; | ||
import CometTransport from '../../../../common/lib/transport/comettransport'; | ||
import XHRRequest from './xhrrequest'; | ||
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; | ||
this.shortName = shortName; | ||
} | ||
|
||
static isAvailable() { | ||
return Platform.Config.xhrSupported && Platform.Config.allowComet; | ||
} | ||
|
||
toString() { | ||
return 'XHRPollingTransport; uri=' + this.baseUri + '; isConnected=' + this.isConnected; | ||
} | ||
|
||
createRequest( | ||
uri: string, | ||
headers: Record<string, string>, | ||
params: RequestParams, | ||
body: unknown, | ||
requestMode: number | ||
) { | ||
return XHRRequest.createRequest(uri, headers, params, body, requestMode, this.timeouts); | ||
} | ||
} | ||
|
||
function initialiseTransport(connectionManager: any): typeof XHRPollingTransport { | ||
if (XHRPollingTransport.isAvailable()) connectionManager.supportedTransports[shortName] = XHRPollingTransport; | ||
|
||
return XHRPollingTransport; | ||
} | ||
|
||
export default initialiseTransport; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import CometTransport from '../../../../common/lib/transport/comettransport'; | ||
import Platform from '../../../../common/platform'; | ||
import XHRRequest from './xhrrequest'; | ||
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); | ||
} | ||
|
||
static isAvailable() { | ||
return Platform.Config.xhrSupported && Platform.Config.streamingSupported && Platform.Config.allowComet; | ||
} | ||
|
||
toString() { | ||
return 'XHRStreamingTransport; uri=' + this.baseUri + '; isConnected=' + this.isConnected; | ||
} | ||
|
||
createRequest( | ||
uri: string, | ||
headers: Record<string, string>, | ||
params: RequestParams, | ||
body: unknown, | ||
requestMode: number | ||
) { | ||
return XHRRequest.createRequest(uri, headers, params, body, requestMode, this.timeouts); | ||
} | ||
} | ||
|
||
function initialiseTransport(connectionManager: any): typeof XHRStreamingTransport { | ||
if (XHRStreamingTransport.isAvailable()) connectionManager.supportedTransports[shortName] = XHRStreamingTransport; | ||
|
||
return XHRStreamingTransport; | ||
} | ||
|
||
export default initialiseTransport; |