Giter Site home page Giter Site logo

ethand91 / mediasoup-ios-client Goto Github PK

View Code? Open in Web Editor NEW
130.0 11.0 63.0 196.57 MB

Mediasoup 3 iOS Client

License: ISC License

Objective-C++ 47.96% Objective-C 48.84% CMake 1.38% Ruby 1.82%
mediasoup libmediasoupclient ios webrtc ios-sdk objective-c objective-c-plus-plus

mediasoup-ios-client's Introduction

mediasoup-ios-client

Objective-C wrapper library for libmediasoupclient for building mediasoup iOS based applications.

This project supports both 64 bit iOS devices and 64 bit iOS Simulators

Cocoapods version License

Website and Documentation

Support Forum


Getting Started

Cocoapods

Add the below into your Podfile:

use_frameworks!

target "target" do
  pod "mediasoup_ios_client"
end

You will need to set enable bitcode to false

Due to the size of the WebRTC.framework with bitcode, it cannot be uploaded to Github.

Swift users will need to implement a Objective-C Bridging Header

Bridging header sample:

https://github.com/ethand91/mediasoup-ios-client-sample/blob/master/mediasoup-ios-cient-sample/mediasoup-ios-cient-sample-Bridging-Header.h

Documentation

API

https://github.com/ethand91/mediasoup-ios-client/blob/master/documentation/Api.md

INSTALLATION (Only needed for development, not needed if you only intent to use the project)

https://github.com/ethand91/mediasoup-ios-client/blob/master/documentation/Installation.md

Usage Example

#import "mediasoup_client_ios/Mediasoupclient.h

// Initialize the underlaying libmediasoupclient
[Mediasoupclient initializePC];

// Create a Device
MediasoupDevice *device = [[MediasoupDevice alloc] init];

// Communicate with our server app to retrieve router RTP capabilities
NSString *routerRtpCapabilities = [mySignalling request:@"getRouterRtpCapabilities"];

// Load the device with the routerRtpCapabilities
[device load:routerRtpCapabilities];

// Check whether we can produce video to the router
if ![device canProduce:@"video"] {
 NSLog(@"cannot produce video");
 // Abort next steps
}

// Create a transport in the server for sending our media through it
NSDictionary *transportData = [mySignalling request:@"createTransport"];

// Object to handle SendTransportListener events
@interface SendTransportHandler: NSObject<SendTransportListener>
@property (nonatomic) id delegate;
@end

@implementation SendTransportHandler
-(void)onConnect:(Transport *)transport dtlsParameters:(NSString *)dtlsParameters {
 // Here we communicate out local parameters to our remote transport
 [mySignalling request:@"transport-connect" transportId:[transport getId] dtlsParameters:dtlsParameters];
}

-(void)onConnectionStateChange:(Transport *)transport connectionState:(NSString *)connectionState {
 NSLog(@"sendTransport::onConnectionStateChange newState = %@", connectionState);
}

-(NSString *)onProduce:(Transport *)transport kind:(NSString *)kind rtpParameters:(NSString *)rtpParameters appData:(NSString *)appData callback:(void(^)(NSString *))callback {
 // Here we must communicate our local parameters to our remote transport
 NSString *id = [mySignalling request:@"produce" transportId:[transport getId] kind:kind rtpParameters:rtpParameters appData:appData];
 
 callback(id);
}
@end

SendTransport *sendTransport = [device createSendTransport:sendTransportHandler.delegate id:transportData["id"] iceParameters:transportData["iceParameters"] iceCandidates:transportData["iceCandidates"] dtlsParameters:transportData["dtlsParameters"]];

// Get the device camera
NSArray *devices = [AVCaptureDevice devicesWithMediaType: AVMediaTypeVideo];

// Start capturing it
RTCPeerConnectionFactory *factory = [[RTCPeerConnectionFactory alloc] init];
RTCCameraVideoCapturer *videoCapturer = [[RTCCameraVideoCapturer alloc] init];
[videoCapturer startCaptureWithDevice:devices[0] format:[devices[0] activeFormat] fps:30];
RTCVideoSource *videoSource = [factory videoSource];
[videoSource adaptOutputFormatToWidth:640 height:480 fps:30];

RTCVideoTrack *videoTrack = [factory videoTrackWithSource:videoSource trackId:@"trackId"];

// Handler to handle producer events
@interface ProducerHandler : NSObject<ProducerListener>
@property (nonatomic) id delegate;
@end

