@@ -689,6 +689,7 @@ func (srv *server) loadPlugins() error {
689689 onSessionTerminatedWrapper []OnSessionTerminatedWrapper
690690 onSubscribeWrappers []OnSubscribeWrapper
691691 onSubscribedWrappers []OnSubscribedWrapper
692+ onUnsubscribeWrappers []OnUnsubscribeWrapper
692693 onUnsubscribedWrappers []OnUnsubscribedWrapper
693694 onMsgArrivedWrappers []OnMsgArrivedWrapper
694695 onDeliverWrappers []OnDeliverWrapper
@@ -729,6 +730,9 @@ func (srv *server) loadPlugins() error {
729730 if hooks .OnSubscribedWrapper != nil {
730731 onSubscribedWrappers = append (onSubscribedWrappers , hooks .OnSubscribedWrapper )
731732 }
733+ if hooks .OnUnsubscribeWrapper != nil {
734+ onUnsubscribeWrappers = append (onUnsubscribeWrappers , hooks .OnUnsubscribeWrapper )
735+ }
732736 if hooks .OnUnsubscribedWrapper != nil {
733737 onUnsubscribedWrappers = append (onUnsubscribedWrappers , hooks .OnUnsubscribedWrapper )
734738 }
@@ -751,6 +755,7 @@ func (srv *server) loadPlugins() error {
751755 onStopWrappers = append (onStopWrappers , hooks .OnStopWrapper )
752756 }
753757 }
758+
754759 // onAccept
755760 if onAcceptWrappers != nil {
756761 onAccept := func (ctx context.Context , conn net.Conn ) bool {
@@ -761,6 +766,7 @@ func (srv *server) loadPlugins() error {
761766 }
762767 srv .hooks .OnAccept = onAccept
763768 }
769+
764770 // onConnect
765771 if onConnectWrappers != nil {
766772 onConnect := func (ctx context.Context , client Client ) (code uint8 ) {
@@ -771,6 +777,7 @@ func (srv *server) loadPlugins() error {
771777 }
772778 srv .hooks .OnConnect = onConnect
773779 }
780+
774781 // onConnected
775782 if onConnectedWrappers != nil {
776783 onConnected := func (ctx context.Context , client Client ) {}
@@ -779,6 +786,7 @@ func (srv *server) loadPlugins() error {
779786 }
780787 srv .hooks .OnConnected = onConnected
781788 }
789+
782790 // onSessionCreated
783791 if onSessionCreatedWrapper != nil {
784792 onSessionCreated := func (ctx context.Context , client Client ) {}
@@ -816,6 +824,7 @@ func (srv *server) loadPlugins() error {
816824 }
817825 srv .hooks .OnSubscribe = onSubscribe
818826 }
827+
819828 // onSubscribed
820829 if onSubscribedWrappers != nil {
821830 onSubscribed := func (ctx context.Context , client Client , topic packets.Topic ) {}
@@ -824,6 +833,16 @@ func (srv *server) loadPlugins() error {
824833 }
825834 srv .hooks .OnSubscribed = onSubscribed
826835 }
836+
837+ //onUnsubscribe
838+ if onUnsubscribeWrappers != nil {
839+ onUnsubscribe := func (ctx context.Context , client Client , topicName string ) {}
840+ for i := len (onUnsubscribeWrappers ); i > 0 ; i -- {
841+ onUnsubscribe = onUnsubscribeWrappers [i - 1 ](onUnsubscribe )
842+ }
843+ srv .hooks .OnUnsubscribe = onUnsubscribe
844+ }
845+
827846 //onUnsubscribed
828847 if onUnsubscribedWrappers != nil {
829848 onUnsubscribed := func (ctx context.Context , client Client , topicName string ) {}
@@ -832,6 +851,7 @@ func (srv *server) loadPlugins() error {
832851 }
833852 srv .hooks .OnUnsubscribed = onUnsubscribed
834853 }
854+
835855 // onMsgArrived
836856 if onMsgArrivedWrappers != nil {
837857 onMsgArrived := func (ctx context.Context , client Client , msg packets.Message ) (valid bool ) {
@@ -842,6 +862,7 @@ func (srv *server) loadPlugins() error {
842862 }
843863 srv .hooks .OnMsgArrived = onMsgArrived
844864 }
865+
845866 // onDeliver
846867 if onDeliverWrappers != nil {
847868 onDeliver := func (ctx context.Context , client Client , msg packets.Message ) {}
@@ -850,6 +871,7 @@ func (srv *server) loadPlugins() error {
850871 }
851872 srv .hooks .OnDeliver = onDeliver
852873 }
874+
853875 // onAcked
854876 if onAckedWrappers != nil {
855877 onAcked := func (ctx context.Context , client Client , msg packets.Message ) {}
@@ -858,6 +880,7 @@ func (srv *server) loadPlugins() error {
858880 }
859881 srv .hooks .OnAcked = onAcked
860882 }
883+
861884 // onClose hooks
862885 if onCloseWrappers != nil {
863886 onClose := func (ctx context.Context , client Client , err error ) {}
@@ -866,6 +889,7 @@ func (srv *server) loadPlugins() error {
866889 }
867890 srv .hooks .OnClose = onClose
868891 }
892+
869893 // onStop
870894 if onStopWrappers != nil {
871895 onStop := func (ctx context.Context ) {}
0 commit comments