Skip to content

Commit

Permalink
somehow working state
Browse files Browse the repository at this point in the history
  • Loading branch information
itzmanish committed Nov 2, 2024
1 parent 26aa1cf commit d0e4b71
Show file tree
Hide file tree
Showing 17 changed files with 586 additions and 622 deletions.
20 changes: 7 additions & 13 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"os/signal"
"syscall"
"time"

"net/http"

Expand All @@ -28,33 +27,28 @@ func main() {
http.Handle("/metrics", promhttp.Handler())
go http.ListenAndServe(":8080", nil)

// Create a deadline to wait for
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Start the SIP server
go func() {
if err := sipServer.Start(); err != nil {
if err := sipServer.Start(ctx); err != nil {
log.Fatal("Failed to start SIP server: " + err.Error())
}
}()

// Initialize and connect components
sipServer.mediaGateway.SetTranscodingService(sipServer.transcodingService)

// Start DTMF handler
sipServer.dtmfHandler.Start()

// Wait for interrupt signal to gracefully shutdown the server
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit

log.Info("Shutting down server...")

// Create a deadline to wait for
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
cancel()

// Doesn't block if no connections, but will otherwise wait
// until the timeout deadline.
if err := sipServer.Shutdown(ctx); err != nil {
if err := sipServer.Shutdown(); err != nil {
log.Error("Server forced to shutdown: " + err.Error())
}

Expand Down
156 changes: 0 additions & 156 deletions conferencing.go

This file was deleted.

8 changes: 8 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package sipnexus

type Config struct {
server ServerConfig
}

type ServerConfig struct {
}
21 changes: 5 additions & 16 deletions dtmf.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
type DTMFHandler struct {
logger logger.Logger
dtmfPayload uint8
eventChan chan string
eventHandlers map[string]func(string)
mu sync.RWMutex
}
Expand All @@ -21,20 +20,13 @@ func NewDTMFHandler(logger logger.Logger, dtmfPayload uint8) *DTMFHandler {
return &DTMFHandler{
logger: logger,
dtmfPayload: dtmfPayload,
eventChan: make(chan string, 100),
eventHandlers: map[string]func(string){},
}
}

func (d *DTMFHandler) Start() {
go d.processEvents()
}

func (d *DTMFHandler) processEvents() {
for event := range d.eventChan {
d.logger.Info(fmt.Sprintf("DTMF event received: %s", event))
d.notifyHandlers(event)
}
func (d *DTMFHandler) processEvent(event string) {
d.logger.Info(fmt.Sprintf("DTMF event received: %s", event))
d.notifyHandlers(event)
}

func (d *DTMFHandler) HandleDTMF(packet *rtp.Packet) error {
Expand All @@ -52,7 +44,7 @@ func (d *DTMFHandler) HandleDTMF(packet *rtp.Packet) error {
char := d.mapDTMFEventToChar(event)

if endOfEvent {
d.eventChan <- char
go d.processEvent(char)
}

return nil
Expand Down Expand Up @@ -112,10 +104,7 @@ func (d *DTMFHandler) notifyHandlers(event string) {
}

func (d *DTMFHandler) IntegrateWithPion(pc *webrtc.PeerConnection) {
pc.OnDTMF(func(dtmf *webrtc.DTMFSender) {
d.logger.Info("DTMF tone received via pion/WebRTC")
// Process DTMF tones received via WebRTC
})
// TODO: need to find a way to get DTMF tone in a call
}

func (d *DTMFHandler) ProcessDTMFEvent(event string, sessionID string) {
Expand Down
93 changes: 0 additions & 93 deletions gateway.go

This file was deleted.

Loading

0 comments on commit d0e4b71

Please sign in to comment.