@implementation ProducerHandler
-(void)onTransportClose:(Producer *)producer {
 NSLog(@"Producer::onTransportClose");
}
@end

// Produce out camera video
Producer *videoProducer = [sendTransport produce:producerHandler.delegate track:videoTrack encodings:nil codecOptions:nil];

Contributing

Clone the repo and install submodules

Due to the size of the WebRTC static library it cannot be uploaded to Github, therefore you will need to follow the instructions in the build folder and build it yourself. (This step is only needed for development, not for library usage)

git clone https://github.com/ethand91/mediasoup-ios-client.git
git submodule init
git submodule update

Unfortunately my Macbook broke and I currently can't afford a new one. :( Will continue this project when I get a new mac.


Like my work? Any support is appreciated.

Buy Me A Coffee

mediasoup-ios-client's People

Contributors

ethand91 avatar fedulvtubudul avatar pablito25sp avatar rockjan avatar simonpickup avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mediasoup-ios-client's Issues

use VP8

how can I use VP8, when i use VP8, did not work
-(instancetype)initWithNativeConsumer:(NSValue *)nativeConsumer {
self = [super init];
if (self) {
self._nativeConsumer = nativeConsumer;

    webrtc::MediaStreamTrackInterface *nativeTrack = [ConsumerWrapper getNativeTrack:self._nativeConsumer];
    rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track(nativeTrack);

// RTCPeerConnectionFactory *factory = [[RTCPeerConnectionFactory alloc] init];

    RTCVideoCodecInfo *info = [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp8Name];
    RTC_OBJC_TYPE(RTCDefaultVideoDecoderFactory) *decoderFactory = [[RTC_OBJC_TYPE(RTCDefaultVideoDecoderFactory) alloc] init];
    RTC_OBJC_TYPE(RTCDefaultVideoEncoderFactory) *encoderFactory = [[RTC_OBJC_TYPE(RTCDefaultVideoEncoderFactory) alloc] init];

    [encoderFactory setPreferredCodec:info];

    RTCPeerConnectionFactory *factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] initWithEncoderFactory:encoderFactory decoderFactory:decoderFactory];
    
    self._nativeTrack = [RTCMediaStreamTrack mediaTrackForNativeTrack:track factory:factory];
    free(factory);
}

return self;

}

iOS 运行之后 点击按钮没有反应 出现以下报错

@ethand91 objc[4211]: Class RTCAudioSessionDelegateAdapter is implemented in both /private/var/containers/Bundle/Application/62D8A3B1-DE3F-4834-B559-2700962BA893/mediasoup-ios-cient-sample.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x101b4d590) and /private/var/containers/Bundle/Application/62D8A3B1-DE3F-4834-B559-2700962BA893/mediasoup-ios-cient-sample.app/Frameworks/WebRTC.framework/WebRTC (0x101439200). One of the two will be used. Which one is undefined.

CFBundleIdentifier Collision

When trying to submit the app, I'm getting a transporter error with version 1.2.3:

[01:06:11]: ERROR ITMS-90685: "CFBundleIdentifier Collision. There is more than one bundle with the CFBundleIdentifier value 'org.webrtc.WebRTC' under the iOS application 'fuu.app'."
ERROR ITMS-90205: "Invalid Bundle. The bundle at 'fuu.app/Frameworks/mediasoup_client_ios.framework' contains disallowed nested bundles."
ERROR ITMS-90206: "Invalid Bundle. The bundle at 'fuu.app/Frameworks/mediasoup_client_ios.framework' contains disallowed file 'Frameworks'."
\nERROR ITMS-90206: "Invalid Bundle. The bundle at 'fuu.app/Frameworks/mediasoup_client_ios.framework' contains disallowed file 'Frameworks'."ifier value 'org.webrtc.WebRTC' under the iOS application 'fuu.app'."
The call to the iTMSTransporter completed with a non-zero exit status: 1. This indicates a failure.

local video stops displaying when calling SendTransport.produce

お疲れ様です!🙂

Thanks for creating this framework.
I've been mostly sticking to the implementation of your sample app https://github.com/ethand91/mediasoup-ios-client-sample
but when

let kindProducer: Producer = sendTransport.produce(producerHandler,
                                                   track: track,
                                                   encodings: nil, // as suggested by your other issue
                                                   codecOptions: codecOptions)
print("test")

