Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SVC questions
07-09-2012, 07:54 AM,
#51
Facebook login (authentication) for websites - EXAMPLE
You will need several files and scripts in order to create a facebook login for a website (SVC in this case) and pass variables obtained either from facebook and/or any other script. At the end of this description you will find a working sample - including all files mentioned here - compressed in an archive (svc_video-chat_fb-auth_full.zip). Just upload to your server and run it, should work.

Step 1, create the index.php:
PHP Code:
<? include_once('login/login.php'); ?>

<!DOCTYPE html>
<html>
<head>
    <title>Video Chat</title>
    
    <!-- ___ include script to load the SVC swf video ___ -->
    <script src="swfobject.js" type="text/javascript"></script>
    <!-- ___  include script to Hide / Unhide containers using jQuery ___ -->
    <script src="jquery.js" type="text/javascript"></script>
    <script>
        function unhide(classID) {
            $("." + classID).toggle();
        }
    </script>
</head>

<body>    
    <div id="videoChat">
        <!-- ___ include the SVC Video Chat ___ -->
        <? include_once('chat/chat.php'); ?>
        <div style="clear:both;"></div>
    </div>
</body>
</html> 
*you will need the following resources:
  • swfobject.js (download the latest package -unzip- and place swfobject.js in your root directory)
  • jquery.js (download the latest package -unzip- and place jquery.js -rename release.js- in your root directory)
you will also need to create login.php and some related resources and chat.php


Step 2, creating login.php:
PHP Code:
<?php

session_start
();

if ( isset(
$_POST) && isset($_POST['submit']) ) {
    
    
$_SESSION['name'] = $_POST['name'];
    
$_SESSION['age'] = $_POST['age'];
    
$_SESSION['gender'] = $_POST['gender'];
    
$_SESSION['country'] = $_POST['country'];
    
    
header("Location: ./index.php");
    exit();
} else if ( isset(
$_POST) && isset($_POST['logout']) ) {
    unset(
$_SESSION['name']);
    unset(
$_SESSION['age']);
    unset(
$_SESSION['gender']);
    unset(
$_SESSION['country']);
    
    
header("Location: ./index.php");
    exit();
}

$me null;
$friends null;
$error null;

if ( isset(
$_SESSION['name']) ) {
    
$me = array();
    
$me['first_name'] = empty($_SESSION['name']) ? "N/A" $_SESSION['name'];
    
$me['gender'] = empty($_SESSION['gender']) ? "N/A" $_SESSION['gender'];
    
$me['age'] = empty($_SESSION['age']) ? "N/A" $_SESSION['age'];
    
$me['country'] = empty($_SESSION['country']) ? "N/A" $_SESSION['country'];
    
$me['country_id'] = "N/A";
    
$me['id'] = "N/A";
}

if ( empty(
$me) ) {


    @include_once(
'../login/auth.php');
    @include_once(
'../login/facebook-php-sdk/facebook.php');
    @include_once(
'../login/country.php');
    
    
$friends_minimum_limit 0;

    
// Create our Application instance.
    
$facebook = new Facebook(array(
        
'appId' => $svc_appID,
        
'secret' => $svc_secret,
        
'cookie' => true,
    ));
    
    function 
getAge($p_strDate) {
        list(
$d,$m,$Y) = explode("/",$p_strDate);
        return (
date("md") < $m $d date("Y") - $Y date("Y") - $Y);
    }
    
    
$user $facebook->getUser();
    
    if ( 
$user ) {
        try {
            
//$uid = $facebook->getUser();
            
$me $facebook->api('/me');
            if ( 
$me['location'] ) {
                
$me['country'] = $me['location']['name'];
                
$me['country_id'] = $me['location']['id'];
            } else if ( 
$me['hometown'] ) {
                
$me['country'] = $me['hometown']['name'];
                
$me['country_id'] = $me['hometown']['id'];
            } else {
                
$me['country'] = "N/A";
                
$me['country_id'] = "";
            }
            
$me['age'] = getAge($me['birthday']);
            
            
$friends $facebook->api(array("method" => "fql.query""query" => "SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())"));
        } catch (
FacebookApiException $e) {
            
$res $e->getResult();
            
$error $res["error"]["message"];
            
error_log($e);
            
$user null
        }
    }
}

?>
*you will need the following resources:
  • facebook / php-sdk (download the sdk and place it -unzipped- in your root directory)
    you may want to rename the long directory name to 'facebook-php-sdk'; in my example, files from facebook-php-sdk-6c82b3f/src directory are moved to facebook-php-sdk/ and I am referring to facebook-php-sdk-6c82b3f/src/facebook.php as facebook-php-sdk/facebook.php
