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
Replace usage of
map[string]interface{}
in peer with gojson.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 frominterface{}
they hope are there. https://golang.org/pkg/encoding/json/#RawMessageAdditionally 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
andresponse.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