is called, it fails silently (test is not printed) and the RTCEAGLVideoView (or RTCMTLVideoView) used to render the VideoTrack stops showing the video input. I can confirm that the VideoView is working by not calling produce.

Do you have any idea what I'm missing?

Best Regards,
Martin

APP crashed on -[SendTransport produce:track:encodings:codecOptions] method. [ERROR] transport_wrapper::+[TransportWrapper nativeProduce:listener:track:encodings:codecOptions:appData:]() | The associated promise has been destructed prior to the associated state becoming ready.

Thank for writing this framework.
I met a crash when called -[SendTransport produce:track:encodings:codecOptions] method.
The error log shows as:[ERROR] transport_wrapper::+TransportWrapper nativeProduce:listener:track:encodings:codecOptions:appData: | The associated promise has been destructed prior to the associated state becoming ready.
I'm using version 1.4.1
I pasted the total log in this file.
errorLog.txt

I also found out that the NO.37 issue produced the same error, and I tried the method as MartinP7r said. But it does not work for me.
#37 (comment)

if necessary, I can provide the source project.

Best Regards,
Michael

repeat implement

objc[4784]: Class RTCEncodedImage is implemented in both /private/var/containers/Bundle/Application/C6374C37-10CF-4763-8FC7-7C808A2D924B/mediasoup-ios-cient-sample.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x105d96348) and /private/var/containers/Bundle/Application/C6374C37-10CF-4763-8FC7-7C808A2D924B/mediasoup-ios-cient-sample.app/Frameworks/WebRTC.framework/WebRTC (0x10559e760). One of the two will be used. Which one is undefined.
objc[4784]: Class RTCRtpFragmentationHeader is implemented in both /private/var/containers/Bundle/Application/C6374C37-10CF-4763-8FC7-7C808A2D924B/mediasoup-ios-cient-sample.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x105d96398) and /private/var/containers/Bundle/Application/C6374C37-10CF-4763-8FC7-7C808A2D924B/mediasoup-ios-cient-sample.app/Frameworks/WebRTC.framework/WebRTC (0x10559e7b0). One of the two will be used. Which one is undefined.

WebRTC framework implemented twice

objc[24967]: Class RTCAudioSessionDelegateAdapter is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729b858) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c234d8). One of the two will be used. Which one is undefined.
objc[24967]: Class DeviceInfoIosObjC is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729bc68) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c23528). One of the two will be used. Which one is undefined.
objc[24967]: Class RTCVideoCaptureIosObjC is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729bcb8) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c23578). One of the two will be used. Which one is undefined.
objc[24967]: Class RTCAudioSession is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729b8a8) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c235c8). One of the two will be used. Which one is undefined.
objc[24967]: Class RTCAudioSessionConfiguration is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729b8f8) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c23618). One of the two will be used. Which one is undefined.
objc[24967]: Class RTCNativeAudioSessionDelegateAdapter is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729b948) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c23668). One of the two will be used. Which one is undefined.
objc[24967]: Class RTCEncodedImage is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729b9c0) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c236e0). One of the two will be used. Which one is undefined.
objc[24967]: Class RTCRtpFragmentationHeader is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729ba10) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c23730). One of the two will be used. Which one is undefined.
objc[24967]: Class RTCVideoCapturer is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729ba38) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c23758). One of the two will be used. Which one is undefined.
objc[24967]: Class RTCVideoCodecInfo is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729ba88) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c237a8). One of the two will be used. Which one is undefined.
objc[24967]: Class RTCVideoEncoderQpThresholds is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729bad8) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c237f8). One of the two will be used. Which one is undefined.
objc[24967]: Class RTCVideoEncoderSettings is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729bb50) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c23870). One of the two will be used. Which one is undefined.
objc[24967]: Class RTCVideoFrame is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729bb78) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c23898). One of the two will be used. Which one is undefined.
objc[24967]: Class RTCDispatcher is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729bbf0) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c249a0). One of the two will be used. Which one is undefined.
objc[24967]: Class RTCCameraPreviewView is implemented in both /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/mediasoup_client_ios.framework/mediasoup_client_ios (0x10729bc18) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c249c8). One of the two will be used. Which one is undefined.
objc[24967]: Class RTCCVPixelBuffer is implemented in both /System/Library/PrivateFrameworks/WebCore.framework/Frameworks/libwebrtc.dylib (0x20c5a09a0) and /private/var/containers/Bundle/Application/DB88FAAB-AF8E-405A-92A6-9C54F9B3EC55/Fuu.app/Frameworks/WebRTC.framework/WebRTC (0x106c24ab8). One of the two will be used. Which one is undefined.

