SwitchChannel.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. package com.telerobot.fs.wshandle;
  2. import com.telerobot.fs.config.CallConfig;
  3. import com.telerobot.fs.entity.bo.ChanneState;
  4. import com.telerobot.fs.entity.bo.ChannelFlag;
  5. import com.telerobot.fs.entity.bo.InboundDetail;
  6. import com.telerobot.fs.entity.dto.CallMonitorInfo;
  7. import com.telerobot.fs.entity.dto.GatewayConfig;
  8. import com.telerobot.fs.wshandle.impl.*;
  9. import java.util.ArrayList;
  10. public class SwitchChannel {
  11. private volatile String uuid = "";
  12. private volatile String uuidBLeg = "";
  13. /**
  14. * 通话类型: 语音通话还是视频通话;
  15. */
  16. private volatile String callType = "";
  17. /**
  18. * 分机号或者外线号码;
  19. */
  20. private volatile String phoneNumber = "";
  21. /**
  22. * 通话应答时间
  23. */
  24. private volatile Long answeredTime = 0L;
  25. private volatile String callDirection = "";
  26. /**
  27. * 通话结束时间
  28. */
  29. private volatile Long hangupTime = 0L;
  30. private volatile ChanneState channelState = ChanneState.INIT;
  31. private volatile String videoLevel = "";
  32. private volatile IOnAnsweredHook answeredHook;
  33. private volatile IOnHangupHook hangupHook;
  34. private volatile IChannelParkHook parkHook;
  35. private volatile IOnRecvMediaHook recvMediaHook;
  36. private volatile IOnRecvBgApiResult recvBgApiResultHook;
  37. /**
  38. * send call status when channel is answered.
  39. */
  40. private volatile boolean sendChannelStatusToWsClient;
  41. /**
  42. * 本通道是否启动监听
  43. */
  44. private volatile boolean callMonitorEnabled;
  45. /**
  46. * 本通道的监听信息
  47. */
  48. private volatile CallMonitorInfo callMonitorInfo;
  49. /**
  50. * try to bridge call after recv park event.
  51. */
  52. private volatile boolean bridgeCallAfterPark;
  53. /**
  54. * 录音/录像的路径
  55. */
  56. private volatile String recordingFilePath;
  57. /**
  58. * 通话的各种(业务)标志数据
  59. */
  60. private ArrayList<ChannelFlag> flags = new ArrayList<>(10);
  61. private volatile GatewayConfig gatewayConfig = null;
  62. private volatile InboundDetail inboundDetail = null;
  63. private volatile String bizFieldValue;
  64. /**
  65. * 挂机的sip状态码
  66. */
  67. private String hangupSipCode = "";
  68. public boolean getSendChannelStatusToWsClient() {
  69. return sendChannelStatusToWsClient;
  70. }
  71. public void setSendChannelStatusToWsClient(boolean sendChannelStatusToWsClient) {
  72. this.sendChannelStatusToWsClient = sendChannelStatusToWsClient;
  73. }
  74. public boolean getCallMonitorEnabled() {
  75. return callMonitorEnabled;
  76. }
  77. public void setCallMonitorEnabled(boolean callMonitorEnabled) {
  78. this.callMonitorEnabled = callMonitorEnabled;
  79. }
  80. public CallMonitorInfo getCallMonitorInfo() {
  81. return callMonitorInfo;
  82. }
  83. public void setCallMonitorInfo(CallMonitorInfo callMonitorInfo) {
  84. this.callMonitorInfo = callMonitorInfo;
  85. }
  86. public boolean getBridgeCallAfterPark() {
  87. return bridgeCallAfterPark;
  88. }
  89. public void setBridgeCallAfterPark(boolean bridgeCallAfterPark) {
  90. this.bridgeCallAfterPark = bridgeCallAfterPark;
  91. }
  92. public String getUuid() {
  93. return uuid;
  94. }
  95. public void setUuid(String uuid) {
  96. this.uuid = uuid;
  97. }
  98. public String getUuidBLeg() {
  99. return uuidBLeg;
  100. }
  101. public void setUuidBLeg(String uuidBLeg) {
  102. this.uuidBLeg = uuidBLeg;
  103. }
  104. public String getCallType() {
  105. return callType;
  106. }
  107. public void setCallType(String callType) {
  108. this.callType = callType;
  109. }
  110. public String getPhoneNumber() {
  111. return phoneNumber;
  112. }
  113. public void setPhoneNumber(String phoneNumber) {
  114. this.phoneNumber = phoneNumber;
  115. }
  116. public Long getAnsweredTime() {
  117. return answeredTime;
  118. }
  119. public void setAnsweredTime(Long answeredTime) {
  120. this.answeredTime = answeredTime;
  121. }
  122. public Long getHangupTime() {
  123. return hangupTime;
  124. }
  125. public void setHangupTime(Long hangupTime) {
  126. this.hangupTime = hangupTime;
  127. }
  128. public String getHangupSipCode() {
  129. return hangupSipCode;
  130. }
  131. public void setHangupSipCode(String hangupSipCode) {
  132. this.hangupSipCode = hangupSipCode;
  133. }
  134. public ChanneState getChannelState() {
  135. return channelState;
  136. }
  137. public void setChannelState(ChanneState channeState) {
  138. this.channelState = channeState;
  139. }
  140. public String getVideoLevel() {
  141. return videoLevel;
  142. }
  143. public void setVideoLevel(String videoLevel) {
  144. this.videoLevel = videoLevel;
  145. }
  146. public IOnHangupHook getHangupHook() {
  147. return hangupHook;
  148. }
  149. public void setHangupHook(IOnHangupHook hangupHook) {
  150. this.hangupHook = hangupHook;
  151. }
  152. public IOnRecvMediaHook getRecvMediaHook() {
  153. return recvMediaHook;
  154. }
  155. public void setRecvMediaHook(IOnRecvMediaHook recvMediaHook) {
  156. this.recvMediaHook = recvMediaHook;
  157. }
  158. public IChannelParkHook getParkHook() {
  159. return parkHook;
  160. }
  161. public IOnRecvBgApiResult getRecvBgApiResultHook() {
  162. return recvBgApiResultHook;
  163. }
  164. public void setRecvBgApiResultHook(IOnRecvBgApiResult recvBgApiResultHook) {
  165. this.recvBgApiResultHook = recvBgApiResultHook;
  166. }
  167. public IOnAnsweredHook getAnsweredHook() {
  168. return answeredHook;
  169. }
  170. public void setAnsweredHook(IOnAnsweredHook answeredHook) {
  171. this.answeredHook = answeredHook;
  172. }
  173. public void setParkHook(IChannelParkHook parkHook) {
  174. this.parkHook = parkHook;
  175. }
  176. public String getCallDirection() {
  177. return callDirection;
  178. }
  179. public void setCallDirection(String callDirection) {
  180. this.callDirection = callDirection;
  181. }
  182. public String getRecordingFilePath() {
  183. return recordingFilePath;
  184. }
  185. public GatewayConfig getGatewayConfig() {
  186. return gatewayConfig;
  187. }
  188. public void setGatewayConfig(GatewayConfig gatewayConfig) {
  189. this.gatewayConfig = gatewayConfig;
  190. }
  191. public InboundDetail getInboundDetail() {
  192. return inboundDetail;
  193. }
  194. public void setInboundDetail(InboundDetail inboundDetail) {
  195. this.inboundDetail = inboundDetail;
  196. }
  197. public String getBizFieldValue() {
  198. return bizFieldValue;
  199. }
  200. public void setBizFieldValue(String bizFieldValue) {
  201. this.bizFieldValue = bizFieldValue;
  202. }
  203. /**
  204. * 获取完整的录音/录像的路径;
  205. * @return
  206. */
  207. public String getRecordingFilePathFull() {
  208. return CallConfig.RECORDINGS_PATH + recordingFilePath;
  209. }
  210. public void setRecordingFilePath(String recordingFilePath) {
  211. this.recordingFilePath = recordingFilePath;
  212. }
  213. public SwitchChannel(String uuid, String uuidBLeg, String callType, String callDirection) {
  214. this.setChannelState(ChanneState.INIT);
  215. this.uuid = uuid;
  216. this.uuidBLeg = uuidBLeg;
  217. this.callType = callType;
  218. this.callDirection = callDirection;
  219. }
  220. /**
  221. * 检测指定的当前对象的flags中是否有指定的flag
  222. * @param flag
  223. * @return
  224. */
  225. public synchronized boolean testFlag(ChannelFlag flag) {
  226. for (ChannelFlag channelFlag : flags) {
  227. if(channelFlag.getIndex() == flag.getIndex()){
  228. return true;
  229. }
  230. }
  231. return false;
  232. }
  233. public synchronized void setFlag(ChannelFlag flag) {
  234. boolean found = false;
  235. for (ChannelFlag channelFlag : flags) {
  236. if(channelFlag.getIndex() == flag.getIndex()){
  237. found = true;
  238. }
  239. }
  240. if(!found){
  241. flags.add(flag);
  242. }
  243. }
  244. public synchronized void clearFlag(ChannelFlag flag) {
  245. flags.remove(flag);
  246. }
  247. }