react-native-tele
Version:
Telecommunication module based on InCall and android.telecom Java for React Native
109 lines (84 loc) • 3.37 kB
Plain Text
package one.telefon.tele;
//import one.telefon.tele.dto.AccountConfigurationDTO;
import org.json.JSONObject;
public class TeleAccount /*extends Account*/ {
private static String TAG = "one.telefon.tele.TeleAccount";
/**
* Last registration reason.
*/
private String reason;
private TeleService service;
//private AccountConfigurationDTO configuration;
private Integer transportId;
public TeleAccount(TeleService service, int transportId, AccountConfigurationDTO configuration) {
this.service = service;
this.transportId = transportId;
this.configuration = configuration;
}
public void register(boolean renew) throws Exception {
setRegistration(renew);
}
public TeleService getService() {
return service;
}
public int getTransportId() {
return transportId;
}
public AccountConfigurationDTO getConfiguration() {
return configuration;
}
public String getRegistrationStatusText() {
try {
return getInfo().getRegStatusText();
} catch (Exception e) {
return "Connecting...";
}
}
public void onRegState(OnRegStateParam prm) {
reason = prm.getReason();
service.emmitRegistrationChanged(this, prm);
}
public void onIncomingCall(OnIncomingCallParam prm) {
TeleCall call = new TeleCall(this, prm.getCallId());
service.emmitCallReceived(this, call);
}
public void onInstantMessage(OnInstantMessageParam prm) {
TeleMessage message = new TeleMessage(this, prm);
service.emmitMessageReceived(this, message);
}
public JSONObject toJson() {
JSONObject json = new JSONObject();
try {
JSONObject registration = new JSONObject();
registration.put("status", getInfo().getRegStatus());
registration.put("statusText", getInfo().getRegStatusText());
registration.put("active", getInfo().getRegIsActive());
registration.put("reason", reason);
json.put("id", getId());
json.put("uri", getInfo().getUri());
json.put("name", configuration.getName());
json.put("username", configuration.getUsername());
json.put("domain", configuration.getDomain());
json.put("password", configuration.getPassword());
json.put("proxy", configuration.getProxy());
json.put("transport", configuration.getTransport());
json.put("contactParams", configuration.getContactParams());
json.put("contactUriParams", configuration.getContactUriParams());
json.put("regServer", configuration.getRegServer());
json.put("regTimeout", configuration.isRegTimeoutNotEmpty() ? String.valueOf(configuration.getRegTimeout()) : "");
json.put("regContactParams", configuration.getRegContactParams());
json.put("regHeaders", configuration.getRegHeaders());
json.put("regOnAdd", configuration.isRegOnAdd());
json.put("registration", registration);
return json;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public String toJsonString() {
return toJson().toString();
}
}