Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda