  A $\gamma$-ray source must have a limited optical depth to pair production.
This simple condition, called compactness, implies that gamma-ray bursts (GRBs)
must involve a highly relativistic motion ($\Gamma \gtrsim 100$) giving the
first and most important clue on their nature. So far, this condition has been
discussed under the assumption that the $\gamma$-ray sources are viewed
on-axis, that is, by an observer within the beaming cone of the relativistic
source. Recently, following the detection of the weak short GRB 170817A, an
extensive interest arose in the possibility that some $\gamma$-ray sources are
viewed off-axis. We generalize here the compactness formalism for an arbitrary
viewing angle taking several possible opacity processes and $\gamma$-ray
spectra into account. We find that for a given observables (peak luminosity,
temporal variability, and spectra) the minimal Lorentz factor, $\Gamma_{\rm
min}$, is obtained, as expected, for an on-axis observer. More remarkably we
find that compactness dictates also a maximal viewing angle, $\theta_{\rm max}
\simeq 1/2\Gamma_{\rm min}$. Our limit implies for regular GRBs a very small
allowed viewing angle ($\lesssim10^{-2}\,\rm rad$), making it extremely
unlikely that they are viewed off-axis. For GRB 170817A we confirm earlier
results that rule out the possibility that the observed $\gamma$-rays were seen
by an on-axis observer as a regular short GRB. The short GRB 150101B was also
suggested to be an off-axis event. We show that its maximal viewing angle
$\lesssim0.05\,\rm rad$, which is inconsistent with the off-axis model. Finally
we show that for low luminosity GRBs, compactness does not exclude by itself an
off-axis model, but when combined with other consideration this option is
strongly disfavored.
