Community
cancel
Showing results for 
Search instead for 
Did you mean: 
12 Views

'class extends' syntax with JavaScript client bundle

Recently I tried to rewrite some code using OWT JavaScript client with nice modern class syntax. The idea was, for example, to derive a custom client from ConferenceClient. With this I run into a problem: whatever is used for bundling the client API messes with the prototype of the constructed object in such a way that is incompatible with the class/extends mechanics. Specifically, it replaces the prototype of derived object with the base prototype, and thus all methods from the derived prototype become unavailable:

class MyClient extends Owt.Conference.ConferenceClient {
   myMethod() {}
}
new MyClient().myMethod(); // TypeError: myMethod is not a function

To tell the truth, this is not a major issue, but probably worth to consider as the new syntax becomes more commonly used. A sample file that demonstrates the error is attached. I tested it in the latest Chrome and Firefox.

Tags (2)
0 Kudos
3 Replies
Highlighted
12 Views

Hi Sergey,

Thanks for reporting this issue.

Starting from v4.0, we're moving to modern JavaScript syntax. You may find that most classes are declared with the class keyword. However, ConferenceClient is not. I guess the following code (https://github.com/open-webrtc-toolkit/owt-client-javascript/blob/d727af2927731ff16214d73f57964a992258636d/src/sdk/conference/client.js#L107) might be the reason of your issue.

Object.setPrototypeOf(this, new EventModule.EventDispatcher());

Right now, we don't have resource to fix this issue immediately. As OWT is an open source project, you could clone the project and try to fix it locally. Your PRs are welcomed. 

0 Kudos
Highlighted
12 Views

Hi Jianjun,

Thank you for the explanation. This seems to be the reason indeed. Somehow I didn't notice that ConferenceClient is not declared with the class syntax. I wonder though, what is there to fix? Why not just declare it as a class extending EventDispatcher instead of setting the prototype explicitly? Other classes (Participant, Subscription, etc) are made just that way. What's wrong with the ConferenceClient?

0 Kudos
Highlighted
12 Views

Hi Sergey,

Classes like Publication, Subscription was added since v4.0 while ConferenceClient was there for a very long time.

0 Kudos