Logic for connect, disconnect and messages ready. animationFrame ptch applied. Needs code organization.