Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda