allow retrieving handlers from an aif so we can merge them in cwtch peers
This commit is contained in:
parent
ad9d0efb02
commit
4d3f52102f
|
@ -27,6 +27,22 @@ func (af *ApplicationInstanceFactory) AddHandler(ctype string, chandler func(*Ap
|
||||||
af.handlerMap[ctype] = chandler
|
af.handlerMap[ctype] = chandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (af *ApplicationInstanceFactory) GetHandlers() []string {
|
||||||
|
keys := make([]string, len(af.handlerMap))
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
for k := range af.handlerMap {
|
||||||
|
keys[i] = k
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
|
func (af *ApplicationInstanceFactory) GetHandler(ctype string) func(*ApplicationInstance) func() channels.Handler {
|
||||||
|
return af.handlerMap[ctype]
|
||||||
|
}
|
||||||
|
|
||||||
// GetApplicationInstance builds a new application instance using a connection as a base.
|
// GetApplicationInstance builds a new application instance using a connection as a base.
|
||||||
func (af *ApplicationInstanceFactory) GetApplicationInstance(rc *connection.Connection) *ApplicationInstance {
|
func (af *ApplicationInstanceFactory) GetApplicationInstance(rc *connection.Connection) *ApplicationInstance {
|
||||||
rai := new(ApplicationInstance)
|
rai := new(ApplicationInstance)
|
||||||
|
|
|
@ -40,9 +40,7 @@ func (ebi *EchoBotInstance) OpenInbound() {
|
||||||
|
|
||||||
func (ebi *EchoBotInstance) ChatMessage(messageID uint32, when time.Time, message string) bool {
|
func (ebi *EchoBotInstance) ChatMessage(messageID uint32, when time.Time, message string) bool {
|
||||||
log.Printf("message from %v - %v", ebi.rai.RemoteHostname, message)
|
log.Printf("message from %v - %v", ebi.rai.RemoteHostname, message)
|
||||||
go ebi.ra.Broadcast(func(rai *application.ApplicationInstance) {
|
ebi.SendChatMessage(ebi.rai, ebi.rai.RemoteHostname+" "+message)
|
||||||
ebi.SendChatMessage(rai, ebi.rai.RemoteHostname+" "+message)
|
|
||||||
})
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,14 +49,14 @@ func (ebi *EchoBotInstance) ChatMessageAck(messageID uint32, accepted bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ebi *EchoBotInstance) SendChatMessage(rai *application.ApplicationInstance, message string) {
|
func (ebi *EchoBotInstance) SendChatMessage(rai *application.ApplicationInstance, message string) {
|
||||||
rai.Connection.Do(func() error {
|
ebi.rai.Connection.Do(func() error {
|
||||||
channel := rai.Connection.Channel("im.ricochet.chat", channels.Outbound)
|
channel := ebi.rai.Connection.Channel("im.ricochet.chat", channels.Outbound)
|
||||||
if channel != nil {
|
if channel != nil {
|
||||||
chatchannel, ok := channel.Handler.(*channels.ChatChannel)
|
chatchannel, ok := channel.Handler.(*channels.ChatChannel)
|
||||||
if ok {
|
if ok {
|
||||||
chatchannel.SendMessage(message)
|
chatchannel.SendMessage(message)
|
||||||
}
|
}
|
||||||
}
|
} //TODO: else?
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,4 +27,4 @@ type Handler interface {
|
||||||
OnOpenChannelRequest(ctype string) (channels.Handler, error)
|
OnOpenChannelRequest(ctype string) (channels.Handler, error)
|
||||||
|
|
||||||
GetSupportedChannelTypes() []string
|
GetSupportedChannelTypes() []string
|
||||||
}
|
}
|
Reference in New Issue