龙空技术网

基于Webrtc服务器搭建音视频通话的详细步骤(附源码下载)

Python乐园 9319

前言:

而今各位老铁们对“webrtc教程net”可能比较看重,大家都需要分析一些“webrtc教程net”的相关内容。那么小编同时在网上搜集了一些对于“webrtc教程net””的相关文章,希望咱们能喜欢,咱们一起来了解一下吧!

基于Webrtc服务器搭建音视频通话。PineAppRtc为android webrtc客户端 ServerProject为服务端,包含房间服务器,信令服务器,穿透服务器。

upstream roomserver {            server 192.168.6.54:8080;        }        server {            #listen 80 default_server;            #listen [::]:80 default_server;            listen 80;            # SSL configuration            #            # listen 443 ssl default_server;            # listen [::]:443 ssl default_server;            #            # Note: You should disable gzip for SSL traffic.            # See:             #            # Read up on ssl_ciphers to ensure a secure configuration.            # See:             #            # Self signed certs generated by the ssl-cert package            # Don't use them in a production server!            #            # include snippets/snakeoil.conf;            root /var/www/html;            # Add index.php to the list if you are using PHP            index index.html index.htm index.nginx-debian.html index.php; #此处添加index.php            server_name _;            #   location / {                # First attempt to serve request as file, then                # as directory, then fall back to displaying a 404.                #   try_files $uri $uri/ =404;            #   }            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000            #            location ~ \.php$ {                include snippets/fastcgi-php.conf;                # With php7.0-cgi alone:                #   fastcgi_pass 127.0.0.1:9000;                # With php7.0-fpm:                fastcgi_pass unix:/run/php/php7.0-fpm.sock;            }            location / {                proxy_pass ;                proxy_set_header Host $host;            }            # deny access to .htaccess files, if Apache's document root            # concurs with nginx's one            #            #location ~ /\.ht {                #   deny all;            #}        }

 <?php              $request_username = $_GET["username"];              if(empty($request_username)) {                  echo "username == null";                  exit;              }              $request_key = $_GET["key"];              $time_to_live = 600;              $timestamp = time() + $time_to_live;//失效时间              $response_username = $timestamp.":".$_GET["username"];              $response_key = $request_key;              if(empty($response_key))              $response_key = "code_key"; //constants.py中CEOD_KEY              $response_password = getSignature($response_username, $response_key);              $jsonObj = new Response();              $jsonObj->username = $response_username;              $jsonObj->password = $response_password;              $jsonObj->ttl = 86400;            //此处需配置自己的服务器            $jsonObj->uris= array("stun:192.168.6.54:3478","turn:192.168.6.54:3478?transport=udp","turn:192.168.6.54:3478?transport=tcp");            echo json_encode($jsonObj);          /**            * 使用HMAC-SHA1算法生成签名值            *            * @param $str 源串            * @param $key 密钥            *            * @return 签名值            */        function getSignature($str, $key) {        $signature = "";        if (function_exists('hash_hmac')) {        $signature = base64_encode(hash_hmac("sha1", $str, $key, true));        } else {        $blocksize = 64;        $hashfunc = 'sha1';        if (strlen($key) > $blocksize) {        $key = pack('H*', $hashfunc($key));        }        $key = str_pad($key, $blocksize, chr(0x00));        $ipad = str_repeat(chr(0x36), $blocksize);        $opad = str_repeat(chr(0x5c), $blocksize);        $hmac = pack(        'H*', $hashfunc(        ($key ^ $opad) . pack(        'H*', $hashfunc(        ($key ^ $ipad) . $str        )        )        )        );        $signature = base64_encode($hmac);        }            return $signature;            }            class Response {                  public $username = "";                  public $password = "";                  public $ttl = "";                  public $uris = array("");              }          ?> 

<?php              $request_username = "inesadt";  //配置成自己的turn服务器用户名            if(empty($request_username)) {                  echo "username == null";                  exit;              }              $request_key = "inesadt";  //配置成自己的turn服务器密码            $time_to_live = 600;              $timestamp = time() + $time_to_live;//失效时间              $response_username = $timestamp.":".$_GET["username"];              $response_key = $request_key;              if(empty($response_key))              $response_key = "CEOD_KEY";//constants.py中CEOD_KEY              $response_password = getSignature($response_username, $response_key);              $arrayObj = array();            $arrayObj[0]['username'] = $response_username;            $arrayObj[0]['credential'] = $response_password;            //配置成自己的stun/turn服务器            $arrayObj[0]['urls'][0] = "stun:192.168.6.54:3478";            $arrayObj[0]['urls'][1] = "turn:192.168.6.54:3478?transport=tcp";            $arrayObj[0]['uris'][0] = "stun:192.168.6.54:3478";            $arrayObj[0]['uris'][1] = "turn:192.168.6.54:3478?transport=tcp";            $jsonObj = new Response();              $jsonObj->lifetimeDuration = "300.000s";            $jsonObj->iceServers = $arrayObj;            echo json_encode($jsonObj);              /**               * 使用HMAC-SHA1算法生成签名值               *               * @param $str 源串               * @param $key 密钥               *               * @return 签名值               */            function getSignature($str, $key) {                $signature = "";                if (function_exists('hash_hmac')) {                    $signature = base64_encode(hash_hmac("sha1", $str, $key, true));                } else {                    $blocksize = 64;                    hashfunc = 'sha1';                    if (strlen($key) > $blocksize) {                        $key = pack('H*', $hashfunc($key));                    }                    $key = str_pad($key, $blocksize, chr(0x00));                    $ipad = str_repeat(chr(0x36), $blocksize);                    $opad = str_repeat(chr(0x5c), $blocksize);                    $hmac = pack(                        'H*', $hashfunc(                                ($key ^ $opad) . pack(                                        'H*', $hashfunc(                                                ($key ^ $ipad) . $str                                       )                                )                            )                        );                     $signature = base64_encode($hmac);                }                return $signature;           }            class Response {                    public $lifetimeDuration = "";                    public $iceServers = array("");            }         ?>

源码下载地址:

技术介绍地址:

源码主页地址:

标签: #webrtc教程net