sudo gem install cocoapods pod init
pod 'TXLiteAVSDK_TRTC', 'version'
pod install pod update
// Import the SDK module @import TXLiteAVSDK_TRTC;
// Import the header file #import "TXLiteAVSDK_TRTC/TRTCCloud.h"
#include "TXLiteAVSDK_TRTC/cpp_interface/ITRTCCloud.h"
@IBAction func createARoom(sender: AnyObject) { let connectOptions = ConnectOptions(token: accessToken) { (builder) in builder.roomName = "my-room" } room = TwilioVideoSDK.connect(options: connectOptions, delegate: self) } // MARK: RoomDelegate func roomDidConnect(room: Room) { print("Did connect to Room") if let localParticipant = room.localParticipant { print("Local identity \\(localParticipant.identity)") // Set the delegate of the local particiant to receive callbacks localParticipant.delegate = self } }
// Create trtc instance(singleton) and set up event listeners self.trtcCloud = [TRTCCloud sharedInstance]; self.trtcCloud.delegate = self; // Package the room entry parameter // Please replace each field in TRTCParams with your own parameters TRTCParams *params = [[TRTCParams alloc] init]; params.sdkAppId = 1400000123; // Please replace with your own SDKAppID params.roomId = 123321; // Please replace with your own room number params.userId = @"denny"; // Please replace with your own userid params.userSig = @"xxx"; // Please replace with your own userSig params.role = TRTCRoleAnchor; // If your application scenario is a video call between several people, please use "TRTC_APP_SCENE_LIVE" [self.trtcCloud enterRoom:params appScene:TRTCAppSceneLIVE]; // Listen to the onEnterRoom event of the SDK and get notification whether the room is successfully entered - (void)onEnterRoom:(NSInteger)result { if (result > 0) { [self toastTip:@"Enter room succeed!"]; } else { [self toastTip:@"Enter room failed!"]; } }
T// start camera var cameraSource = CameraSource(delegate: self), let captureDevice = CameraSource.captureDevice(position: .front) cameraSource.startCapture(device: captureDevice, completion: nil) // Use CameraSource to produce video from the device's front camera. if let camera = TVICameraCapturer(source: .frontCamera), let videoTrack = TVILocalVideoTrack(capturer: camera) { // TVIVideoView is a TVIVideoRenderer and can be added to any TVIVideoTrack. let renderer = TVIVideoView(frame: view.bounds) // Add renderer to the video track videoTrack.addRenderer(renderer) self.localVideoTrack = videoTrack self.camera = camera self.view.addSubview(renderer) }
self.trtcCloud = [TRTCCloud sharedInstance]; // Set the preview mode of the local video image: Enable horizontal mirroring and set the fill mode for the video image TRTCRenderParams *param = [[TRTCRenderParams alloc] init]; param.fillMode = TRTCVideoFillMode_Fill; param.mirrorType = TRTCVideoMirrorTypeAuto; [self.trtcCloud setLocalRenderParams:param]; // Enable local camera preview(`localCameraVideoView` is used to render the local video image) [self.trtcCloud startLocalPreview:YES view:localCameraVideoView]; // Enable mic and set `quality` to `SPEECH` for the voice mode [self.trtcCloud startLocalAudio:TRTCAudioQualitySpeech]; [self.trtcCloud startLocalAudio:TRTCAudioQualitySpeech];
// MARK: RemoteParticipantDelegate /* * In the Participant Delegate, we can respond when the Participant adds a Video * Track by rendering it on screen. */ func didSubscribeToVideoTrack(videoTrack: RemoteVideoTrack, publication: RemoteVideoTrackPublication, participant: RemoteParticipant) { if let remoteView = VideoView.init(frame: self.view.bounds, delegate:self) { videoTrack.addRenderer(remoteView) self.view.addSubview(remoteView) self.remoteView = remoteView } } // MARK: VideoViewDelegate // Lastly, we can subscribe to important events on the VideoView func videoViewDimensionsDidChange(view: VideoView, dimensions: CMVideoDimensions) { self.view.setNeedsLayout() }
self.trtcCloud = [TRTCCloud sharedInstance]; // Play back the camera (primary stream) image of `denny` [self.trtcCloud startRemoteView:@"denny" streamType:TRTCVideoStreamTypeBig view:cameraView];
//TodisconnectfromaRoom,wecall: room?.disconnect() //ThisresultsinacallbacktoRoomDelegate#roomDidDisconnect(room:Room,error:Error?) //MARK:RoomDelegate funcroomDidDisconnect(room:Room,error:Error?){ print("Disconnectedfromroom\\(room.name)") }
self.trtcCloud = [TRTCCloud sharedInstance]; // Exit the current room [self.trtcCloud exitRoom]; // Listen the `onExitRoom` callback to get notification - (void)onExitRoom:(NSInteger)reason { if (reason == 0) { NSLog(@"Exit current room by calling the 'exitRoom' api of sdk ..."); } else if (reason == 1) { NSLog(@"Kicked out of the current room by server through the restful api..."); } else if (reason == 2) { NSLog(@"Current room is dissolved by server through the restful api..."); } }
Feedback