abstract ws connection code from app code