cloudwebrtc / go-protoo

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

Protoo Changes #6

Closed jbrady42 closed 4 years ago

jbrady42 commented 4 years ago

Changed the internal event based api to channel based. Exactly the same message handling, but each transport and peer is managed by a single goroutine. This makes it earlier to reason about the threading implications of the code, vs the event dispatch where every handler runs in an isolated goroutine.

The request API is also updated to provide a response channel the client can listen on instead of using the success and fail callbacks. The callback code is left in place to maximize compatibility and the new channels will only be used if nil is passed in place of callbacks.

The websocket transport read/write handlers were split into separate goroutines. The shutdown sequence was reworked. Calling close on the transport signals the write loop to exit and then close the underlying socket. At which point the client fires the close event. This will trigger a read error if the read loop is currently blocked, and the read loop will exit.

If there is a read error, the read loop exits signaling transport shutdown and the previous sequence takes over.

Client and server both use the same transport read/write loop now.

Finally the "ping" keepalive messages were changed to use ping message type from the socket library vs sending empty messages.

Go examples also updated.

This was developed and tested with https://github.com/jbrady42/ion-load. The required changes to integrate Ion are here https://github.com/pion/ion/commit/87ff90409e2c2ee8bb99d710c7b09ab04e4d5dce

Squash on merge

cloudwebrtc commented 4 years ago

LGTM!