File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
app/javascript/action_cable Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -30,14 +30,16 @@ export function getConfig(name) {
30
30
}
31
31
32
32
export function createWebSocketURL ( url ) {
33
- if ( url && ! / ^ w s s ? : / i. test ( url ) ) {
33
+ const webSocketURL = typeof url === 'function' ? url ( ) : url ;
34
+
35
+ if ( webSocketURL && ! / ^ w s s ? : / i. test ( webSocketURL ) ) {
34
36
const a = document . createElement ( "a" )
35
- a . href = url
37
+ a . href = webSocketURL
36
38
// Fix populating Location properties in IE. Otherwise, protocol will be blank.
37
39
a . href = a . href
38
40
a . protocol = a . protocol . replace ( "http" , "ws" )
39
41
return a . href
40
42
} else {
41
- return url
43
+ return webSocketURL
42
44
}
43
45
}
Original file line number Diff line number Diff line change @@ -41,5 +41,13 @@ module("ActionCable", () => {
41
41
42
42
assert . equal ( consumer . url , testURL )
43
43
} )
44
+
45
+ test ( "uses function to generate URL" , assert => {
46
+ const generateURL = ( ) => {
47
+ return testURL
48
+ }
49
+ const consumer = ActionCable . createConsumer ( generateURL )
50
+ assert . equal ( consumer . url , testURL )
51
+ } )
44
52
} )
45
53
} )
You can’t perform that action at this time.
0 commit comments