cloudwebrtc / go-protoo

A minimalist and extensible go signaling framework for WebRTC.
MIT License
23 stars 6 forks source link

Use raw JSON for data payloads #5

Closed jbrady42 closed 4 years ago

jbrady42 commented 4 years ago

Replace usage of map[string]interface{} in peer with go json.RawMessage type. This allows us to keep the data opaque and let the client handle it using normal json decoding. The benefit here is both parties can share a strong JSON contract instead of first checking, then casting fields from interface{} they hope are there. https://golang.org/pkg/encoding/json/#RawMessage

Additionally parse messages into their appropriate type before handling. This made some of the request handing easier to read/code as we can naturally call request.Method and response.Id now without any casting.

For an example of the work needed to integrate these changes into Ion, take a look at this PR which uses the protoo client to join an Ion room and publish a stream. https://github.com/jbrady42/ion-vid/pull/1

cloudwebrtc commented 4 years ago

LGTM