Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
themeRDark
        var url = $('#urlServer').val();
	    var appKey = "clickToCallApp";

	    var connectionOptions = {
		    urlServer: url,
		    appKey: appKey
	    };

	    //create session
	    console.log("Create new session with url " + url);
	    Flashphoner.createSession(connectionOptions).on(SESSION_STATUS.ESTABLISHED, function(session){
		    setStatus("Session", SESSION_STATUS.ESTABLISHED);
			//session connected, place call
		    call(session);
	    }).on(SESSION_STATUS.DISCONNECTED, function(){
	        setStatus("Session", SESSION_STATUS.DISCONNECTED);
	        onHangup();
	    }).on(SESSION_STATUS.FAILED, function(){
	        setStatus("Session", SESSION_STATUS.FAILED);
	        onHangup();
		});


3. Получение от сервера события, подтверждающего успешное соединение.

...

Code Block
languagejs
themeRDark
        Flashphoner.createSession(connectionOptions).on(SESSION_STATUS.ESTABLISHED, function(session){
		    setStatus("Session", SESSION_STATUS.ESTABLISHED);
			//session connected, place call
		    call(session);
	    }).on(SESSION_STATUS.DISCONNECTED, function(){
	        setStatus("Session", SESSION_STATUS.DISCONNECTED);
	        onHangup();...
	    }).on(SESSION_STATUS.FAILED, function(){
	        setStatus("Session", SESSION_STATUS.FAILED);
	        onHangup();...
		});


4. Исходящий звонок.

session.createCall(), call() код

...

Code Block
languagejs
themeRDark
    var constraints = {
        audio: true,
        video: false
    };
	
	//prepare outgoing call 
    var outCall = session.createCall({
		callee: $("#callee").val(),
		visibleName: "Click To Call",
		localVideoDisplay: localDisplay,
		remoteVideoDisplay: remoteDisplay,
		constraints: constraints,
		receiveAudio: true,
              receiveVideo: false
	}).on(CALL_STATUS.RING, function(){
		setStatus("Call", CALL_STATUS.RING);
    }).on(CALL_STATUS.ESTABLISHED, function(){
		setStatus("Call", CALL_STATUS.ESTABLISHED);
    }).on(CALL_STATUS.FINISH, function(){
		setStatus("Call", CALL_STATUS.FINISH);
	    onHangup();
    }).on(CALL_STATUS.FAILED, function(){
		setStatus("Call", CALL_STATUS.FAILED);
		onHangup();
	});
	
	outCall.call();


5. Завершение звонка.

...

Code Block
languagejs
themeRDark
    $("#callBtn").text("Hangup").removeClass("btn-success").addClass("btn-danger").off('click').click(function(){
        $(this).prop('disabled', true);
	    outCall.hangup();
    }).prop('disabled', false);

...