Latest 1.8.2
Homepage https://github.com/CrassusX/YstenEngineKit
License MIT
Platforms ios 8.0
Dependencies Socket.IO-Client-Swift
Authors

CI Status
Version
License
Platform

安装

  • Podfile 中加入下面一行代码来使用 YstenEngineKit
pod 'YstenEngineKit'
  • 直接将YstenEngineKit.frameworkWebRTC.framework拷贝到工程中

使用教程

本教程将讲解YstenEngineKit的基本使用功能。

YstenEngineKit 基本组成

  • YstenEngine:功能实现
  • YSTTypeDefines:错误状态,连麦状态,视频自适应方式,本地视图旋转方向等枚举的声明;

YstenEngine使用介绍

NOTE:必须要在主线程上调用方法,所有的代理回调都会在主线程返回;
plist必须增加权限:NSCameraUsageDescription和NSMicrophoneUsageDescription
1.使用userId,初始化YstenEngine

_ystenEngine = [[YstenEngine getInstance] init:self userId:g_UserId];

2.通过请求获取到加入房间的token

  • 加入房间,当加入房间成功后,主动将本地流发布给远端
[_ystenEngine joinChannel:token];
  • 只是加入房间,显示本地用户视频,然后等连接房间成功后,在主动发起本地流给远端
[_ystenEngine joinChannelWithOutPublish:token];

// 等待用户加入房间成功,操作主动发布本地流给远端
- (void)YstenEngine:(YstenEngine *)engine onJoinComplete:(BOOL)result reason:(NSError *)reason
{
    [_ystenEngine publish];
}

3.创建显示本地视频视图
NOTE:在使用本sdk的1.7.30以下版本必须在第2步骤后才能创建,使用1.7.30以上版本在步骤1,2之前创建本地视图都可以.

- (void)createLocalView
{
    if( !localVideoView ) {
        localVideoView = [_ystenEngine createLocalVideoView:CGRectMake(0, 0, _localView.frame.size.width, _localView.frame.size.height) withDisplayType:Ysten_VideoViewDisplay_Banlance];
        [_localView addSubview:localVideoView];

        localVideoView.backgroundColor = [UIColor clearColor];
    }
}

5.远端用户加入房间或者离开房间

// 加入房间
- (void)YstenEngine:(YstenEngine *)engine onUserJoined:(NSString *)userId
{
   // 根据此userId创建视图
    UIView *remotelVideoView = [_ystenEngine createRemoteVideoView: [UIApplication sharedApplication].keyWindow.frame forUser:userId withDisplayType:Ysten_VideoViewDisplay_Banlance];

    if (userId && remotelVideoView) {
        [remoteVideoViewArray setObject:remotelVideoView forKey:userId];
        remotelVideoView.backgroundColor = [UIColor blueColor];
        remotelVideoView.frame = rect;
        [remotelVideoView setHidden:YES];

        [_remoteView addSubview:remotelVideoView];
    }
}

// 离开房间
- (void)YstenEngine:(YstenEngine *)engine onUserLeft:(NSString *)userId
{
    UIView *removeView = [remoteVideoViewArray objectForKey:userId];
    [removeView removeFromSuperview];
    [remoteVideoViewArray removeObjectForKey:userId];
    removeView = nil;
}

6.结束视频通话

   [_ystenEngine leaveChannel];

   // 销毁本地视图和远端视图
   for (NSString *userId in remoteVideoViewArray) {
        UIView *v = [remoteVideoViewArray objectForKey:userId];
        [v removeFromSuperview];
        v = nil;
        NSLog(@"[Demo]Remove remote view:%@", userId);
    }
    [remoteVideoViewArray removeAllObjects];

    [localVideoView removeFromSuperview];
    localVideoView = nil;

其他说明

  • 属性
  • roomState:加入房间的状态,如果是YSTRoomStateConnected,那么就可以操作相关所有的动作。
  • audioEnabled:是否本地流音频有
  • videoEnabled:是否本地流视频可显示
  • videoSize: 配置本地视频流显示分辨率,默认是{1280,720}
// 设置必须在此两种方式之前设置
// 方式一:
_ystenEngine.videoSize = CGSizeMake(2014, 1100);
[_ystenEngine openLocalMedia];
// 方式二:
_ystenEngine.videoSize = CGSizeMake(2014, 1100);
[_ystenEngine joinChannel:self.token];
  • 主要功能:
  • 创建本地视频显示视图:- (UIView *)createLocalVideoView:(CGRect)frame withDisplayType:(YstenVideoViewDisplayType)type
  • 创建远端视频显示视图:- (UIView )createRemoteVideoView:(CGRect)frame forUser:(NSString )userId withDisplayType:(YstenVideoViewDisplayType)type
  • 本地视频是否显示:- (void)enableLocalVideo:(BOOL)enable
  • 本地音频是否静音:- (void)enableLocalAudio:(BOOL)enable
  • 切换前后置摄像头:- (void)switchCamera
  • 打开扬声器:- (void)activeSpeakerphone:(BOOL)enable
  • 发布本地流:- (void)publish
  • 取消发布本地流:- (void)unPublish
  • 重新发布本地流: – (void)republish
  • 重新订阅远端用户的流:- (void)resubscribeUserId:(NSString *)userId
  • 订阅所有的远端用户:- (void)subscribeAllRemote
  • 取消订阅所有的远端用户:- (void)unsubscribeAllRemote
  • 打开本地媒体:- (void)openLocalMedia
