-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
Hello. I just have a problem about creating Producer.
I'm making video chat application using MQTT and Mediasoup.
When I call the "SendTransport.createProducer()" function, it returns nil always. I don't know why.
Could you give me some advices?
Here are my sample code
// Mediasoup Class
private func generateSendTransport(params: [String:Any]) {
if(device == nil){
return
}
do{
let transportParams = try? JSONSerialization.data(withJSONObject: params)
if(transportParams == nil){
return
}
let decoded = try? JSONDecoder().decode(TransportParams.self, from: transportParams!)
if(decoded == nil){
return
}
let iceParameters = try JSONEncoder().encode(decoded!.iceParameters)
let iceCandidates = try JSONEncoder().encode(decoded!.iceCandidates)
let dtlsParameters = try JSONEncoder().encode(decoded!.dtlsParameters)
let sctpParameters = try JSONEncoder().encode(decoded!.sctpParameters)
let appData = try JSONEncoder().encode(decoded!.appData)
sendTransport = try device!.createSendTransport(
id: decoded!.id,
iceParameters: String(data: iceParameters, encoding: .utf8)!,
iceCandidates: String(data: iceCandidates, encoding: .utf8)!,
dtlsParameters: String(data: dtlsParameters, encoding: .utf8)!,
sctpParameters: String(data: sctpParameters, encoding: .utf8)!,
appData: nil)
sendTransport?.delegate = self
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 1.0) {[self] in
produce()
}
}catch{
return
}
}
private func produce() {
videoProducer = try? sendTransport?.createProducer(for: videoTrack!, encodings: nil, codecOptions: nil, codec: nil, appData: nil)
audioProducer = try? sendTransport?.createProducer(for: audioTrack!, encodings: nil, codecOptions: nil, codec: nil, appData: nil)
}
// End of Mediasoup class
// Delegate of Transport
extension RfUnityRoom : SendTransportDelegate {
func onProduce(transport: Mediasoup.Transport, kind: Mediasoup.MediaKind, rtpParameters: String, appData: String, callback: @escaping (String?) -> Void) {
let me = getMe()
if(me == nil){
return
}
mqtt?.sendMessage(topic: reqTopic, request: [
"type": "produce",
"payload": [
"conferenceID": roomId,
"endpointID": me!.uuid,
"transportId": transport.id,
"rtpParameters": rtpParameters,
"kind": kind,
"appData": appData,
] as[String:Any],
])
}
func onProduceData(transport: Mediasoup.Transport, sctpParameters: String, label: String, protocol dataProtocol: String, appData: String, callback: @escaping (String?) -> Void) {
}
func onConnect(transport: Mediasoup.Transport, dtlsParameters: String) {
let me = getMe()
if(me == nil){
return
}
mqtt?.sendMessage(topic: reqTopic, request: [
"type": "connectWebRtcTransport",
"payload": [
"conferenceID": roomId,
"endpointID": me!.uuid,
"transportId": transport.id,
"dtlsParameters": dtlsParameters,
] as [String:Any],
])
}
func onConnectionStateChange(transport: Mediasoup.Transport, connectionState: Mediasoup.TransportConnectionState) {
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels