Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for an optional connection up/down buffered channel to the client. #174

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0perl <[email protected]>
Dan Cropp <[email protected]>
Danil Matyukhin <[email protected]>
JAF <[email protected]>
Laurel Lawson <[email protected]>
Expand Down
17 changes: 10 additions & 7 deletions bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ type BridgeData struct {
// Key is the cluster-unique identifier for this bridge
Key *Key `json:"key"`

ID string `json:"id"` // Unique Id for this bridge
Class string `json:"bridge_class"` // Class of the bridge
Type string `json:"bridge_type"` // Type of bridge (mixing, holding, dtmf_events, proxy_media)
ChannelIDs []string `json:"channels"` // List of pariticipating channel ids
Creator string `json:"creator"` // Creating entity of the bridge
Name string `json:"name"` // The name of the bridge
Technology string `json:"technology"` // Name of the bridging technology
ID string `json:"id"` // Unique Id for this bridge
Class string `json:"bridge_class"` // Class of the bridge
Type string `json:"bridge_type"` // Type of bridge (mixing, holding, dtmf_events, proxy_media)
ChannelIDs []string `json:"channels"` // List of pariticipating channel ids
Creator string `json:"creator"` // Creating entity of the bridge
Name string `json:"name"` // The name of the bridge
Technology string `json:"technology"` // Name of the bridging technology
CreationTime string `json:"creationtime"` // Creation Time
VideoMode string `json:"video_mode"` // Video mode the bridge is using. (none, talker, sfu, single)
VideoSourceID string `json:"video_source_id"` // The ID of the channel that is the source of video in this bridge, if one exists.
}

// BridgeAddChannelOptions describes additional options to be applied to a channel when it is joined to a bridge
Expand Down
29 changes: 26 additions & 3 deletions client/native/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type Options struct {

// Logger provides a logger which should be used for this client.
Logger *slog.Logger

// buffered channel for sending Connection Up (true) or Down (false) messages to the caller
ChanMsgConnected chan bool
}

// ConnectWithContext creates and connects a new Client to Asterisk ARI.
Expand Down Expand Up @@ -191,7 +194,14 @@ func (c *Client) Close() {
c.cancel()
}

c.connected = false
if c.connected {
c.connected = false
if c.Options.ChanMsgConnected != nil {
c.Options.ChanMsgConnected <- false
}
}

c.Options.ChanMsgConnected = nil
}

// Application returns the ARI Application accessors for this client
Expand Down Expand Up @@ -375,6 +385,9 @@ func (c *Client) listen(ctx context.Context, wg *sync.WaitGroup) {

// We are connected
c.connected = true
if c.Options.ChanMsgConnected != nil {
c.Options.ChanMsgConnected <- true
}

// Signal that we are connected (the first time only)
if wg != nil {
Expand All @@ -387,13 +400,23 @@ func (c *Client) listen(ctx context.Context, wg *sync.WaitGroup) {
case err = <-c.wsRead(ws):
c.Options.Logger.Error("read failure on websocket", "error", err)

c.connected = false
if c.connected {
c.connected = false
if c.Options.ChanMsgConnected != nil {
c.Options.ChanMsgConnected <- false
}
}

time.Sleep(10 * time.Millisecond)
}

// Make sure our websocket connection is closed before looping
c.connected = false
if c.connected {
c.connected = false
if c.Options.ChanMsgConnected != nil {
c.Options.ChanMsgConnected <- false
}
}

err = ws.Close()
if err != nil {
Expand Down