// 可以在初始化ystenEngine后即可调openLocalMedia方法,然后在代理回调函数, 初始化本地视图
- (void)YstenEngine:(YstenEngine *)engine onFirstLocalVideo:(NSString *)userId
{
    if (localVideoView) {
        [localVideoView removeFromSuperview];
        localVideoView = nil;
    }
    [self createLocalView];
}

- (void)createLocalView
{
    if( !localVideoView ) {
        localVideoView = [_ystenEngine createLocalVideoView:CGRectMake(0, 0, _localView.frame.size.width, _localView.frame.size.height) withDisplayType:Ysten_VideoViewDisplay_Banlance];
        [_localView addSubview:localVideoView];

        localVideoView.backgroundColor = [UIColor clearColor];
    }
}
  • 代理回调
  • 所有的错误情况回调:- (void)YstenEngine:(YstenEngine )engine errorMessage:(NSError )error
  • 房间状态变化回调:- (void)YstenEngine:(YstenEngine *)engine roomStateDidChange:(YSTRoomState)roomState
  • 加入房间回调:- (void)YstenEngine:(YstenEngine )engine onJoinComplete:(BOOL)result reason:(NSError )reason
  • 离开房间回调:- (void)YstenEngine:(YstenEngine )engine onLeaveComplete:(BOOL)result reason:(NSError )reason
  • 发布本地流成功:- (void)YstenEngine:(YstenEngine )engine didPublish:(NSString )userId
  • 取消发布本地流成功:- (void)YstenEngine:(YstenEngine )engine didUnpublish:(NSString )userId
  • 成功订阅用户:- (void)YstenEngine:(YstenEngine )engine didSubscribe:(NSString )userId
  • 取消订阅用户成功:- (void)YstenEngine:(YstenEngine )engine didUnSubscribe:(NSString )userId
  • 远端首帧显示:- (void)YstenEngine:(YstenEngine )engine onFirstRemoteVideo:(NSString )userId
  • 流状态显示:- (void)YstenEngine:(YstenEngine )engine onStatReport:(NSDictionary )report
  • 音频流开启或关闭:- (void)YstenEngine:(YstenEngine )engine onEnableAudio:(BOOL)enable forUser:(NSString )userId
  • 视频流开启或关闭:- (void)YstenEngine:(YstenEngine )engine onEnableVideo:(BOOL)enable forUser:(NSString )userId
  • 远端用户进入房间并推流:- (void)YstenEngine:(YstenEngine )engine onUserJoined:(NSString )userId
  • 远端推流用户离开房间:- (void)YstenEngine:(YstenEngine )engine onUserLeft:(NSString )userId
  • 未推流用户加入房间:- (void)YstenEngine:(YstenEngine )engine onUserJoin:(NSString )userId
  • 未推流用户离开房间:- (void)YstenEngine:(YstenEngine )engine onUserLeave:(NSString )userId

作者

Crassus, [email protected]

协议

YstenEngineKit 被许可在 MIT 协议下使用。查阅 LICENSE 文件来获得更多信息。

Latest podspec

{
    "name": "YstenEngineKit",
    "version": "1.8.2",
    "summary": "u5373u65f6u901au8baf.",
    "description": "TODO: u57fau4e8eWebRTCu5f00u53d1u5e93uff0cu7528u4e8eu89c6u9891u901au8baf.",
    "homepage": "https://github.com/CrassusX/YstenEngineKit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Crassus": "[email protected]"
    },
    "source": {
        "git": "https://github.com/CrassusX/YstenEngineKit.git",
        "tag": "1.8.2"
    },
    "platforms": {
        "ios": "8.0"
    },
    "swift_version": "4.0",
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "4.0"
    },
    "source_files": "YstenEngineKit/YstenEngineKit.framework/Headers/*.{h}",
    "public_header_files": "YstenEngineKit/YstenEngineKit.framework/Headers/YSTRTCKit.h",
    "vendored_frameworks": "YstenEngineKit/*.{framework}",
    "dependencies": {
        "Socket.IO-Client-Swift": [
            "<=13.3.1"
        ]
    }
}

Pin It on Pinterest

Share This