Skip to content

Commit

Permalink
bump build
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenDE committed Mar 3, 2025
1 parent 6137ee4 commit 8e66151
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 44 deletions.
47 changes: 34 additions & 13 deletions priv/static/phoenix.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions priv/static/phoenix.cjs.js.map

Large diffs are not rendered by default.

45 changes: 33 additions & 12 deletions priv/static/phoenix.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var Phoenix = (() => {
// js/phoenix/constants.js
var globalSelf = typeof self !== "undefined" ? self : null;
var phxWindow = typeof window !== "undefined" ? window : null;
var global = globalSelf || phxWindow || global;
var global = globalSelf || phxWindow || globalThis;
var DEFAULT_VSN = "2.0.0";
var SOCKET_STATES = { connecting: 0, open: 1, closing: 2, closed: 3 };
var DEFAULT_TIMEOUT = 1e4;
Expand All @@ -68,6 +68,7 @@ var Phoenix = (() => {
var XHR_STATES = {
complete: 4
};
var AUTH_TOKEN_PREFIX = "base64url.bearer.phx.";

// js/phoenix/push.js
var Push = class {
Expand Down Expand Up @@ -529,13 +530,13 @@ var Phoenix = (() => {

// js/phoenix/ajax.js
var Ajax = class {
static request(method, endPoint, accept, body, timeout, ontimeout, callback) {
static request(method, endPoint, headers, body, timeout, ontimeout, callback) {
if (global.XDomainRequest) {
let req = new global.XDomainRequest();
return this.xdomainRequest(req, method, endPoint, body, timeout, ontimeout, callback);
} else {
let req = new global.XMLHttpRequest();
return this.xhrRequest(req, method, endPoint, accept, body, timeout, ontimeout, callback);
return this.xhrRequest(req, method, endPoint, headers, body, timeout, ontimeout, callback);
}
}
static xdomainRequest(req, method, endPoint, body, timeout, ontimeout, callback) {
Expand All @@ -553,10 +554,12 @@ var Phoenix = (() => {
req.send(body);
return req;
}
static xhrRequest(req, method, endPoint, accept, body, timeout, ontimeout, callback) {
static xhrRequest(req, method, endPoint, headers, body, timeout, ontimeout, callback) {
req.open(method, endPoint, true);
req.timeout = timeout;
req.setRequestHeader("Content-Type", accept);
for (let [key, value] of Object.entries(headers)) {
req.setRequestHeader(key, value);
}
req.onerror = () => callback && callback(null);
req.onreadystatechange = () => {
if (req.readyState === XHR_STATES.complete && callback) {
Expand Down Expand Up @@ -617,7 +620,10 @@ var Phoenix = (() => {
return btoa(binary);
};
var LongPoll = class {
constructor(endPoint) {
constructor(endPoint, protocols) {
if (protocols.length === 2 && protocols[1].startsWith(AUTH_TOKEN_PREFIX)) {
this.authToken = atob(protocols[1].slice(AUTH_TOKEN_PREFIX.length));
}
this.endPoint = null;
this.token = null;
this.skipHeartbeat = true;
Expand Down Expand Up @@ -656,7 +662,11 @@ var Phoenix = (() => {
return this.readyState === SOCKET_STATES.open || this.readyState === SOCKET_STATES.connecting;
}
poll() {
this.ajax("GET", "application/json", null, () => this.ontimeout(), (resp) => {
const headers = { "Accept": "application/json" };
if (this.authToken) {
headers["X-Phoenix-AuthToken"] = this.authToken;
}
this.ajax("GET", headers, null, () => this.ontimeout(), (resp) => {
if (resp) {
var { status, token, messages } = resp;
this.token = token;
Expand Down Expand Up @@ -739,13 +749,13 @@ var Phoenix = (() => {
this.onclose(opts);
}
}
ajax(method, contentType, body, onCallerTimeout, callback) {
ajax(method, headers, body, onCallerTimeout, callback) {
let req;
let ontimeout = () => {
this.reqs.delete(req);
onCallerTimeout();
};
req = Ajax.request(method, this.endpointURL(), contentType, body, this.timeout, ontimeout, (resp) => {
req = Ajax.request(method, this.endpointURL(), headers, body, this.timeout, ontimeout, (resp) => {
this.reqs.delete(req);
if (this.isActive()) {
callback(resp);
Expand Down Expand Up @@ -1034,6 +1044,7 @@ var Phoenix = (() => {
this.defaultEncoder = serializer_default.encode.bind(serializer_default);
this.defaultDecoder = serializer_default.decode.bind(serializer_default);
this.closeWasClean = false;
this.disconnecting = false;
this.binaryType = opts.binaryType || "arraybuffer";
this.connectClock = 1;
if (this.transport !== LongPoll) {
Expand Down Expand Up @@ -1089,6 +1100,7 @@ var Phoenix = (() => {
this.reconnectTimer = new Timer(() => {
this.teardown(() => this.connect());
}, this.reconnectAfterMs);
this.authToken = opts.authToken;
}
/**
* Returns the LongPoll transport reference
Expand Down Expand Up @@ -1150,10 +1162,14 @@ var Phoenix = (() => {
*/
disconnect(callback, code, reason) {
this.connectClock++;
this.disconnecting = true;
this.closeWasClean = true;
clearTimeout(this.fallbackTimer);
this.reconnectTimer.reset();
this.teardown(callback, code, reason);
this.teardown(() => {
this.disconnecting = false;
callback && callback();
}, code, reason);
}
/**
*
Expand All @@ -1167,7 +1183,7 @@ var Phoenix = (() => {
console && console.log("passing params to connect is deprecated. Instead pass :params to the Socket constructor");
this.params = closure(params);
}
if (this.conn) {
if (this.conn && !this.disconnecting) {
return;
}
if (this.longPollFallbackMs && this.transport !== LongPoll) {
Expand Down Expand Up @@ -1260,7 +1276,11 @@ var Phoenix = (() => {
transportConnect() {
this.connectClock++;
this.closeWasClean = false;
this.conn = new this.transport(this.endPointURL());
let protocols = ["phoenix"];
if (this.authToken) {
protocols.push(`${AUTH_TOKEN_PREFIX}${btoa(this.authToken).replace(/=/g, "")}`);
}
this.conn = new this.transport(this.endPointURL(), protocols);
this.conn.binaryType = this.binaryType;
this.conn.timeout = this.longpollerTimeout;
this.conn.onopen = () => this.onConnOpen();
Expand Down Expand Up @@ -1323,6 +1343,7 @@ var Phoenix = (() => {
if (this.hasLogger())
this.log("transport", `${this.transport.name} connected to ${this.endPointURL()}`);
this.closeWasClean = false;
this.disconnecting = false;
this.establishedConnections++;
this.flushSendBuffer();
this.reconnectTimer.reset();
Expand Down
Loading

0 comments on commit 8e66151

Please sign in to comment.