From 823d0fc16cee88f582a83c2232899bcdbbcb2406 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Mon, 12 Aug 2024 19:01:26 +0530 Subject: [PATCH] Updated realtime url to return url based on given host --- ably/export_test.go | 4 ++-- ably/options.go | 10 +++------- ably/realtime_conn.go | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/ably/export_test.go b/ably/export_test.go index 1f8ac150..e9531f90 100644 --- a/ably/export_test.go +++ b/ably/export_test.go @@ -70,8 +70,8 @@ func (opts *clientOptions) RestURL() string { return opts.restURL() } -func (opts *clientOptions) RealtimeURL() string { - return opts.realtimeURL() +func (opts *clientOptions) RealtimeURL(realtimeHost string) string { + return opts.realtimeURL(realtimeHost) } func (c *REST) Post(ctx context.Context, path string, in, out interface{}) (*http.Response, error) { diff --git a/ably/options.go b/ably/options.go index 2a06a0c2..16b43b8c 100644 --- a/ably/options.go +++ b/ably/options.go @@ -486,13 +486,9 @@ func (opts *clientOptions) restURL() (restUrl string) { return "https://" + baseUrl } -func (opts *clientOptions) realtimeURL() (realtimeUrl string) { - baseUrl := opts.getRealtimeHost() - _, _, err := net.SplitHostPort(baseUrl) - if err != nil { // set port if not set in baseUrl - port, _ := opts.activePort() - baseUrl = net.JoinHostPort(baseUrl, strconv.Itoa(port)) - } +func (opts *clientOptions) realtimeURL(realtimeHost string) (realtimeUrl string) { + port, _ := opts.activePort() + baseUrl := net.JoinHostPort(realtimeHost, strconv.Itoa(port)) if opts.NoTLS { return "ws://" + baseUrl } diff --git a/ably/realtime_conn.go b/ably/realtime_conn.go index 713428e9..bb08d812 100644 --- a/ably/realtime_conn.go +++ b/ably/realtime_conn.go @@ -390,7 +390,7 @@ func (c *Connection) connectWith(arg connArgs) (result, error) { var conn conn host := c.hosts.getPreferredHost() for { - u, err := url.Parse(host) + u, err := url.Parse(c.opts.realtimeURL(host)) if err != nil { return nil, err }