Recientemente estaba tratando de enviar un objeto MediaStream en javascript y noté que podía pero había un error. Use el siguiente código.
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]; } }); } Como no pude cambiar el objetivo... utilicé la solución anterior. Cada vez que intento llamar a MediaStream.getTracks() , obtengo TypeError: Illegal invocation Le agradecería su ayuda. La función funciona con cualquier otro objeto. y el 'objetivo' se cambia modificando la propiedad _stream_ . También me di cuenta de que esto
let x=new Proxy(stream,{}); x.getTracks()no funciona
Está bien para cualquier persona con un problema casi similar, logré evadir el error con el siguiente código.
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]; } }); }pero todavía no sé por qué existe el error en primer lugar. tal vez es un error, no lo sé.