Added callbacks for onOpen and onClose

New lines 65-66, 117-119, 156-158, 197-198, 219-220