https://github.com/garronej/omniobserver
https://github.com/garronej/omniobserver
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/garronej/omniobserver
- Owner: garronej
- License: mit
- Created: 2019-06-02T14:19:45.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-03T09:06:11.000Z (about 6 years ago)
- Last Synced: 2025-02-05T11:18:49.846Z (4 months ago)
- Language: TypeScript
- Size: 27.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# omniobserver
NOTE: Chrome debugger will show detailed call stack.
Example observing WebRTC and the event listener on RTCPeerConnection.
```typescript
/** will observe getUserMedia and RTCPeerConnection */
export function observeWebRTC() {observeObjectProperty(navigator.mediaDevices, "getUserMedia");
observeObjectProperty(window, "RTCPeerConnection", (rtcPeerConnection: RTCPeerConnection) => {console.log(rtcPeerConnection);
if( !!rtcPeerConnection.getStats ){
setTimeout(()=>{
rtcPeerConnection.getStats().then(
stats=> {const arr: any[]= [];
stats.forEach(o => {
console.log(JSON.stringify(o));
arr.push(o);
});
console.log("<======>");
console.log(JSON.stringify(arr));
}
);},20000);
}
const {
addEventListener: addEventListenerBackup,
removeEventListener: removeEventListenerBackup
} = rtcPeerConnection;const proxyByOriginal = new WeakMap();
Object.defineProperties(
rtcPeerConnection,
{
"addEventListener": {
"configurable": true,
"enumerable": true,
"value": function addEventListener(type: string, listener: Function) {const listenerProxy = function (...args) {
console.log(`RTCPeerConnectionEvent: "${type}"`, args);
return listener.apply(rtcPeerConnection, args);
};
proxyByOriginal.set(listener, listenerProxy);
return addEventListenerBackup.call(rtcPeerConnection, type, listenerProxy);
}
},
"removeEventListener": {
"configurable": true,
"enumerable": true,
"value": function removeEventListener(type: string, listener: Function) {
return removeEventListenerBackup.call(rtcPeerConnection, type, proxyByOriginal.get(listener));
}
}}
);});
}
```