Fish warn each other about danger by releasing chemicals into the water as a signal, research has found.