Skip to content

Commit

Permalink
Merge pull request #1379 from ably/xhr-transports-typescript
Browse files Browse the repository at this point in the history
refactor: convert web comet transports to typescript
  • Loading branch information
owenpearson authored Jul 12, 2023
2 parents 404c412 + 52f1f4e commit 8e9d1c8
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 70 deletions.
35 changes: 0 additions & 35 deletions src/platform/web/lib/transport/xhrpollingtransport.js

This file was deleted.

42 changes: 42 additions & 0 deletions src/platform/web/lib/transport/xhrpollingtransport.ts
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;
35 changes: 0 additions & 35 deletions src/platform/web/lib/transport/xhrstreamingtransport.js

This file was deleted.

40 changes: 40 additions & 0 deletions src/platform/web/lib/transport/xhrstreamingtransport.ts
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;

0 comments on commit 8e9d1c8

Please sign in to comment.