To implement the functionality of video chat in the browser, there are two of the most appropriate of the technology - WebRTC and Flash. Each technology has a number of features, for example, Flash can use H.264 video codecs or Sorenson, and VP8 is currently available in WebRTC, which makes these two approaches poorly compatible with each other (transcoding video on the fly is very expensive operation), besides video chat is better to do peer-to-peer whenever possible, is it worth saying that connecting Flash and WebRTC will not come out directly. In our example, we will consider a video call option from a WebRTC call to WebRTC, using the VoxImplant platform. In general, you can make a choice of a specific option, up to a dynamic choice of technology, depending on whom we are calling. Details, as usual, under the cut. VoxEngine.forwardCallToUserDirect(); VoxEngine.forwardCallToUser(null, true); , but in this case calls will cost money. var call1, call2; VoxEngine.addEventListener(AppEvents.CallAlerting, function(e) { call1 = e.call; call2 = VoxEngine.callUserDirect(e.call, e.destination, e.displayName, e.headers); call2.addEventListener(CallEvents.Connected, handleCallConnected); }); function handleCallConnected(e) { call1.answerDirect(call2); // , , - setTimeout(VoxEngine.terminate, 5000); } // SDK <script type="text/javascript" src="//cdn.voximplant.com/edge/voximplant.min.js"></script> // HTML function log(str) { document.getElementById("log").innerHTML += str+"<br/>"; } // VoxImplant var voxAPI = VoxImplant.getInstance(); // voxAPI.on(VoxImplant.Events.SDKReady, onSdkReady); voxAPI.on(VoxImplant.Events.ConnectionEstablished, onConnectionEstablished); voxAPI.on(VoxImplant.Events.ConnectionFailed, onConnectionFailed); voxAPI.on(VoxImplant.Events.ConnectionClosed, onConnectionClosed); voxAPI.on(VoxImplant.Events.AuthResult, onAuthResult); voxAPI.v(VoxImplant.Events.IncomingCall, onIncomingCall); voxAPI.on(VoxImplant.Events.MicAccessResult, onMicAccessResult); // SDK try { voxAPI.init({ micRequired: true, // / VoxImplant videoSupport: true // }); } catch(e) { // , log(e.message); } // SDK - function onSdkReady(){ voxAPI.connect(); // / } // function onMicAccessResult(e) { if (e.result) { // / } else { // / } } // VoxImplant function onConnectionEstablished() { // - , // application_user, application_name, account_name application_user_password voxAPI.login(application_user+"@"+application_name+"."+account_name+".voximplant.com", application_user_password); } // VoxImplant function onConnectionFailed() { // - UDP } // function onConnectionClosed() { // connect } function onAuthResult(e) { if (e.result) { // - } else { // , e.code, } } var currentCall = null; // // function onIncomingCall(e) { currentCall = e.call; // currentCall.on(VoxImplant.CallEvents.Connected, onCallConnected); currentCall.on(VoxImplant.CallEvents.Disconnected, onCallDisconnected); currentCall.on(VoxImplant.CallEvents.Failed, onCallFailed); // . . currentCall.answer(null, {}, { receiveVideo: true, sendVideo: true }); } // function createCall() { // application_username - , ( ) currentCall = voxAPI.call(application_username, { receiveVideo: true, sendVideo: true }, "TEST CUSTOM DATA", {"X-DirectCall": "true"}); // currentCall.on(VoxImplant.CallEvents.Connected, onCallConnected); currentCall.on(VoxImplant.CallEvents.Disconnected, onCallDisconnected); currentCall.on(VoxImplant.CallEvents.Failed, onCallFailed); } // function onCallConnected(e) { // voxAPI.sendVideo(true); currentCall.showRemoteVideo(true); } // function onCallDisconnected(e) { currentCall = null; } // function onCallFailed(e) { // e.code, e.reason } 


Source: https://habr.com/ru/post/231383/
All Articles