you will also need to create auth.php:
PHP Code:
<?php

$svc_appID 
"App ID/API Key";
$svc_secret "App Secret";
$svc_perms "Permissions";

?>
*you will need the following:
  • create a facebook app (visit facebook.com/developer and click "+ Create New App", you will receive the App ID and -Secret)
  • you may also want to request some additional permissions like age -birthdate-, location, gender, etc
    use the permissions in this format: $svc_perms = "user_location,user_birthday";


Step 3, creating chat.php:
PHP Code:
<? $flashContent_id "flashContent_1"?>
<style>
    object:focus { outline:none; }
    #<?=$flashContent_id?> { display:none; }
</style>

<?php if ( $me && (empty($friends) || (!empty($friends) && sizeof($friends) >= $friends_minimum_limit)) ): ?>
    <script type="text/javascript">
        <!--//--><![CDATA[//><!--
        var alreadyCreated = false;
        if ( document.getElementById("<?=$flashContent_id?>") ) {
            alreadyCreated = true;
        }
        
        if ( alreadyCreated == false ) {
            var swfVersionStr = "10.2.0";
            var xiSwfUrlStr = "svc/lib/playerProductInstall.swf";
            
            var flashvars = {};
            <?php if ( !empty($me) ): ?>
                flashvars.userName =   "<?=$me['first_name']?>";
                flashvars.sex =        "<?=$me['gender']?>";
                flashvars.age =        "<?=$me['age']?>";
                flashvars.country =    "<?=$me['country']?>";
                flashvars.id =         "<?=$me['id']?>";
            <?php endif ?>
            
            var params = {};
            params.quality = "high";
            params.bgcolor = "#ffffff";
            params.allowscriptaccess = "sameDomain";
            params.allowfullscreen = "true";
            params.wmode = "transparent";
            
            var attributes = {};
            attributes.id = "VideoChat";
            attributes.name = "VideoChat";
            attributes.align = "middle";
            
            swfobject.embedSWF(
                "VideoChat.swf",
                "<?=$flashContent_id?>",
                "666",
                "397",
                swfVersionStr,
                xiSwfUrlStr,
                flashvars,
                params,
                attributes
            );
            swfobject.createCSS("#<?=$flashContent_id?>", "display:block;text-align:left;");
        }
        //--><!]]>
    </script>
<?php endif ?>


<?php if ( empty($me) ): ?>
    
    <script language="javascript" type="text/javascript">
        if ( window.fbAsyncInit ) {
        } else {
            window.fbAsyncInit = function() {
                FB.init({
                    appId   : '<?=$facebook->getAppId()?>',
                    cookie  : true, // enable cookies to allow the server to access the session
                    xfbml   : true, // parse XFBML
                    oauth   : true,
                    status  : true,
                });
                
                FB.Event.subscribe('auth.login', function(response) {
                    // whenever the user logs in, we refresh the page
                    window.location.reload();
                });
                FB.Event.subscribe('auth.logout', function(response) {
                    window.location.reload();
                });
            };
            
            // Load the SDK Asynchronously
            (function(d) {
                var js, id = 'facebook-jssdk';
                if ( d.getElementById(id) ) return;
                js = d.createElement('script');
                js.id = id;
                js.async = true;
                js.src = "//connect.facebook.net/en_US/all.js";
                d.getElementsByTagName('head')[0].appendChild(js);
            }(document));
        }
    </script>
    
