0x19 / goesl

Freeswitch Event Socket Library wrapper for Go
https://godoc.org/github.com/0x19/goesl
MIT License
127 stars 124 forks source link

events of json type don't have their Content-Type header set #15

Open regner opened 6 years ago

regner commented 6 years ago

Sample code:

// Setup, connection handling, etc.

b := bytes.NewBufferString("event json DTMF\n")
b.WriteTo(conn)

// Some other code and then this runs in a goroutine for us

for {
    msg, err := conn.ReadMessage()

    // For JSON events this ends up being ""
    msgType := msg.GetHeader("Content-Type")

    switch msgType {
    case "text/disconnect-notice":
        done <- true
    case "text/event-plain":
        // assuming "event plain DTMF" is sent instead of JSON this will trigger
    case "text/event-json":
        // This will never trigger
    }

    //This is my current hack
    if eventName, ok := msg.Headers["Event-Name"]; ok {
        switch eventName {
        case "DTMF":
            logger.Errorf("DTMF: %s", msg.Headers["DTMF-Digit"])
        }
    }
}

Our current version of gesl: revision = "1cd1251c682b6645e93bdc58ba48de5ed75fbd48" version = "1.0"