We are given:
\[
\left(x \sin \frac{y}{x} \right) dy = \left( y \sin \frac{y}{x} - x \right) dx
\]
Step 1: Rewrite the equation.
\[
x \sin \left( \frac{y}{x} \right) \, dy = \left[ y \sin \left( \frac{y}{x} \right) - x \right] dx
\]
Step 2: Use the substitution \( v = \frac{y}{x} \Rightarrow y = vx \Rightarrow dy = v\,dx + x\,dv \)
Substitute in the equation:
\[
x \sin(v) (v\,dx + x\,dv) = \left( vx \sin(v) - x \right) dx
\]
Expand both sides:
\[
xv \sin(v) \, dx + x^2 \sin(v) \, dv = x v \sin(v) \, dx - x \, dx
\]
Cancel \( x v \sin(v) dx \) from both sides:
\[
x^2 \sin(v) \, dv = -x \, dx
\]
Step 3: Separate variables.
\[
x \sin(v) \, dv = - \, dx
\]
Step 4: Integrate both sides.
\[
\int \sin(v) \, dv = -\int \frac{1}{x} \, dx
\]
\[
- \cos(v) = - \log |x| + c
\Rightarrow \cos\left( \frac{y}{x} \right) = \log |x| + c
\]
% Final Answer
\[
\boxed{ \cos\left( \frac{y}{x} \right) = \log |x| + c }
\]