<?php endif ?>
    
    <!-- ___ SVC LOGOUT BUTTON ___ -->
    <? //include_once('./login/logout.php'); ?>
    
    <!-- ___ SVC FLASH CONTENT ___ -->
    <?php if ( $me && (empty($friends) || (!empty($friends) && sizeof($friends) >= $friends_minimum_limit)) ): ?>
        <!-- Video chat -->
        <div class="content" style="width:666px;height:397px;margin-left:auto;margin-right:auto;padding-top:10px;">
            <!--
                SWFObject's dynamic embed method replaces this alternative HTML content with Flash content when enough 
                JavaScript and Flash plug-in support is available. The div is initially hidden so that it doesn't show
                when JavaScript is disabled.
            -->
            <div id="<?=$flashContent_id?>">
                <p>
                To view this page ensure that Adobe Flash Player version 
                10.0.0 or greater is installed. 
                <a href='http://www.adobe.com/go/getflashplayer'><img src='http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>
                </p>
            </div>
            
            <noscript>
                <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="666" height="397" id="VideoChatSingle">
                    <param name="movie" value="VideoChat.swf" />
                    <param name="quality" value="high" />
                    <param name="bgcolor" value="#ffffff" />
                    <param name="allowScriptAccess" value="sameDomain" />
                    <param name="allowFullScreen" value="true" />
                    <?php if ( !empty($me) ): ?>
                    <param name="flashVars" value="userName=<?=$me['first_name']?>&sex=<?=$me['gender']?>&age=<?=$me['age']?>&country=<?=$me['country']?>&id=<?=$me['id']?>" />
                    <?php endif ?>
                    
                    <!--[if !IE]>-->
                    <object type="application/x-shockwave-flash" data="VideoChat.swf" width="666" height="397">
                        <param name="quality" value="high" />
                        <param name="bgcolor" value="#ffffff" />
                        <param name="allowScriptAccess" value="sameDomain" />
                        <param name="allowFullScreen" value="true" />
                        <!--<![endif]-->
                        <!--[if gte IE 6]>-->
                            <p> 
                            Either scripts and active content are not permitted to run or Adobe Flash Player version
                            10.0.0 or greater is not installed.
                            </p>
                        <!--<![endif]-->
                            <a href="http://www.adobe.com/go/getflashplayer">
                            <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" />
                            </a>
                        <!--[if !IE]>-->
                    </object>
                    <!--<![endif]-->
                    <param name="wmode" value="transparent" />
                </object>
            </noscript>
        </div>
    <?php endif ?>
    
    
    <?php if ( !empty($friends) && sizeof($friends) < $friends_minimum_limit ): ?>
        <div>
            Error: minimum requirements not met.
        </div>
    <?php endif ?>
    <!-- ___ END SVC FLASH CONTENT ___ -->
    
    
    
    <?php if ( empty($me) ): ?>
    <!-- ___ SVC LOGIN BOX WITH AND WITHOUT (HIDDEN) FACEBOOK ___ -->    
        <div class="login_box">
            <!-- ___ SVC login with Facebook ___ -->    
            <div class="login_box_facebook">
                Signing in to Video Chat.<br /><br />
                
                    <?php if ( !empty($error) ): ?>
                        <font color="red"><?=$error?></font>
                    <?php else: ?>
                
                <fb:login-button size="large"  show-faces="false" autologoutlink="false" background="white" scope="<?=$svc_perms?>">
                    Login with Facebook
                </fb:login-button>
                    
                    <?php endif ?><br /><br />
                
                or <a href="javascript:unhide('login_box_svc');" class="login_link">login without Facebook</a>.
                        </div>
            <!-- ___ SVC login without Facebook ___ -->    
            <div class="login_box_svc" style="display: none;">
                <? @include_once('./geoip/geoip.php'); ?><br />
                <form method="post">
                <div id="login_center">
                    <label class="input">
                    <span>Username</span>
                    <input tabindex="1" type="text" name="name" class="login_name" style="width:173px; height:18px;">
                    </label>
                    
                    <!-- display country code -->
                    <!-- <span class="descr"><?php //echo " (".$country_code.")"; ?></span> -->

                    <!-- country selected by geoIP -->
                    <div style="clear:both;"></div>
                    <div class="login_geoip">from <? echo $location?></div>
                    <input tabindex="2" type="hidden" name="country" style="width: 0px;" value="<?php echo $location;?>">
                    
                    <!-- country selected manually -->
                    <?php /*
                    echo '
                        <select tabindex="2" name="country" style="width: 80px;">
                        <option value="'.$location.'">'.$location.'</option>';
                        
                        foreach($country_list as $key => $value)
                        {
                        echo '<option value="'.$value.'">'.$value.'</option>';
                        }
                        
                    echo '</select>';
                          */
                    
?>
                </div>
                <div style="clear:both;"></div>
                <div id="login_center">
                    <select tabindex="3" name="age" style="width: 80px;">
                        <option value="N/A">age</option>
                        <?php
                        
for($i 13$i  != 100$i++) {
                            echo 
"<option value=" $i ">" $i "</option>";
                        }
                        
?>             
                    </select>
                        &nbsp;&nbsp;
                    <select tabindex="4" name="gender" style="width: 80px;">
                        <option value="N/A">gender</option>
                        <option value="male">male</option>
                        <option value="female">female</option>           
                    </select>
                </div>
                <div style="clear:both;"></div>
                <div id="login_center">
                    <input tabindex="5" type="submit" name="submit" value="Login" class="login_submit">
                </div>
                    
                </form>
            </div>
        </div>
    <?php endif ?>
