ParsePayload parses the payload if it is not parsed previously. This method can be called concurrently.
()
| 48 | // ParsePayload parses the payload if it is not parsed previously. This method |
| 49 | // can be called concurrently. |
| 50 | func (w *WebRTCSignalMessage) ParsePayload() (*Payload, error) { |
| 51 | w.mu.Lock() |
| 52 | defer w.mu.Unlock() |
| 53 | |
| 54 | if w.isParsed { |
| 55 | return w.parsedPayload, nil |
| 56 | } |
| 57 | |
| 58 | payload := &Payload{} |
| 59 | if err := json.Unmarshal(w.Payload, payload); err != nil { |
| 60 | return nil, err |
| 61 | } |
| 62 | |
| 63 | w.parsedPayload = payload |
| 64 | return payload, nil |
| 65 | } |
| 66 | |
| 67 | // ParseWebRTCSignalMessage parses the web rtc command/message |
| 68 | func ParseWebRTCSignalMessage(msg string) (*WebRTCSignalMessage, error) { |