Giter VIP home page Giter VIP logo

react-native-trtc's Introduction

react-native-trtc

基于腾讯实时音视频(TRTC)最新SDK React Native 组件基本封装完成,同时支持IOS和Android

没有实现全部API的封装,有很少部分不常用功能尚未实现

后续有时间会继续完善

安装(React Native >= 0.60.0)

npm i --save rn-trtc

打开ios目录运行

pod install

使用

TRTCLocalView 显示本视频预览 TRTCRemoteView 显示远程视频流

需要在加入房间后render

import React, { Component, useEffect, useRef } from "react";
import TRTCEngine, {
    TRTCLocalView, 
    Scene, 
    Role, 
    VideoRotation, 
    TRTCRemoteView, 
    LogLevel,
    VideoResolution
} from 'rn-trtc';

TRTCEngine.setLogLevel(LogLevel.TRTCLogLevelNone); // 设置日志级别

// 初始化,参数参照官方文档
const engine = TRTCEngine.create({
    videoResolution: VideoResolution.TRTC_VIDEO_RESOLUTION_640_360,
    videoFps: 15,
    videoBitrate: 1200,
});

engine.setBeautyStyle(1); // 设置美颜风格
engine.setBeautyLevel(5); // 设置美颜级别
engine.setWhitenessLevel(1); // 设置美白级别
        
// 绑定事件,事件名参照官方文档
engine.addListener("onError", (args) => {
    console.error(args)
});

engine.addListener("onEnterRoom", (args) => {
    const {result} = args;
    if(result > 0){
        console.log(`进房成功,总计耗时${result}ms`)
    }else{
        console.error(`进房失败,错误码${result}`)
    }
});
// 进入房间
engine.enterRoom({
    sdkAppId: sdkAppId, //appId: number
    userId: userId,  // userId: string
    roomId: roomId, // roomId: nubmer
    userSig: userSig, // 用户签名参照官方文档生成
    role: Role.TRTCRoleAudience, // 加入房间的角色
}, Scene.TRTC_APP_SCENE_LIVE)

// API
engine.switchRole(Role.TRTCRoleAnchor);
engine.startLocalAudio();

// 加入房间成功后显示本地视频预览
{joinSucceed && <TRTCLocalView style={styles.videoContainer}/>}

// 有远程视频加入显示
{remoteUsers.map((uid, index)=><TRTCRemoteView uid={uid}
                                    key={`trtc-${index}`}
                                    style={styles.videoContainer}/>)}

官方API文档

react-native-trtc's People

Contributors

martinzz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.