Skip to content

Commit eb969c5

Browse files
authored
Merge pull request #6 from spacetourist/master
Patched type issue
2 parents c4495ef + 9e0d676 commit eb969c5

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

message.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,26 @@ func (m *Message) Parse() error {
120120
return fmt.Errorf(EUnsuccessfulReply, string(m.Body)[5:])
121121
}
122122
case "text/event-json":
123-
if err := json.Unmarshal(m.Body, &m.Headers); err != nil {
123+
// OK, what is missing here is a way to interpret other JSON types - it expects string only (understandably
124+
// because the FS events are generally "string: string") - extract into empty interface and migrate only strings.
125+
// i.e. Event CHANNEL_EXECUTE_COMPLETE - "variable_DP_MATCH":["a=rtpmap:101 telephone-event/8000","101"]
126+
var decoded map[string]interface{}
127+
128+
if err := json.Unmarshal(m.Body, &decoded); err != nil {
124129
return err
125130
}
126131

132+
// Copy back in:
133+
for k, v := range decoded {
134+
switch v.(type) {
135+
case string:
136+
m.Headers[k] = v.(string)
137+
default:
138+
//delete(m.Headers, k)
139+
Warning("Removed non-string property (%s)", k)
140+
}
141+
}
142+
127143
if v, _ := m.Headers["_body"]; v != "" {
128144
m.Body = []byte(v)
129145
delete(m.Headers, "_body")

0 commit comments

Comments
 (0)