Add onOpen and onClose callbacks.