How to disable phone speaker during Audio Call


we are using Jisti SDK for our chat application for IOS/ Android and we have an issue during the Audio call that call use a phone speaker which makes the call very loud.
and when we tried to close the speaker the call didn’t work

Any advice on how we can fix that?