forked from genofire/unified-push-xmpp
				
			distributor: check server for msgoffline support XEP-0160
with discovery XEP-0030 ;) wip #8
This commit is contained in:
		
							parent
							
								
									29cf678106
								
							
						
					
					
						commit
						63aa921252
					
				|  | @ -35,3 +35,5 @@ require ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| replace dev.sum7.eu/genofire/unified-push-xmpp/messages => ../messages | replace dev.sum7.eu/genofire/unified-push-xmpp/messages => ../messages | ||||||
|  | 
 | ||||||
|  | replace mellium.im/xmpp => ../../../../mellium.im/xmpp | ||||||
|  |  | ||||||
|  | @ -12,6 +12,7 @@ import ( | ||||||
| 	"mellium.im/sasl" | 	"mellium.im/sasl" | ||||||
| 	"mellium.im/xmlstream" | 	"mellium.im/xmlstream" | ||||||
| 	"mellium.im/xmpp" | 	"mellium.im/xmpp" | ||||||
|  | 	"mellium.im/xmpp/disco" | ||||||
| 	"mellium.im/xmpp/jid" | 	"mellium.im/xmpp/jid" | ||||||
| 	"mellium.im/xmpp/mux" | 	"mellium.im/xmpp/mux" | ||||||
| 	"mellium.im/xmpp/stanza" | 	"mellium.im/xmpp/stanza" | ||||||
|  | @ -62,7 +63,9 @@ func (s *XMPPService) Run(dbus *distributor.DBus, store *storage.Storage) error | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  | 	go s.checkServer() | ||||||
| 	s.session.Serve(mux.New( | 	s.session.Serve(mux.New( | ||||||
|  | 		// disco.Handle(),
 | ||||||
| 		mux.MessageFunc("", xml.Name{Local: "subject"}, s.message), | 		mux.MessageFunc("", xml.Name{Local: "subject"}, s.message), | ||||||
| 	)) | 	)) | ||||||
| 	return nil | 	return nil | ||||||
|  | @ -116,6 +119,28 @@ func (s *XMPPService) message(msgHead stanza.Message, t xmlstream.TokenReadEncod | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // checkServer - background job
 | ||||||
|  | func (s *XMPPService) checkServer() error { | ||||||
|  | 	domain := s.session.LocalAddr().Domain() | ||||||
|  | 	log.Infof("your instant is %s - check running", domain) | ||||||
|  | 	info, err := disco.GetInfo(context.TODO(), "", domain, s.session) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  | 	// check if server support msgoffline
 | ||||||
|  | 	supportMSGOffline := false | ||||||
|  | 	for _, f := range info.Features { | ||||||
|  | 		if f.Var == "msgoffline" { | ||||||
|  | 			supportMSGOffline = true | ||||||
|  | 			break | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	if !supportMSGOffline { | ||||||
|  | 		log.Warn("your server does not support offline messages (XEP-0160) - it is need to deliever messages later, if this distributer has current no connection") | ||||||
|  | 	} | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // Register handler of DBUS Distribution
 | // Register handler of DBUS Distribution
 | ||||||
| func (s *XMPPService) Register(appID, appToken string) (string, string, error) { | func (s *XMPPService) Register(appID, appToken string) (string, string, error) { | ||||||
| 	publicToken := uuid.New().String() | 	publicToken := uuid.New().String() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue