あなたが新しいものに送信機能を複製して、あなたのログを追加して、元の関数を上書きすることができます。 websocketインスタンスを作成するたびにそれを行う必要があります。
これはあなたがそれを行う方法です。
//First, create a clone prototype
Function.prototype.clone = function() {
var that = this;
var temp = function temporary() { return that.apply(this, arguments); };
for(var key in this) {
if (this.hasOwnProperty(key)) {
temp[key] = this[key];
}
}
return temp;
};
//Then, when you create your ws object, use the clone function to copy the "send". For example, you can name the new function "parentSend"
ws = new WebSocket('ws://mystuff.com');
ws.parentSend = ws.send.clone();
//Finally, recode a new send function, with the logs, and the call to parentsend()
ws.send = function(msg){
console.log(msg);
this.parentSend(msg);
};
これは、私たちはws.sendを呼び出すたび簡単な方法
var ws = new WebSocket("ws://example.com:80");
ws.oldSend = ws.send;
ws.send = function(data) {
ws.oldSend(data);
console.log('Captured data:', data);
};`
は今、それが私たちの再定義WSを呼び出し、それをやった