Add onclose and reconnect functions