Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js listen websocket

function listen(fn){
  fn=fn||console.log
  let property=Object.getOwnPropertyDescriptor
  (MessageEvent.prototype,"data")
  const data=property.get
  function lookAtMessage(){ //to replace get function
    let socket=this.currentTarget instanceof WebSocket
    if(!socket){return data.call(this)}
    let msg=data.call(this)
    Object.defineProperty(this,"data",{value:msg}) //anti-loop
    fn({data:msg,socket:this.currentTarget,event:this})
    return msg
  }
  property.get=lookAtMessage
  Object.defineProperty
  (MessageEvent.prototype,"data",property)
}
listen( ({data})=>console.log(data) )
Comment

PREVIOUS NEXT
Code Example
Javascript :: use navigation in class component react native drawer navigation 
Javascript :: sorting the object 
Javascript :: jquery basics 
Javascript :: string in js 
Javascript :: cast string to int angular 
Javascript :: datatable hide no data available in table 
Javascript :: json to csv 
Javascript :: jquerey dropdown button 
Javascript :: remove last character from string javascript 
Javascript :: laravel json eloquent 
Javascript :: calendar picker react js 
Javascript :: solidity payable 
Javascript :: how to get last element of an array 
Javascript :: ArduinoJson.h 
Javascript :: toggle buttons angular styles 
Javascript :: slide js 
Javascript :: axios delete 
Javascript :: get jsonp with fetch 
Javascript :: .then function 
Javascript :: unexpected end of json input 
Javascript :: Find Largest Number by function by javascript 
Javascript :: typescript base64 from file 
Javascript :: use node modules in next.js 
Javascript :: JavaScript Access Elements of an Array 
Javascript :: Sets can be used to store __________. in js 
Javascript :: how to pass functions as a props in react js 
Javascript :: react autocomplete 
Javascript :: js function definition 
Javascript :: variables in javascript 
Javascript :: discord.js reply to message author 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =