Javascript code to receive messages