check for null listener before calling listener.onMessage