AppRTC(Webrtc)本地服务器搭建

由于https://appr.tc已经无法访问,我们需要自己搭建一个Webrtc服务器,本地环境如下:

系统 芯片
macOS 15.2 Apple M1

拉取镜像

sudo docker pull piasy/apprtc-server

编写配置文件

镜像拉成功后,还需要一个配置文件,文件命名为constants.py,存放到一个目录下如/home/xxx/constants.py,内容如下:

# Copyright 2015 Google Inc. All Rights Reserved.

"""AppRTC Constants.
This module contains the constants used in AppRTC Python modules.
"""
import os

# Deprecated domains which we should to redirect to REDIRECT_URL.
REDIRECT_DOMAINS =  [
  'apprtc.appspot.com', 'apprtc.webrtc.org', 'www.appr.tc'
]
# URL which we should redirect to if matching in REDIRECT_DOMAINS.
REDIRECT_URL = 'https://appr.tc'

ROOM_MEMCACHE_EXPIRATION_SEC = 60 * 60 * 24
MEMCACHE_RETRY_LIMIT = 100

LOOPBACK_CLIENT_ID = 'LOOPBACK_CLIENT_ID'

# Turn/Stun server override. This allows AppRTC to connect to turn servers
# directly rather than retrieving them from an ICE server provider.
ICE_SERVER_OVERRIDE = None
# Enable by uncomment below and comment out above, then specify turn and stun
# ICE_SERVER_OVERRIDE  = [
#   {
#     "urls": [
#       "turn:hostname/IpToTurnServer:19305?transport=udp",
#       "turn:hostname/IpToTurnServer:19305?transport=tcp"
#     ],
#     "username": "TurnServerUsername",
#     "credential": "TurnServerCredentials"
#   },
#   {
#     "urls": [
#       "stun:hostname/IpToStunServer:19302"
#     ]
#   }
# ]

ICE_SERVER_BASE_URL = 'http://SERVER_PUBLIC_IP:3033'
ICE_SERVER_URL_TEMPLATE = '%s/iceconfig?key=%s'
ICE_SERVER_API_KEY = os.environ.get('ICE_SERVER_API_KEY')

# Dictionary keys in the collider instance info constant.
WSS_INSTANCE_HOST_KEY = 'host_port_pair'
WSS_INSTANCE_NAME_KEY = 'vm_name'
WSS_INSTANCE_ZONE_KEY = 'zone'
WSS_INSTANCES = [{
    WSS_INSTANCE_HOST_KEY: 'SERVER_PUBLIC_IP:8089',
    WSS_INSTANCE_NAME_KEY: 'wsserver-std',
    WSS_INSTANCE_ZONE_KEY: 'us-central1-a'
}]

WSS_HOST_PORT_PAIRS = [ins[WSS_INSTANCE_HOST_KEY] for ins in WSS_INSTANCES]

# memcache key for the active collider host.
WSS_HOST_ACTIVE_HOST_KEY = 'wss_host_active_host'

# Dictionary keys in the collider probing result.
WSS_HOST_IS_UP_KEY = 'is_up'
WSS_HOST_STATUS_CODE_KEY = 'status_code'
WSS_HOST_ERROR_MESSAGE_KEY = 'error_message'

RESPONSE_ERROR = 'ERROR'
RESPONSE_ROOM_FULL = 'FULL'
RESPONSE_UNKNOWN_ROOM = 'UNKNOWN_ROOM'
RESPONSE_UNKNOWN_CLIENT = 'UNKNOWN_CLIENT'
RESPONSE_DUPLICATE_CLIENT = 'DUPLICATE_CLIENT'
RESPONSE_SUCCESS = 'SUCCESS'
RESPONSE_INVALID_REQUEST = 'INVALID_REQUEST'

IS_DEV_SERVER = os.environ.get('APPLICATION_ID', '').startswith('dev')

BIGQUERY_URL = 'https://www.googleapis.com/auth/bigquery'

# Dataset used in production.
BIGQUERY_DATASET_PROD = 'prod'

# Dataset used when running locally.
BIGQUERY_DATASET_LOCAL = 'dev'

# BigQuery table within the dataset.
BIGQUERY_TABLE = 'analytics'

运行服务

需要自己修改constants.py的路径以及ip地址

sudo docker run --rm \
-p 8080:8080 -p 8089:8089 -p 3478:3478 -p 3478:3478/udp -p 3033:3033 \
--expose=59000-65000 \
-e PUBLIC_IP=<your local ip> \
-v /home/xxx/constants.py:/apprtc_configs \
-t -i piasy/apprtc-server
1.png

2.png

服务启动后,访问http://localhost:8080,出现以下页面,就说明服务运行成功了

web.png

运行demo

demo源码下载地址:https://github.com/kongpf8848/webrtc_demo下载,下载源码后,在Android Studio中打开,替换https://appr.tchttp://xxx:8080,xxx为本地服务器IP

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容