Merge remote-tracking branch 'origin/master'

This commit is contained in:
carson 2021-02-23 13:46:17 -07:00
commit f96d880e34
2 changed files with 9 additions and 3 deletions

View File

@ -1052,8 +1052,13 @@ return (function () {
} }
function processWebSocketSource(elt, wssSource) { function processWebSocketSource(elt, wssSource) {
if (wssSource.indexOf("ws:") !== 0 && wssSource.indexOf("wss:") !== 0) { if (wssSource.indexOf("/") == 0) { // complete absolute paths only
wssSource = "wss:" + wssSource; var base_part = location.hostname + (location.port ? ':'+location.port: '');
if (location.protocol == 'https:') {
wssSource = "wss://" + base_part + wssSource;
} else if (location.protocol == 'http:') {
wssSource = "ws://" + base_part + wssSource;
}
} }
var socket = htmx.createWebSocket(wssSource); var socket = htmx.createWebSocket(wssSource);
socket.onerror = function (e) { socket.onerror = function (e) {

View File

@ -8,7 +8,8 @@ title: </> htmx - hx-ws
The `hx-ws` allows you to work with [Web Sockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications) The `hx-ws` allows you to work with [Web Sockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications)
directly from HTML. The value of the attribute can be one or more of the following, separated by commas: directly from HTML. The value of the attribute can be one or more of the following, separated by commas:
* `connect:<url>` or `connect:<prefix>:<url>` - A URL to establish an `WebSocket` connection against. Prefixes `ws` or `wss` can optionally be specified. If not specified, HTMX defaults to add the `wss` prefix to the url. * `connect:<url>` or `connect:<prefix>:<url>` - A URL to establish an `WebSocket` connection against.
* Prefixes `ws` or `wss` can optionally be specified. If not specified, HTMX defaults to add the location's scheme-type, host and port to have browsers send cookies via websockets.
* `send` - Sends a message to the nearest websocket based on the trigger value for the element (either the natural event * `send` - Sends a message to the nearest websocket based on the trigger value for the element (either the natural event
of the event specified by [`hx-trigger`]) of the event specified by [`hx-trigger`])