*you may want to add some styling and country list or geoIP detection:
  • to populate the country list and to make users able to select their country, simply create a file called country.php and inside the file create a php array with all countries:
    PHP Code:
    <?php
    $country_list 
    = array(
            
    "Afghanistan",
            
    "Albania",
            
    "Algeria",
            
    "Zimbabwe"
        
    );
    ?>

    .zip   country.php.zip (Size: 1.22 KB / Downloads: 7)
  • you may use any GeoIP detection method instead of the php array (recommended)
  • and some styling for the whole page/login boxes:
    Code:
        .login_box {
            margin-left:auto;
            margin-right:auto;
            width: 500px;
            height: 100%;
            padding: 15px;
            border: 15px solid #6778AE;
            -moz-border-radius: 4px;
            -webkit-border-radius: 4px;
            background-color: white;
            overflow: auto;
            text-align: center;
        }

and here is everything:
.zip   svc_video-chat_fb-auth_full.zip (Size: 217.87 KB / Downloads: 67)
- upload to your server
- create the facebook app
- edit /login/auth.php (insert facebook App ID and -Secret)
- enjoy
I love video chat!
Reply
08-23-2012, 12:21 PM,
#52
RE: SVC questions
facebook / php-sdk is missing, pls. read above and use the provided links

Quote:*you will need the following resources:
facebook / php-sdk (download the sdk and place it -unzipped- in your root directory)
you may want to rename the long directory name to 'facebook-php-sdk'; in my example, files from facebook-php-sdk-6c82b3f/src directory are moved to facebook-php-sdk/ and I am referring to facebook-php-sdk-6c82b3f/src/facebook.php as facebook-php-sdk/facebook.php
Reply
09-10-2012, 03:03 PM,
#53
RE: SVC questions
for my web application I need to chose which two people get matched up for video chat (through a search process). can this software support the joining of two specific users for video chat?

scenario:

userA is to be matched up with userB
redirect both users to the chat page, passing in each users information forcing them to chat (not random)

thanks!
Reply
09-11-2012, 12:34 PM,
#54
RE: SVC questions
Can this software be used to set up a video chat between to specific people?

For example, both users are decided prior to chatting, then they are both automatically directed to the chat page, passing in user information from both users to the chat software.
Reply
09-19-2012, 10:19 AM,
#55
RE: SVC questions
(09-10-2012, 03:03 PM)noskop2dafaccio Wrote:  for my web application I need to chose which two people get matched up for video chat (through a search process). can this software support the joining of two specific users for video chat?

scenario:

userA is to be matched up with userB
redirect both users to the chat page, passing in each users information forcing them to chat (not random)

thanks!

not the SVC-SR (Single Random) the SVC software is capable but I am not sure you can get that source released yet. Come back with a post in about a week. Thank you!
Reply
09-19-2012, 10:20 AM,
#56
RE: SVC questions
(09-11-2012, 04:08 PM)noskop2dafaccio Wrote:  I want to use my own network of people, not the default one that it is connecting to. How can I do this?

You can use any database, any website to connect your users but as I mentioned, at the moment random video chat only
Reply
09-24-2012, 04:13 AM,
#57
RE: SVC questions
(09-19-2012, 10:19 AM)Govido Wrote:  
(09-10-2012, 03:03 PM)noskop2dafaccio Wrote:  for my web application I need to chose which two people get matched up for video chat (through a search process). can this software support the joining of two specific users for video chat?

scenario:

userA is to be matched up with userB
redirect both users to the chat page, passing in each users information forcing them to chat (not random)

thanks!

not the SVC-SR (Single Random) the SVC software is capable but I am not sure you can get that source released yet. Come back with a post in about a week. Thank you!

In the download package "SVC-SR0.9_video_chat_free.zip" there is no configuration.php or registration.php. Also, is the above source ready yet? Thank you so much for your help.
Reply
09-27-2012, 01:46 AM,
#58
RE: SVC questions
Configuration and preference based tuning of the software is optional and can be found in commercial packages only. The source is sold separately only to SVC developers (SVC libraries): http://videosoftware.pro/software/buy-now
Reply
12-27-2012, 09:18 AM,
#59
RE: SVC questions
(09-19-2012, 10:19 AM)Govido Wrote:  not the SVC-SR (Single Random) the SVC software is capable but I am not sure you can get that source released yet. Come back with a post in about a week. Thank you!

Is this available yet?

Reply
12-28-2012, 02:13 AM,
#60
RE: SVC questions
Expected in Q1 2013 with a major release. No promises though, depends on the developer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)