Bez popisu

initJsSIP.js 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. var eventHandlers, options;
  2. $(document).ready(function() {
  3. init()
  4. })
  5. function testStart() {
  6. //成功注册成功
  7. userAgent.on('registered', function(data) {
  8. if (data.response.status_code === 200) {
  9. loginTrue()
  10. }
  11. });
  12. //注册失败
  13. userAgent.on('registrationFailed', function(data) {
  14. console.log("registrationFailed, ", data);
  15. });
  16. //为传入或传出会话/呼叫激发。data:
  17. userAgent.on('newRTCSession', function(data) {
  18. console.info('onNewRTCSession: ', data);
  19. if(data.session._direction == "outgoing") {
  20. sipCallRTCSession(data, 1) //1是呼出
  21. }
  22. if(data.originator == "remote") {
  23. sipCallRTCSession(data, 2) //2是呼入
  24. // sipIncomingRTCSession(incomingSession) confirmed
  25. }
  26. //接受呼叫时激发
  27. data.session.on('accepted', function(data) {
  28. console.info("3");
  29. if(data.originator == 'remote' && currentSession == null) {
  30. currentSession = incomingSession;
  31. incomingSession = null;
  32. }
  33. });
  34. //确认呼叫后激发
  35. data.session.on('confirmed', function(data) {
  36. console.info("4");
  37. $(".callStyle").text("通话中");
  38. if(data.originator == 'remote' && currentSession == null) {
  39. currentSession = incomingSession;
  40. incomingSession = null;
  41. }
  42. });
  43. //在将远程SDP传递到RTC引擎之前以及在发送本地SDP之前激发。此事件提供了修改传入和传出SDP的机制。
  44. data.session.on('sdp', function(data) {
  45. console.info("5");
  46. });
  47. //接收或生成对邀请请求的1XX SIP类响应(>100)时激发。该事件在SDP处理之前触发(如果存在),以便在需要时对其进行微调,甚至通过删除数据对象中响应参数的主体来删除它
  48. data.session.on('progress', function(data) {
  49. console.info("6");
  50. if(data.originator == 'remote') {}
  51. });
  52. });
  53. }
  54. function init() {
  55. sip_uri_ = "sip:" + selectExten + "@12345sp1.jbdu.cn"; // 12345sp.zwfw.anyang.gov.cn
  56. sip_password_ = "123456"; //zhumadian12345800100
  57. ws_uri_ = "wss://12345sp1.jbdu.cn:7443";
  58. console.info("get input info: sip_uri = ", sip_uri_, " sip_password = ", sip_password_, " ws_uri = ", ws_uri_);
  59. var socket = new JsSIP.WebSocketInterface(ws_uri_);
  60. var configuration = {
  61. sockets: [socket],
  62. outbound_proxy_set: ws_uri_,
  63. uri: sip_uri_, //与用户代理关联的SIP URI(字符串)。这是您的提供商提供给您的SIP地址
  64. password: sip_password_, //SIP身份验证密码
  65. contact_uri: 'sip:' + selectExten + '@12345sp1.jbdu.cn;transport=wss',
  66. register: true, //指示启动时JsSIP用户代理是否应自动注册
  67. session_timers: false, //启用会话计时器(根据RFC 4028)
  68. };
  69. userAgent = new JsSIP.UA(configuration);
  70. eventHandlers = {
  71. 'progress': function(e) {
  72. console.log('call is in progress');
  73. },
  74. 'failed': function(e) {
  75. console.log('call failed: ', e);
  76. callVideoFail()
  77. },
  78. 'ended': function(e) {
  79. console.log('call ended : ', e);
  80. dropCall();
  81. },
  82. 'confirmed': function(e) {
  83. console.log('call confirmed : ', e);
  84. }
  85. };
  86. options = {
  87. 'eventHandlers': eventHandlers,
  88. 'mediaConstraints': {
  89. 'audio': true,
  90. 'video': true
  91. },
  92. 'mediaStream': localStream
  93. };
  94. }