Intel® Collaboration Suite for WebRTC
Community support and discussions on the Intel® Collaboration Suite for WebRTC (Intel® CS for WebRTC).
Announcements
Intel Customer Support will be observing the Martin Luther King holiday on Monday, Jan. 17, and will return on Tues. Jan. 18.
For the latest information on Intel’s response to the Log4j/Log4Shell vulnerability, please see Intel-SA-00646
1135 Discussions

'class extends' syntax with JavaScript client bundle

Nozhenko__Sergey
Beginner
217 Views

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.

0 Kudos
3 Replies
Jianjun_Z_Intel
Employee
217 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. 

Nozhenko__Sergey
Beginner
217 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?

Jianjun_Z_Intel
Employee
217 Views

Hi Sergey,

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

Reply