Skip to content

Commit

Permalink
Bugfix. attach wasn't working for WorkerWebsocket
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbrand committed Dec 2, 2023
1 parent 1f87f57 commit c1f0675
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ class Connection {
* application. This is often used to support auto-login type features
* without putting user credentials into the page.
*
* @param {string} jid - The full JID that is bound by the session.
* @param {string|Function} jid - The full JID that is bound by the session.
* @param {string} sid - The SID of the BOSH session.
* @param {number} rid - The current RID of the BOSH session. This RID
* will be used by the next request.
Expand All @@ -541,8 +541,11 @@ class Connection {
* allowed range of request ids that are valid. The default is 5.
*/
attach(jid, sid, rid, callback, wait, hold, wind) {
if (this._proto instanceof Strophe.Bosh) {
if (this._proto instanceof Strophe.Bosh && typeof jid === 'string') {
return this._proto._attach(jid, sid, rid, callback, wait, hold, wind);
} else if (this._proto instanceof Strophe.WorkerWebsocket && typeof jid === 'function') {
const callback = jid;
return this._proto._attach(callback);
} else {
throw new SessionError('The "attach" method is not available for your connection protocol');
}
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const XHTML = {
* @property {connstatus} Status.ATTACHED - The connection has been attached
* @property {connstatus} Status.REDIRECT - The connection has been redirected
* @property {connstatus} Status.CONNTIMEOUT - The connection has timed out
* @property {connstatus} Status.BINDREQUIRED - The JID resource needs to be bound for this session
* @property {connstatus} Status.ATTACHFAIL - Failed to attach to a pre-existing session
* @property {connstatus} Status.RECONNECTING - Not used by Strophe, but added for integrators
*/
Expand Down
4 changes: 2 additions & 2 deletions src/types/connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ declare class Connection {
* application. This is often used to support auto-login type features
* without putting user credentials into the page.
*
* @param {string} jid - The full JID that is bound by the session.
* @param {string|Function} jid - The full JID that is bound by the session.
* @param {string} sid - The SID of the BOSH session.
* @param {number} rid - The current RID of the BOSH session. This RID
* will be used by the next request.
Expand All @@ -689,7 +689,7 @@ declare class Connection {
* @param {number} [wind] - The optional HTTBIND window value. This is the
* allowed range of request ids that are valid. The default is 5.
*/
attach(jid: string, sid: string, rid: number, callback: Function, wait?: number, hold?: number, wind?: number): void;
attach(jid: string | Function, sid: string, rid: number, callback: Function, wait?: number, hold?: number, wind?: number): void;
/**
* Attempt to restore a cached BOSH session.
*
Expand Down
4 changes: 4 additions & 0 deletions src/types/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export type Status = {
* - The connection has timed out
*/
CONNTIMEOUT: connstatus;
/**
* - The JID resource needs to be bound for this session
*/
BINDREQUIRED: connstatus;
/**
* - Failed to attach to a pre-existing session
*/
Expand Down

0 comments on commit c1f0675

Please sign in to comment.