First pass rewriting bcsocket in javascript