You have to consider different cases. Let's take an example: $f:[-2,2] \rightarrow \mathbb{R}$ defined by $f(x)=x^2$, now consider $f:[-1,1]\rightarrow \mathbb{R}$ and choose $\epsilon=1$, then if we take $\delta=\frac{1}{2}$ see that whenever $x,y \in [-1,1]$ and $|x-y|<\frac{1}{2}$, $|f(x)-f(y)|<1$. But if you take $x=0.9,y=1.35$, then also $|x-y|=0.45<\frac{1}{2}$ but $|f(x)-f(y)|=1.0125>1$. So one $\delta$ doesn't work for all $|x-y|<\delta$.
For given $\epsilon>0~\exists~M_1,M_2 >0$ such that $|f(x)-a|<\frac{\epsilon}{2}$ whenever $x<-M_1$ and $|f(x)-b|<\frac{\epsilon}{2}$ whenever $x>M_2$. Let $M=\max\{M_1,M_2\}$.
So there will be the following cases:
(i) $x,y<-M$, (ii) $x,y>M$, (iii) $x,y \in [-M,M]$, (iv) $x \in [-M,M],~y<-M$, (v) $x \in [-M,M],~y>M$ and (vi) $x<-M,~y>M$, (where $M>0$ is what we got from the definition of limit at infinity).
(i) Let $x,y<-M(\leq-M_1)$, then $|f(x)-f(y)|=|f(x)-a-f(y)+a|\leq |f(x)-a|+|f(y)-a|<\epsilon$. So no specific role of $\delta $ here.
(ii) is done similarly.
From (iii) for chosen $\epsilon>0$ we get a $\delta_1>0$ such that $|f(x)-f(y)|<\epsilon$ whenever $|x-y|<\delta_1$ (using the fact that continuous function on compact set is uniformly continuous).
For (iv) we have to the continuity of $f$ at $-M$, for chosen $\epsilon>0~~~\exists~\delta_2>0$ such that $|f(x)-f(-M)|<\frac{\epsilon}{2}$ whenever $|x-(-M)|<\delta_2$. For $|f(x)-f(y)|$ to be small enough $x,y$ can't be too far apart and $x,y$ should belong to $(-M-\frac{\delta_2}{2},-M+\frac{\delta_2}{2})$. Now if we take $|x-y|<\frac{\delta_2}{2}$ then since $|x-(-M)|\leq |x-y|+|y+M|<\frac{\delta_2}{2}+\frac{\delta_2}{2}=\delta_2$ and similarly $|y-(-M)|<\delta_2$ we get $|f(x)-f(y)|<\epsilon$ whenever $|x-y|<\frac{\delta_2}{2}$.
For (v) similarly using continuity of $f$ at $M$ we get a $\frac{\delta_3}{2}$.
Note that we have to find a $\delta>0$ for which the definition of uniform continuity is satisfied. So we take $\delta =\frac{1}{2}\min\{\delta_1, \frac{\delta_2}{2}, \frac{\delta_3}{2},2M\}$ (if certain $\delta$ works, then so will anything less than that $\delta$, so multiplying by 0.5 doesn't violate anything! It just helps with the strict inequalities. You may not take it if you wish. Actually we could have also simply taken $\epsilon$ instead of $\frac{\epsilon}{2}$ in the beginning.). Because in the case of (vi) $|x-y|\geq 2M$ and $\delta<2M$ (why strict inequality?!), we don't have to actually consider (vi).
All in all now $|x-y|<\delta\Rightarrow |f(x)-f(y)|<\epsilon$.