Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
How can i proxy a mediastream object without TypeError: Illegal invocation

I recently was trying to proxy a MediaStream Object in javascript And noticed i could but there was an error. I used the following code.


function createChangeableStream(stream) {
                    stream["_stream_"]=stream;
                        return new Proxy(stream,{
                    set: function(obj, prop, value){
                          if(prop==="_stream_")
                             obj._stream_=value;
                          else
                             obj._stream_[prop]=value;
                    },
                    get: function(obj, prop) {
                         if(prop==="_stream_")
                             return obj._stream_;
                         else
                             return obj._stream_[prop];
                    }
                });
                }

since i could not change the target... i used the above workaround. Each time i try to call MediaStream.getTracks(), i get TypeError: Illegal invocation I would be grateful for your help. The function works with any other objects. and the 'target' is changed by modifying _stream_ property. I also realized that this

let x=new Proxy(stream,{});
x.getTracks()

doesn't work.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Okay for anyone with almost similar problem i succeeded evading the error with the following code.

function createChangeableStream(stream) {
                    stream["_stream_"]=stream;
                    stream["_call_handler_"]=function (obj,prop,args) {
                        return obj[prop](...args);
                    }
                        return new Proxy(stream,{
                    set: function(obj, prop, value){
                          if(prop==="_stream_")
                             obj._stream_=value;
                          else
                             obj._stream_[prop]=value;
                    },
                    get: function(obj, prop) {
                         if(prop==="_stream_")
                             return obj._stream_;
                         else if((typeof obj._stream_[prop])==="function"){
                              return function () {
                                 return obj._call_handler_(obj._stream_,prop,[...arguments]);
                              } 
                          }else
                             return obj._stream_[prop];
                    }
                });
                }

but i still don't know why the error exists at the first place. maybe its a bug, i don't know.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!