@@ -20,6 +20,7 @@ func completer(d prompt.Document) []prompt.Suggest {
2020 {Text : "users" , Description : "Show sip accounts" },
2121 {Text : "onlines" , Description : "Show online sip devices" },
2222 {Text : "calls" , Description : "Show active calls" },
23+ {Text : "originate" , Description : "Originate a call and bridge to another call" },
2324 {Text : "set debug on" , Description : "Show debug msg in console" },
2425 {Text : "set debug off" , Description : "Turn off debug msg in console" },
2526 {Text : "show loggers" , Description : "Print Loggers" },
@@ -39,6 +40,21 @@ Options:
3940
4041func consoleLoop (b2bua * b2bua.B2BUA ) {
4142
43+ usersCompleter := func (d prompt.Document ) []prompt.Suggest {
44+ accounts := b2bua .GetAccounts ()
45+ s := make ([]prompt.Suggest , 0 , len (accounts ))
46+ for user := range accounts {
47+ s = append (s , prompt.Suggest {Text : user , Description : "User" })
48+ }
49+ aors := b2bua .GetRegistry ().GetAllContacts ()
50+ for aor := range aors {
51+ for _ , instance := range aors [aor ] {
52+ s = append (s , prompt.Suggest {Text : instance .Contact .Address .String (), Description : "online device" })
53+ }
54+ }
55+ return prompt .FilterHasPrefix (s , d .GetWordBeforeCursor (), true )
56+ }
57+
4258 fmt .Println ("Please select command." )
4359 for {
4460 t := prompt .Input ("CLI> " , completer ,
@@ -74,14 +90,20 @@ func consoleLoop(b2bua *b2bua.B2BUA) {
7490 } else {
7591 fmt .Printf ("No users\n " )
7692 }
93+ case "originate" :
94+ fmt .Printf ("Please enter the source user: " )
95+ source := prompt .Input ("Source> " , usersCompleter )
96+ fmt .Printf ("Please enter the destination user: " )
97+ destination := prompt .Input ("Destination> " , usersCompleter )
98+ b2bua .Originate (source , destination )
7799 case "calls" :
78100 fallthrough
79101 case "cl" : /* call list*/
80102 calls := b2bua .Calls ()
81103 if len (calls ) > 0 {
82104 fmt .Printf ("Calls:\n " )
83105 for _ , call := range calls {
84- fmt .Printf ("%v: \n " , call .ToString ())
106+ fmt .Printf ("%v\n " , call .ToString ())
85107 }
86108 } else {
87109 fmt .Printf ("No active calls\n " )
0 commit comments