-
-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Abstract signaling server messages #62
base: master
Are you sure you want to change the base?
Conversation
@@ -666,4 +696,10 @@ export class WebrtcProvider extends Observable { | |||
}) | |||
super.destroy() | |||
} | |||
|
|||
addSignalingConn(url, conn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conn
is technically a function. Maybe we need to call it createT
or something similar?
const topics = Array.from(rooms.keys()) | ||
topics.forEach(topic => | ||
this.subscribe(topic) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Azure Web PubSub cannot join multiple groups, but that shouldn't stop the built-in client from doing so. Maybe instead of the forEach
this needs a subscribeMulti()
method or let subscribe()
detect whether topic
is an array in derived classes and do the iteration there?
@dmonad do you have any feedback on this approach or if it is even feasible to do this level of refactoring in your module? |
Hi @byrond, first of all, thanks for contributing to this repository! I manage a lot of different tools, and I'm always hesitant to merge new features. I prefer simplicity over extensibility because simple projects are easier to maintain. Any new feature that is introduced causes at least one more bug that I have to fix. At this time, this feature is not a priority for me. That said, I think the approach is valid. I haven't done a full review yet. If you gather more support, I might merge this feature into the next major release. Btw, this repository is fully typed using jsdoc comments (I prefer that over typescript files). If you do |
Issue #11 provides a solution for using a different type of signaling server. However, certain parts of y-webrtc make assumptions about the messages being sent through the signaling server. This is a suggestion for refactoring some of the code to make it possible to swap out
SignalingConn
with a derived class.In our case, we wanted to use Azure Web PubSub as the signaling server, and Microsoft uses slightly different message formats, event names, and terminology (i.e. "join groups" instead of "subscribe to topics", "group-message" instead of a "message" event, etc.).
Here is our example code where we have derived classes from
SignalingConn
andWebrtcProvider
using the refactored y-webrtc in this PR. It uses the Azure Web PubSub client from Microsoft.The following refactoring was done:
WebsocketClient
and creates a property to hold an instance of it.subscribe
,unsubscribe
, andpublish
methods forSignalingConn
so external code doesn't need to know how to format signaling server messages.connected
method, since clients may determine signaling server connectivity differently.setupClient
method which can be overridden to use a different signaling server client (ex: Azure Web PubSub client) including differing message event names (ex:message
vsgroup-message
)rooms
iteration into ahandleConnect
method, so that global set does not have to be exported and used in derived classes.handleMessage
method so the logic can be reused and does not need to be included in the clientmessage
event definitions of derived classes.Questions
Overriding
WebrtcProvider
just to change the class used for signaling connections seems excessive. Is there a way we can pass this into the base WebrtcProvider instead? Maybe create a factory method that we can override in a derived class.This is the only line we need to change in the
connect()
method:const signalingConn = map.setIfUndefined(signalingConns, url, () => new SignalingConn(url))
What about this needs to be cleaned up to prevent introducing TypeScript errors if/when
y-webrtc.js
is converted to TS?