Solving the callback problems using instance variables
Beatify
Call onMessageReceived when connection opens
Replace the message types with digits on server side
Using "that" to access the instance variables inside onmessage event