From 99dbddad8c8b0d017c9004961b53b6f9198719b7 Mon Sep 17 00:00:00 2001 From: David McAfee Date: Thu, 11 Nov 2021 15:03:16 -0800 Subject: [PATCH] fix: AWSAppSyncRealTimeProvider websocket init fix (#9200) --- .../src/Providers/AWSAppSyncRealTimeProvider.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/pubsub/src/Providers/AWSAppSyncRealTimeProvider.ts b/packages/pubsub/src/Providers/AWSAppSyncRealTimeProvider.ts index 065ac9b1758..9dbe7cd29fd 100644 --- a/packages/pubsub/src/Providers/AWSAppSyncRealTimeProvider.ts +++ b/packages/pubsub/src/Providers/AWSAppSyncRealTimeProvider.ts @@ -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( @@ -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 @@ -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 });