Jump to content
  • 1

Best way to override JS SDK functions


rahul7827
 Share

Question

Hello Members

Suggest me how to override the functions of JS SDK.

Sometimes I need to add OR customize the javascript source code as per our requirement.

Since writing custom functions inside JS SDK is risky, since after npm install everything gets reset.

What i have figured out is :

Create a separate .js file and import it at the bottom of media_manager.js and override the function
which i need like this

 
initializeDummyFrame(){
        this.dummyCanvas.getContext('2d').fillRect(0, 0, 320, 240);
        this.replacementStream = this.dummyCanvas.captureStream();
}
 

Now overriding like this

 
OR_initializeDummyFrame() {
 
initializeDummyFrame = function() {
let w = width_of_video_frame
let h = height_of_video_frame
        this.dummyCanvas.getContext('2d').fillRect(0, 0, w, h);
        this.replacementStream = this.dummyCanvas.captureStream();
}

}

 

 

By using this way I only have to add my custom .js file once, when i use "npm install".

@mustafaboleken and @Selim Is this the right way ? or If we can improve it please suggest.

 

Thank you

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
3 hours ago, rahul7827 said:

Hello Members

Suggest me how to override the functions of JS SDK.

Sometimes I need to add OR customize the javascript source code as per our requirement.

Since writing custom functions inside JS SDK is risky, since after npm install everything gets reset.

What i have figured out is :

Create a separate .js file and import it at the bottom of media_manager.js and override the function
which i need like this

 
initializeDummyFrame(){
        this.dummyCanvas.getContext('2d').fillRect(0, 0, 320, 240);
        this.replacementStream = this.dummyCanvas.captureStream();
}
 

Now overriding like this

 
OR_initializeDummyFrame() {
 
initializeDummyFrame = function() {
let w = width_of_video_frame
let h = height_of_video_frame
        this.dummyCanvas.getContext('2d').fillRect(0, 0, w, h);
        this.replacementStream = this.dummyCanvas.captureStream();
}

}

 

 

By using this way I only have to add my custom .js file once, when i use "npm install".

@mustafaboleken and @Selim Is this the right way ? or If we can improve it please suggest.

 

Thank you

In the context of object oriented design patterns , such problems are normally solved by using adapter pattern or decorator pattern. These patterns will allow you to wrap functionality around the core. This can also be done on code design level. I would really suggest looking into these two patterns for design sake.

  • Like 2
Link to comment
Share on other sites

 Share

×
×
  • Create New...