Skip to content

Commit

Permalink
fix: AWSAppSyncRealTimeProvider websocket init fix (#9200)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-mcafee authored Nov 11, 2021
1 parent b5819c5 commit 99dbdda
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/pubsub/src/Providers/AWSAppSyncRealTimeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,6 @@ export class AWSAppSyncRealTimeProvider extends AbstractPubSubProvider {
if (this.socketStatus === SOCKET_STATUS.CLOSED) {
try {
this.socketStatus = SOCKET_STATUS.CONNECTING;
// Creating websocket url with required query strings
const protocol = this.isSSLEnabled ? 'wss://' : 'ws://';
let discoverableEndpoint: string = appSyncGraphqlEndpoint
.replace('https://', protocol)
.replace('http://', protocol);

const payloadString = '{}';
const headerString = JSON.stringify(
Expand All @@ -622,6 +617,8 @@ export class AWSAppSyncRealTimeProvider extends AbstractPubSubProvider {

const payloadQs = Buffer.from(payloadString).toString('base64');

let discoverableEndpoint = appSyncGraphqlEndpoint;

if (this.isCustomDomain(discoverableEndpoint)) {
discoverableEndpoint = discoverableEndpoint.concat(
customDomainPath
Expand All @@ -630,6 +627,12 @@ export class AWSAppSyncRealTimeProvider extends AbstractPubSubProvider {
discoverableEndpoint = discoverableEndpoint.replace('appsync-api', 'appsync-realtime-api').replace('gogi-beta', 'grt-beta');
}

// Creating websocket url with required query strings
const protocol = this.isSSLEnabled ? 'wss://' : 'ws://';
discoverableEndpoint = discoverableEndpoint
.replace('https://', protocol)
.replace('http://', protocol);

const awsRealTimeUrl = `${discoverableEndpoint}?header=${headerQs}&payload=${payloadQs}`;

await this._initializeRetryableHandshake({ awsRealTimeUrl });
Expand Down

0 comments on commit 99dbdda

Please sign in to comment.