@@ -809,73 +809,72 @@ const xmpp = {
809
809
* Any other presence that alters the user roster or client state.
810
810
*/
811
811
eventPresenceCallback ( stanza ) {
812
- if ( ! stanza ) return true ;
813
- const from = this . JID . parse ( stanza . getAttribute ( 'from' ) ) ;
814
- // Discard any <presence/> that is not from the MUC domain.
815
- // (This client does not support direct non-MUC communication.)
816
- if ( from . domain != config . xmpp . mucService ) return true ;
817
-
818
- // Find the room and nickname that the presence came from, and the type.
819
- const room = from . node ;
820
- const nick = from . resource ;
821
- const type = stanza . getAttribute ( 'type' ) ;
812
+ try {
813
+ const from = this . JID . parse ( stanza . getAttribute ( 'from' ) ) ;
814
+ // Discard any <presence/> that is not from the MUC domain.
815
+ // (This client does not support direct non-MUC communication.)
816
+ if ( from . domain != config . xmpp . mucService ) return true ;
822
817
823
- // Initialize the room roster if it doesn't exist yet.
824
- if ( ! this . roster [ room ] ) this . roster [ room ] = { } ;
818
+ // Find the room and nickname that the presence came from, and the type.
819
+ const room = from . node ;
820
+ const nick = from . resource ;
821
+ const type = stanza . getAttribute ( 'type' ) ;
825
822
823
+ // Initialize the room roster if it doesn't exist yet.
824
+ if ( ! this . roster [ room ] ) this . roster [ room ] = { } ;
826
825
827
- if ( type == 'error' ) {
828
- // We're not throwing this one, the error handling happens in here.
829
- const error = new this . StanzaError ( stanza ) ;
830
- switch ( error . condition ) {
831
- case 'conflict' :
832
- if ( room == this . room . current ) {
833
- ui . messageError ( strings . error . nickConflict , { nick} ) ;
834
- this . nick . target = this . nick . current ;
835
- }
836
- else {
837
- ui . messageError ( strings . error . joinConflict , { nick} ) ;
838
- if ( this . nickConflictResolve ( ) ) {
839
- ui . messageInfo ( strings . info . rejoinNick , { nick : this . nick . target } ) ;
840
- this . joinRoom ( this . room . target , this . nick . target ) ;
841
- }
842
- }
843
- break ;
844
- case 'not-authorized' :
845
- const password = prompt ( strings . info . promptRoomPassword ) ;
846
- if ( password ) {
847
- this . joinExistingRoom ( room , password ) ;
848
- }
849
- else {
850
- ui . messageError ( strings . error . joinPassword , { room : this . room . available [ room ] } ) ;
851
- }
852
- break ;
853
- case 'forbidden' :
854
- ui . messageError ( strings . error . joinBanned , { room : this . room . available [ room ] } ) ;
855
- break ;
856
- case 'not-allowed' :
857
- ui . messageError ( strings . error . noCreate ) ;
858
- break ;
859
- case 'jid-malformed' :
860
- this . nick . target = this . nick . current ;
861
- ui . messageError ( strings . error . badNick , { nick} ) ;
826
+ if ( type == 'error' ) {
827
+ this . eventPresenceError ( room , nick , stanza ) ;
828
+ return true ;
862
829
}
863
- return true ;
864
- }
865
830
866
- // Find the status codes.
867
- const item = stanza . querySelector ( 'item' ) ;
868
- const codes = Array . from ( stanza . querySelectorAll ( 'status' ) ) . map (
869
- e => parseInt ( e . getAttribute ( 'code' ) )
870
- ) ;
831
+ // Find the status codes.
832
+ const item = stanza . querySelector ( 'item' ) ;
833
+ const codes = Array . from ( stanza . querySelectorAll ( 'status' ) ) . map (
834
+ e => parseInt ( e . getAttribute ( 'code' ) )
835
+ ) ;
871
836
872
- if ( type == 'unavailable' )
873
- this . eventPresenceUnavailable ( room , nick , codes , item , stanza ) ;
874
- else
875
- this . eventPresenceDefault ( room , nick , codes , item , stanza ) ;
837
+ if ( type == 'unavailable' )
838
+ this . eventPresenceUnavailable ( room , nick , codes , item , stanza ) ;
839
+ else
840
+ this . eventPresenceDefault ( room , nick , codes , item , stanza ) ;
841
+ }
842
+ catch ( e ) {
843
+ Cadence . handleError ( e ) ;
844
+ }
876
845
return true ;
877
846
} ,
878
847
848
+ eventPresenceError ( room , nick , stanza ) {
849
+ // We're not throwing this one, the error handling happens in here.
850
+ const error = new this . StanzaError ( stanza ) ;
851
+ switch ( error . condition ) {
852
+ case 'conflict' :
853
+ if ( room == this . room . current ) {
854
+ this . nick . target = this . nick . current ;
855
+ throw new Cadence . Error ( strings . error . nickConflict , { nick} ) ;
856
+ }
857
+ if ( this . nickConflictResolve ( ) ) {
858
+ ui . messageInfo ( strings . info . rejoinNick , { nick : this . nick . target } ) ;
859
+ this . joinRoom ( this . room . target , this . nick . target ) ;
860
+ }
861
+ else throw new Cadence . Error ( strings . error . joinConflict , { nick} ) ;
862
+ break ;
863
+ case 'not-authorized' :
864
+ const password = prompt ( strings . info . promptRoomPassword ) ;
865
+ if ( password ) this . joinExistingRoom ( room , password ) ;
866
+ else throw new Cadence . Error ( strings . error . joinPassword , { room : this . room . available [ room ] } ) ;
867
+ break ;
868
+ case 'forbidden' :
869
+ throw new Cadence . Error ( strings . error . joinBanned , { room : this . room . available [ room ] } ) ;
870
+ case 'not-allowed' :
871
+ throw new Cadence . Error ( strings . error . noCreate ) ;
872
+ case 'jid-malformed' :
873
+ this . nick . target = this . nick . current ;
874
+ throw new Cadence . Error ( strings . error . badNick , { nick} ) ;
875
+ }
876
+ } ,
877
+
879
878
/**
880
879
* Handle presence stanzas of type `unavailable`.
881
880
*/
@@ -1021,7 +1020,7 @@ const xmpp = {
1021
1020
* This function handles any <message> stanzas received.
1022
1021
*/
1023
1022
eventMessageCallback ( stanza ) {
1024
- if ( stanza ) {
1023
+ try {
1025
1024
const from = this . JID . parse ( stanza . getAttribute ( 'from' ) ) ;
1026
1025
const { domain, node, resource} = from ;
1027
1026
@@ -1127,6 +1126,9 @@ const xmpp = {
1127
1126
if ( resource != this . nick . current ) ui . notify ( message ) ;
1128
1127
}
1129
1128
}
1129
+ catch ( e ) {
1130
+ Cadence . handleError ( e ) ;
1131
+ }
1130
1132
return true ;
1131
1133
} ,
1132
1134
@@ -1140,13 +1142,13 @@ const xmpp = {
1140
1142
const error = new xmpp . StanzaError ( stanza ) ;
1141
1143
switch ( error . condition ) {
1142
1144
case 'remote-server-not-found' :
1143
- return ui . messageError ( strings . error . notFound . domain , from ) ;
1145
+ throw new Cadence . Error ( strings . error . notFound . domain , from ) ;
1144
1146
case 'service-unavailable' :
1145
- return ui . messageError ( strings . error . notFound . node , from ) ;
1147
+ throw new Cadence . Error ( strings . error . notFound . node , from ) ;
1146
1148
case 'item-not-found' :
1147
- return ui . messageError ( strings . error . notFound . nick , { nick : from . resource } ) ;
1149
+ throw new Cadence . Error ( strings . error . notFound . nick , { nick : from . resource } ) ;
1148
1150
case 'forbidden' :
1149
- return ui . messageError ( strings . error . messageDenied , error ) ;
1151
+ throw new Cadence . Error ( strings . error . messageDenied , error ) ;
1150
1152
}
1151
1153
} ,
1152
1154
0 commit comments