rahul7827 Posted November 14, 2022 Share Posted November 14, 2022 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 More sharing options...
0 Connessione Posted November 14, 2022 Share Posted November 14, 2022 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. 2 Link to comment Share on other sites More sharing options...
0 rahul7827 Posted November 14, 2022 Author Share Posted November 14, 2022 Thanks @Connessione for your suggestion. It helped me learning this concept. I was not aware that this can also be done in such a way. Really its a great solution, I went through Adapter Pattern. Thank you 🙂 1 Link to comment Share on other sites More sharing options...
0 Connessione Posted November 14, 2022 Share Posted November 14, 2022 You are welcome @rahul7827🙂 Link to comment Share on other sites More sharing options...
Question
rahul7827
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
Now overriding like this
let h = height_of_video_frame
}
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
Top Posters For This Question
2
2
Popular Days
Nov 14
4
Top Posters For This Question
rahul7827 2 posts
Connessione 2 posts
Popular Days
Nov 14 2022
4 posts
Popular Posts
Connessione
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
rahul7827
Thanks @Connessione for your suggestion. It helped me learning this concept. I was not aware that this can also be done in such a way. Really its a great solution, I went through Adapter Pat
3 answers to this question
Recommended Posts