CyCoreSystems / ari

Golang Asterisk REST Interface (ARI) library
Apache License 2.0
189 stars 73 forks source link

ari 3.0 - event filtering #50

Closed sheenobu closed 8 years ago

sheenobu commented 8 years ago

We've discussed event filtering via these single method interfaces:

type ChannelEvent interface {
   GetChannelID() string
}

Issue

Certain events have multiple channel IDs, for example BridgeBlindTransfer:

type BridgeBlindTransfer struct {
   Bridge BridgeData
   Channel ChannelData
   ReplaceChannel ChannelData
   Transferee ChannelData
}

There is only one Bridge but multiple Channels.

  1. Should we just use one channel on GetChannelID()? so we only filter on one specific channel field?
  2. Should we refactor our filtering mechanism?

    Refactoring

// Matcher is an interface Handles can implement to provide event filtering
type Matcher interface {
   Matches(evt ari.Event) bool
}

// ChannelEvent allows arbitrary events to give a Matcher a series of Channel IDs to operate on.
type ChannelEvent interface {
   GetChannelIDs() []string // multiple ID support
}

// Example code:

var channelHandle ChannelHandle
evt <- sub.Events()
if !channelHandle.Matches(evt) {
   //ignore event 
} else {
  // process event
}

Writing this up.... I think I'll go with the refactoring anyway. That will move the event filtering logic from the individual Subscribe implementations in client/native and client/nc into the main ari package and each client only needs to call handle.Matches(evt) before dispatching to the subscription.

sheenobu commented 8 years ago

This is done. Keeping open for documentation

sheenobu commented 8 years ago

Moved to wiki