ParseWebRTCSignalMessage parses the web rtc command/message
(msg string)
| 66 | |
| 67 | // ParseWebRTCSignalMessage parses the web rtc command/message |
| 68 | func ParseWebRTCSignalMessage(msg string) (*WebRTCSignalMessage, error) { |
| 69 | // All messages are text (utf-8 encoded at present) |
| 70 | if !utf8.Valid([]byte(msg)) { |
| 71 | return nil, errInvalidChar |
| 72 | } |
| 73 | |
| 74 | w := &WebRTCSignalMessage{} |
| 75 | if err := json.Unmarshal([]byte(msg), w); err != nil { |
| 76 | return nil, err |
| 77 | } |
| 78 | |
| 79 | if err := validateOperation(w.Type); err != nil { |
| 80 | return nil, err |
| 81 | } |
| 82 | |
| 83 | return w, nil |
| 84 | } |
| 85 | |
| 86 | func validateOperation(op string) error { |
| 87 | switch strings.ToUpper(op) { |