pod installing mediasoup_ios_client error

[!] Error installing mediasoup_ios_client
[!] Failed to download 'mediasoup_ios_client': [!] /usr/bin/git -C /var/folders/s0/h_pcj4wj3hxfy4y0k2v8ryz40000gp/T/d20200303-91582-1ivqlky submodule update --init --recursive

Submodule path 'mediasoup-client-ios/dependencies/libmediasoupclient': checked out 'a75cf2a77ef1dd6b0b52b1a16596d65ef8fe6e83'
Submodule 'mediasoup-client-ios/dependencies/libmediasoupclient' (https://github.com/ethand91/libmediasoupclient.git) registered for path 'mediasoup-client-ios/dependencies/libmediasoupclient'
Submodule 'mediasoup-client-ios/dependencies/webrtc/src' (https://github.com/ethand91/webrtc-mac-src.git) registered for path 'mediasoup-client-ios/dependencies/webrtc/src'
Cloning into '/private/var/folders/s0/h_pcj4wj3hxfy4y0k2v8ryz40000gp/T/d20200303-91582-1ivqlky/mediasoup-client-ios/dependencies/libmediasoupclient'...
Cloning into '/private/var/folders/s0/h_pcj4wj3hxfy4y0k2v8ryz40000gp/T/d20200303-91582-1ivqlky/mediasoup-client-ios/dependencies/webrtc/src'...
error: Server does not allow request for unadvertised object fba755df2ea8163a5bbefb7e8e7c58dec433534a
Fetched in submodule path 'mediasoup-client-ios/dependencies/webrtc/src', but it did not contain fba755df2ea8163a5bbefb7e8e7c58dec433534a. Direct fetching of that commit failed.

Error "Failed to set remote offer sdp: Duplicate a=mid value '2'"

It happen whem i'm trying to receive 2 and more consumers!
"
Receive: message
SocketNotificationResponse(method: EBSWebRTCiOS.Methods.newConsumer, payload: Optional({
"kind" : "audio",
"appData" : {
"peerId" : "5e900aad9373cc2d9546806d",
"source" : "mic"
},
"type" : "simple",
"peerId" : "5e900aad9373cc2d9546806d",
"id" : "a8c5c217-f7d4-4896-8732-97617679c52b",
"producerPaused" : false,
"producerId" : "2daec80e-721e-4113-97e6-79084fce3a11",
"rtpParameters" : {
"codecs" : [
{
"channels" : 2,
"payloadType" : 100,
"rtcpFeedback" : [

    ],
    "mimeType" : "audio\/opus",
    "parameters" : {
      "sprop-stereo" : 1,
      "usedtx" : 1,
      "useinbandfec" : 1,
      "minptime" : 10
    },
    "clockRate" : 48000
  }
],
"headerExtensions" : [
  {
    "parameters" : {

    },
    "encrypt" : false,
    "uri" : "urn:ietf:params:rtp-hdrext:sdes:mid",
    "id" : 1
  },
  {
    "id" : 4,
    "parameters" : {

    },
    "encrypt" : false,
    "uri" : "http:\/\/www.webrtc.org\/experiments\/rtp-hdrext\/abs-send-time"
  },
  {
    "parameters" : {

    },
    "encrypt" : false,
    "uri" : "urn:ietf:params:rtp-hdrext:ssrc-audio-level",
    "id" : 10
  }
],
"encodings" : [
  {
    "ssrc" : 608869349
  }
],
"rtcp" : {
  "reducedSize" : true,
  "mux" : true,
  "cname" : "iaBbtBsUsI5\/yaN\/"
},
"mid" : "2"

}
}))
consumeTrack(consumerInfo:)
Optional("{\n "peerId" : "5e900aad9373cc2d9546806d",\n "source" : "mic"\n}")
2020-06-01 13:22:11.186960+0300 EBSWebRTCiOS_Example[371:42689] *** Terminating app due to uncaught exception 'RuntimeException', reason: 'Failed to set remote offer sdp: Duplicate a=mid value '2'.'"

Crash when using method getRtpParameters from Producer

Error:
libc++abi.dylib: terminating with uncaught exception of type nlohmann::detail::type_error: [json.exception.type_error.302] type must be string, but is object

When call function getRtpParameters from Producer

self.socket.connect won't throw or connect

Without touching the sample-media-server and just changing the config.js listenIps: [ { ip: '192.168.2.2', announcedIp: undefined } ], to my local IP address it seems that my client application refuses to show any sign of connection. I haven't touched the SSL certs from the sample-media-server repo.

I am using the below pods

pod "mediasoup_ios_client", "~> 1.5.0"
pod "Starscream", "~> 4.0.3"

Starscream made some minor changes so I had to change EchoSocket to the below initialization.

func connect(wsUri: String) throws {
    /*
     if !wsUri.starts(with: "ws://") || !wsUri.starts(with: "wss://") {
     throw SocketError.INVALID_WS_URI
     }
     */
    
    if (self.socket != nil && isConnected) {
      return
    }
    
    let request = URLRequest(url: URL(string: wsUri)!)

    // Allow self-signed certificates
    // Load certificates and public keys into an app bundle, use the builtin pinner and TrustKit.
    let pinner = FoundationSecurity(allowSelfSigned: true) // don't validate SSL certificates

    self.socket = WebSocket.init(request: request, certPinner: inner)
    // ^^^^^^ Initializing the socket changed to latest Starscream pod ^^^^^^

    // Handle socket delegate methods on the global thread (semaphor will lock if not set to global..)
    self.socket!.callbackQueue = DispatchQueue.global()
    self.socket!.delegate = self
    self.socket!.connect()
  }

Below is my code, trying to keep it short to make sure I understand the steps.

import Foundation
import Combine
import SwiftyJSON
import WebRTC

final internal class HostBroadcastViewModel: ObservableObject, Identifiable {
  
  public let roomId: String
  
  private let disposables = Set<AnyCancellable>()
  private let socket: IMediaSocket
  
  private var room: IRoomManager?
  private var roomDelegate: RoomListener?
  
  init(mediaSocket: IMediaSocket, roomId: String) {
    socket = mediaSocket
    self.roomId = roomId
  }
  
  func startBroadcasting() {
    self.socket.register(observer: self)
    print("Will connect to server")
    
    do {
      try self.socket.connect(wsUri: "wss://192.168.2.2:443") // Doesn't throw or any sign of connection
    } catch {
      print("Failed to connect to server")
    }
    
  }
  
  private func handleWebSocketConnected() {
    // Initialize mediasoup client
    initializeMediasoup()
    
    // Get router rtp capabilities
    let getRoomRtpCapabilitiesResponse: JSON = Request.shared.sendGetRoomRtpCapabilitiesRequest(socket: socket, roomId: roomId)
    print("response! " + getRoomRtpCapabilitiesResponse.description)
    let roomRtpCapabilities: JSON = getRoomRtpCapabilitiesResponse["roomRtpCapabilities"]
    print("roomRtpCapabilities " + roomRtpCapabilities.description)
    
    // Initialize mediasoup device
    let device: MediasoupDevice = MediasoupDevice.init()
    device.load(roomRtpCapabilities.description)
    
    print("handleWebSocketConnected() device loaded")
    
    room = AppDependencyContainer.shared.createMediasoupRoomManager(socket: socket, device: device, roomId: roomId)
    roomDelegate = self
    room!.roomListener = roomDelegate
    
    // Join the room
    do {
      try room!.join()
    } catch {
      print("failed to join room")
      return
    }
    
    // Create recv webrtcTransport
    room!.createRecvTransport()
    // Create send webrtcTransport
    room!.createSendTransport()
    
    // Start media capture/sending
//    self.displayLocalVideo()
  }
  
  private func initializeMediasoup() {
    Mediasoupclient.initialize()
    print("initializeMediasoup() client initialized")
    
    // Set mediasoup log
    Logger.setLogLevel(LogLevel.WARN)
    Logger.setDefaultHandler()
  }
  
}

extension HostBroadcastViewModel : MessageObserver {
  func on(event: String, data: JSON?) { 
    // Never invoked after connect() is called
    switch event {
      case ActionEvent.OPEN:
        print("socket connected")
        self.handleWebSocketConnected()
        break
      case ActionEvent.NEW_USER:
        print("NEW_USER id =" + data!["userId"]["userId"].stringValue)
        break
      case ActionEvent.NEW_CONSUMER:
        print("NEW_CONSUMER data=" + data!.description)
        self.handleNewConsumerEvent(consumerInfo: data!["consumerData"])
        break
      default:
        print("Unknown event " + event)
    }
  }
  
  private func handleNewConsumerEvent(consumerInfo: JSON) {
    print("handleNewConsumerEvent info = " + consumerInfo.description)
    // Start consuming
    room!.consumeTrack(consumerInfo: consumerInfo)
  }
}


// Extension for RoomListener
extension HostBroadcastViewModel : RoomListener {
  func onNewConsumer(consumer: Consumer) {
    print("RoomListener::onNewConsumer kind=" + consumer.getKind())
    
    if consumer.getKind() == "video" {
      let videoTrack: RTCVideoTrack = consumer.getTrack() as! RTCVideoTrack
      videoTrack.isEnabled = true
//      videoTrack.add(self.remoteVideoView) - I have to see how to bind this in SwiftUI
    }
    
    do {
      consumer.getKind() == "video"
        ? try room!.resumeRemoteVideo()
        : try room!.resumeRemoteAudio()
    } catch {
      print("onNewConsumer() failed to resume remote track")
    }
  }
}

Server starting successfully

initializeWorkers() [num:8]
websocket SSL server running on port 443

Config.js

const os = require('os');

module.exports = Object.freeze({
  numWorkers: Object.keys(os.cpus()).length,
  worker: {
    logLevel: 'debug',
    logTags: [
      'rtp',
      'rtcp',
      'ice',
      'dtls'
    ],
    rtcMinPort: 40000,
    rtcMaxPort: 49999
  },
  router: {
    mediaCodecs: [
      {
        kind: 'audio',
        mimeType: 'audio/opus',
        clockRate: 48000,
        channels: 2,
      },
      {
        kind: 'video',
        mimeType: 'video/VP8',
        clockRate: 90000,
      }
    ]
  },
  webRtcTransport: {
    listenIps: [ { ip: '192.168.2.2', announcedIp: undefined } ],
    enableUdp: true,
    enableTcp: true,
    preferUdp: true,
    preferTcp: false
  }
});

Any help how to debug is appreciated

Support multiple architectures

Currently the library supports arm64 and x86_64, however the built framework only supports arm64.

I will look into supporting multiple architectures however due to the size of a fat libwebrtc.a library, I may only support 64 bit. With 32 bit included libwebrtc.a can go over 2GB..

Reconnection after a network failure.

I can‘t find a way to reconnect after the app disconnected with server in your demo. Because mediasoup is more higher level than WebRTC.framework, we can't use WebRTC functions to handle the reconnection. So what is the best practice of a reconnection? Should we follow the steps as this: reinit a websocket and recreateTransport -> rejoinRoom -> recreateProducer -> recreateConsumer or mediasoup has another efficient way?

'error creating transceiver'

in v 1.3.3
when i'm try to call transport.produce crash with 'error creating transceiver'
please help me, thanks

[TransportWrapper nativeProduce:listener:track:encodings:codecOptions:appData:]

Support cocoapods

Support cocoapods so the framework does not need to be uploaded each time.

Due to the dependencies and build steps needed this is pretty hard to implement.
If anyone has any experience uploading objective-C++ frameworks to cocoapods, help would be greatly appreciated.

PeerConnectionFactory

One of the issues I've ben stumbling on, is the fact that libmediasoupclient always uses the C++ APIs, while in fact in some cases, specifically MacOS (but probably also others), the video/audio encoders/decoders are defined in the Objective C layer. Since libmediasoupclient uses the default factories not all the features of the platform are explored or used. The fact that the iOS/Mac client does not pass its own factories causes that H264 uses ffmpeg instead of hardware decoding/encoding. I've implemented some fix in my branch as a gap measure to fix it, but I'm not submitting as PR since there might be cleaner way of handling that.

Error on MediasoupDevice.createSendTransport

I'm trying to create sendTransport and got error.

*** Terminating app due to uncaught exception 'RuntimeException', reason: '[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal'

I think that problem could be somewhere in iceParameters, iceCandidates or dtlsParameters...
I'm using Codable approach and short extension to encode this parameters before using.

var jsonEncoded: String {
        guard let jsonData = try? JSONEncoder().encode(self) else {
            fatalError("Encoding error")
        }
        return String(data: jsonData, encoding: .utf8)!
  }

Nothing special. And this encoding worked with MediasoupDevice.load method..
Can someone help me resolve this issue?

Where can I find the file “Device.h”

error: mediasoup-ios-client/mediasoup-client-ios/include/Device.h: No such file or directory (in target 'mediasoup-client-ios' from project 'mediasoup-client-ios')

+[Mediasoupclient cleanup]: unrecognized selector sent to class 0x1022cb1e8

I can't understand that crash but there indeed has a declaration in the .h file.

I call this method when i prepared to dispose the sdk and finish a conference.
Maybe i called this method in a wrong way, please correct me, thank you!

PS: I run the sdk with the version: 1.4.1 (upgrade from 1.2.3)

#import "Device.hpp" file not found

#import "Device.hpp" file not found
#import "Logger.hpp" file not found
#import "Mediasoupclient.h" file not found
...
help me .thank you !

Please help

Hi, sorry for my stupid question, but I need some explanations during the implementation this line of code:

// Communicate with our server app to retrieve router RTP capabilities
NSString *routerRtpCapabilities = [mySignalling request:@"getRouterRtpCapabilities"];

So, can you explain me what is the object "mySignalling" and where can i get it? or create some working demo iOS project - so i can better understand how it works

Thanks

Can't publish app on TestFlight

I try to publish Example app with mediasoup-ios-client integrated like a pod
had errors :
Screen Shot 2020-06-09 at 10 10 09
Screen Shot 2020-06-09 at 10 38 39
Could you help me to solve this problem. Thanks!

considerable memory leaks when trying to leave room

When I leave a room (closing and removing all producers, consumers, transports). About 30mb of memory are not being released.
I was wondering if you've been experiencing the same?
Below some screenshots of my runtime memory view:
(I'd also post your Logger's data, but seems to be to much data for github to display. If you need it i'll find another way)

VideoConf_xcworkspace

VideoConf_xcworkspace-2

Does not support vp9

Hello, not in the demo webRTC does not support vp9, I changed a new webTRC, cause crashes.

About the use of vp9

Hello, I have been able to use VP9, thank you very much! However, I ran into a problem that my vp9 encoding was not recognized by the counter. Could you please test whether using vp9 in your place is normal? Thank you very much for your help!

1.2.2: onProduce:kind:rtpParameters:callback: unrecognized selector sent to instance

The SendTransportListener protocol requires this method to be implemented:

func onProduce(_ transport: Transport!, kind: String!, rtpParameters: String!, appData: String!, callback: ((String?) -> Void)!)

But the selector that is being sent to the instance is different:

[fuu.WebRtcSendRoom onProduce:kind:rtpParameters:callback:]
[fuu.WebRtcSendRoom onProduce:kind:rtpParameters:callback:]: unrecognized selector sent to instance 0x281964d20
2020-04-05 23:50:23.801767+0200 fuu[807:173143] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[fuu.WebRtcSendRoom onProduce:kind:rtpParameters:callback:]: unrecognized selector sent to instance 0x281964d20'

Created a lot of threads

When I use it, I find that a lot of threads are created. Have you ever encountered?
After about 5 calls, the thread created about 100.

Symbol(s) not found for architecture x86_64

Hey, thank you for starting this project! However, after importing the frameworks, I cant build (it seems like the lib was only build for iOS-arm64):

ld: warning: ignoring file /Users/asd/Projects/test/test-mediasoup/mediasoup_client_ios.framework/mediasoup_client_ios, building for iOS Simulator-x86_64 but attempting to link with file built for iOS-arm64
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_Device", referenced from:
      objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture x86_64

Am I missing something?
Thanks!

Can`t build mediasoup-ios-client source code

Thanks for your share!

According to your instructions, I had compiles libwebRTC.a and libmediasoupclient.a.
But when compile source code in Xcode, I got error.
In webrtc module, it's warning "Must define either WEBRTC_WIN or WEBRTC_POSIX."!
I`m not good in c++, Can you tell me how to resolve such as problems as this?

Hope to receive your guidance

AA79A8E1-9020-4A1F-83D5-3FFEF822683C
Hello, I use mediasoup directly - ios - the client - master/build/mediasoup_client_ios framework test, and doesn't support vp9.Or am I using method is not correct.Request you to give me a clear instruction.Very thank you.

Asking questions

First study mediasoup webrtc

How to modify request.swift for protoo.websocket used by server

What information can I refer to

Support bitcode

As the title says.

Rebuilding libwebrtc.a with bitcode support should resolve this.

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.