Repository: HaishinKit/HaishinKit.swift

Issue #821: Connection always NetConnection.Connect.Closed
Created: 2021-02-04T09:39:55Z
Describe the bug
When I try to connect to rmtp server, the notification event always reports NetConnection.Connect.Closed.
To Reproduce
The RTMP server url I'm using looks something like this, it is an AWS server, there is no authentication
rtmp://3.127.38.148/5WF7f3WEo8few5f4Pf9e84/ZQZQsmgDPxpCcrnbxaEhIEtJwKhMfj?psk=161037020796912143250530521225
This url is generated before the stream starts, I receive this url from API and then in the callback I call the connect function.
Smartphone (please complete the following information):

Device: iPhone 11, iPhone 8
OS:  iOS 14.3

I'm building and compiling on Mac M1
Additional context
I thought it might be the url address that's wrong, but later I tried another streaming library LFLiveKit and it worked immediately, and the Android version of the app I'm working on also works without problems, so I've been wondering what's wrong here.
I did the setup same way it is showed in the example, only it will never connect and it gets closed immediately.
Thanks you for help! I really like this library and would be sad to not be able to use it :)

Duplicate issue #817: Wrong NetStream.Publish.Start code with Live Streaming on AWS
Created: 2021-01-29T11:45:51Z
Describe the bug
I can have a few devices, which shows that they are streaming via RTMP on AWS.
But in fact, only the first device has been streaming.
To Reproduce
At the same time I can have a few devices which shows active streaming with active current FPS, totalBytes In, totalBytes Out values.
Expected behavior
As with local RTMP Server, I got error with "NetStream.Publish.BadName" code and description "Stream already publishing"
Screenshots


Devices:

OS: iOS, macOS
HaishinKit version 1.1.2

Device logs with AWS
2021-01-29 13:18:14.744474+0200 Example iOS[15449:4045280] Metal API Validation Enabled
2021-29-01 13:18:14.827 [Info] [com.haishinkit.Exsample.iOS] [LiveViewController.swift:80] viewWillAppear(_:) > viewWillAppear
2021-29-01 13:18:14.835 [Warn] [com.haishinkit.Exsample.iOS] [LiveViewController.swift:83] viewWillAppear(_:) > Error Domain=AVFoundationErrorDomain Code=-11852 "Cannot use iPhone Microphone" UserInfo={NSLocalizedFailureReason=This app is not authorized to use iPhone Microphone., AVErrorDeviceKey=<AVCaptureFigAudioDevice: 0x2812fe220 [iPhone Microphone][com.apple.avfoundation.avcapturedevice.built-in_audio:0]>, NSLocalizedDescription=Cannot use iPhone Microphone}
2021-29-01 13:18:14.853 [Info] [com.haishinkit.HaishinKit] [VideoIOComponent.swift:96] fps > (fps: 30.0, duration: __C.CMTime(value: 100, timescale: 3000, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0))
2021-29-01 13:18:55.183 [Debug] [com.haishinkit.HaishinKit] [RTMPConnection.swift:462] didSetReadyState(_:) > uninitialized
2021-29-01 13:18:55.381 [Debug] [com.haishinkit.HaishinKit] [RTMPConnection.swift:462] didSetReadyState(_:) > versionSent
2021-29-01 13:18:55.432 [Debug] [com.haishinkit.HaishinKit] [RTMPConnection.swift:462] didSetReadyState(_:) > ackSent
2021-29-01 13:18:55.476 [Debug] [com.haishinkit.HaishinKit] [RTMPConnection.swift:462] didSetReadyState(_:) > handshakeDone
2021-29-01 13:18:55.481 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: zero,streamId: 3,message: Optional(RTMPCommandMessage{type: amf0Command,length: 272,streamId: 0,timestamp: 0,payload: 260 bytes,objectEncoding: amf0,commandName: connect,transactionId: 1,commandObject: Optional(["capabilities": Optional(239), "swfUrl": nil, "app": Optional("live"), "audioCodecs": Optional(1024), "tcUrl": Optional("rtmp://52.19.18.94:1935/live"), "pageUrl": nil, "videoFunction": Optional(1), "videoCodecs": Optional(128), "fpad": Optional(false), "objectEncoding": Optional(0), "flashVer": Optional("FMLE/3.0 (compatible; FMSc/1.0)")]),arguments: [],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:18:55.656 [Trace] [com.haishinkit.HaishinKit] [RTMPConnection.swift:520] listen(_:) > RTMPChunk{size: 128,type: zero,streamId: 3,message: Optional(RTMPCommandMessage{type: amf0Command,length: 236,streamId: 0,timestamp: 0,payload: 236 bytes,objectEncoding: amf0,commandName: _result,transactionId: 1,commandObject: Optional(["capabilities": Optional(31.0), "fmsVer": Optional("FMS/3,5,1,525"), "mode": Optional(1.0)]),arguments: [Optional(["description": Optional("Connection succeeded."), "code": Optional("NetConnection.Connect.Success"), "data": Optional(["version": Optional("3,5,1,525")]), "objectEncoding": Optional(0.0), "level": Optional("status")])],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:18:55.658 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: zero,streamId: 2,message: Optional(RTMPSetChunkSizeMessage{type: chunkSize,length: 16,streamId: 0,timestamp: 0,payload: 4 bytes,size: 8192}),fragmented: false,_data: 12 bytes}
2021-29-01 13:18:55.659 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: zero,streamId: 3,message: Optional(RTMPCommandMessage{type: amf0Command,length: 37,streamId: 0,timestamp: 0,payload: 25 bytes,objectEncoding: amf0,commandName: createStream,transactionId: 2,commandObject: nil,arguments: [],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:18:55.659 [Info] [com.haishinkit.Exsample.iOS] [LiveViewController.swift:159] rtmpStatusHandler(_:) > NetConnection.Connect.Success
2021-29-01 13:18:55.659 [Trace] [com.haishinkit.HaishinKit] [RTMPConnection.swift:520] listen(_:) > RTMPChunk{size: 128,type: zero,streamId: 2,message: Optional(RTMPWindowAcknowledgementSizeMessage{type: windowAck,length: 4,streamId: 0,timestamp: 0,payload: 4 bytes,size: 2500000}),fragmented: false,_data: 12 bytes}
2021-29-01 13:18:55.660 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: zero,streamId: 2,message: Optional(RTMPWindowAcknowledgementSizeMessage{type: windowAck,length: 16,streamId: 0,timestamp: 0,payload: 4 bytes,size: 2500000}),fragmented: false,_data: 12 bytes}
2021-29-01 13:18:55.661 [Trace] [com.haishinkit.HaishinKit] [RTMPConnection.swift:520] listen(_:) > RTMPChunk{size: 128,type: zero,streamId: 2,message: Optional(RTMPSetPeerBandwidthMessage{type: bandwidth,length: 5,streamId: 0,timestamp: 0,payload: 5 bytes,size: 2500000,limit: dynamic}),fragmented: false,_data: 12 bytes}
2021-29-01 13:18:55.788 [Trace] [com.haishinkit.HaishinKit] [RTMPConnection.swift:520] listen(_:) > RTMPChunk{size: 128,type: zero,streamId: 3,message: Optional(RTMPCommandMessage{type: amf0Command,length: 29,streamId: 0,timestamp: 0,payload: 29 bytes,objectEncoding: amf0,commandName: _result,transactionId: 2,commandObject: Optional([:]),arguments: [Optional(1.0)],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:18:55.789 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: zero,streamId: 3,message: Optional(RTMPCommandMessage{type: amf0Command,length: 57,streamId: 0,timestamp: 0,payload: 45 bytes,objectEncoding: amf0,commandName: FCPublish,transactionId: 3,commandObject: nil,arguments: [Optional("03d83e7d6a98efb0d3e0")],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:18:55.789 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: zero,streamId: 4,message: Optional(RTMPCommandMessage{type: amf0Command,length: 62,streamId: 1,timestamp: 0,payload: 50 bytes,objectEncoding: amf0,commandName: publish,transactionId: 0,commandObject: nil,arguments: [Optional("03d83e7d6a98efb0d3e0"), Optional("live")],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:18:55.833 [Trace] [com.haishinkit.HaishinKit] [RTMPConnection.swift:520] listen(_:) > RTMPChunk{size: 128,type: zero,streamId: 3,message: Optional(RTMPCommandMessage{type: amf0Command,length: 96,streamId: 0,timestamp: 0,payload: 96 bytes,objectEncoding: amf0,commandName: onFCPublish,transactionId: 0,commandObject: Optional([:]),arguments: [Optional(["code": Optional("NetStream.Publish.Start"), "description": Optional("03d83e7d6a98efb0d3e0")])],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:18:55.834 [Info] [com.haishinkit.Exsample.iOS] [LiveViewController.swift:159] rtmpStatusHandler(_:) > NetStream.Publish.Start
2021-29-01 13:18:55.835 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: zero,streamId: 3,message: Optional(RTMPDataMessage{type: amf0Data,length: 145,streamId: 1,timestamp: 0,payload: 133 bytes,objectEncoding: amf0,handlerName: @setDataFrame,arguments: [Optional("onMetaData"), Optional(["framerate": Optional(30.0), "height": Optional(720), "width": Optional(1280), "videocodecid": Optional(7), "videodatarate": Optional(10000)])],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:18:55.880 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: zero,streamId: 9,message: Optional(RTMPVideoMessage{type: video,length: 42,streamId: 1,timestamp: 0,payload: 30 bytes,codec: unknown,status: 0}),fragmented: false,_data: 12 bytes}
2021-29-01 13:18:55.880 [Debug] [com.haishinkit.HaishinKit] [RTMPStream.swift:621] sampleOutput(video:withTimestamp:muxer:) > first video frame was sent
2021-29-01 13:18:55.880 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: one,streamId: 9,message: Optional(RTMPVideoMessage{type: video,length: 7636,streamId: 1,timestamp: 0,payload: 7628 bytes,codec: unknown,status: 0}),fragmented: false,_data: 8 bytes}
2021-29-01 13:18:55.885 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: one,streamId: 9,message: Optional(RTMPVideoMessage{type: video,length: 14563,streamId: 1,timestamp: 0,payload: 14555 bytes,codec: unknown,status: 0}),fragmented: false,_data: 8 bytes}
2021-29-01 13:18:55.910 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: one,streamId: 9,message: Optional(RTMPVideoMessage{type: video,length: 15648,streamId: 1,timestamp: 33,payload: 15640 bytes,codec: unknown,status: 0}),fragmented: false,_data: 8 bytes}
2021-29-01 13:18:55.923 [Trace] [com.haishinkit.HaishinKit] [RTMPConnection.swift:520] listen(_:) > RTMPChunk{size: 128,type: zero,streamId: 3,message: Optional(RTMPCommandMessage{type: amf0Command,length: 148,streamId: 1,timestamp: 0,payload: 148 bytes,objectEncoding: amf0,commandName: onStatus,transactionId: 0,commandObject: Optional([:]),arguments: [Optional(["code": Optional("NetStream.Publish.Start"), "level": Optional("status"), "clientid": Optional("oAACAAAA"), "description": Optional("03d83e7d6a98efb0d3e0 is now published.")])],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:18:55.923 [Info] [com.haishinkit.Exsample.iOS] [LiveViewController.swift:159] rtmpStatusHandler(_:) > NetStream.Publish.Start
2021-29-01 13:18:55.944 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: one,streamId: 9,message: Optional(RTMPVideoMessage{type: video,length: 16043,streamId: 1,timestamp: 33,payload: 16035 bytes,codec: unknown,status: 0}),fragmented: false,_data: 8 bytes}
2021-29-01 13:18:55.976 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: one,streamId: 9,message: Optional(RTMPVideoMessage{type: video,length: 7992,streamId: 1,timestamp: 34,payload: 7984 bytes,codec: unknown,status: 0}),fragmented: false,_data: 8 bytes}
2021-29-01 13:18:56.011 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: one,streamId: 9,message: Optional(RTMPVideoMessage{type: video,length: 2486,streamId: 1,timestamp: 33,payload: 2478 bytes,codec: unknown,status: 0}),fragmented: false,_data: 8 bytes}

Device logs with Local RTMP Server
2021-01-29 13:41:58.267242+0200 Example iOS[6483:3134709] Metal API Validation Enabled
2021-29-01 13:41:58.400 [Info] [com.haishinkit.Exsample.iOS] [LiveViewController.swift:80] viewWillAppear(_:) > viewWillAppear
2021-29-01 13:41:58.416 [Info] [com.haishinkit.HaishinKit] [VideoIOComponent.swift:96] fps > (fps: 30.0, duration: __C.CMTime(value: 100, timescale: 3000, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0))
2021-29-01 13:42:09.384 [Debug] [com.haishinkit.HaishinKit] [RTMPConnection.swift:462] didSetReadyState(_:) > uninitialized
2021-29-01 13:42:09.679 [Debug] [com.haishinkit.HaishinKit] [RTMPConnection.swift:462] didSetReadyState(_:) > versionSent
2021-29-01 13:42:09.686 [Debug] [com.haishinkit.HaishinKit] [RTMPConnection.swift:462] didSetReadyState(_:) > ackSent
2021-29-01 13:42:09.687 [Debug] [com.haishinkit.HaishinKit] [RTMPConnection.swift:462] didSetReadyState(_:) > handshakeDone
2021-29-01 13:42:09.691 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: zero,streamId: 3,message: Optional(RTMPCommandMessage{type: amf0Command,length: 265,streamId: 0,timestamp: 0,payload: 253 bytes,objectEncoding: amf0,commandName: connect,transactionId: 1,commandObject: Optional(["flashVer": Optional("FMLE/3.0 (compatible; FMSc/1.0)"), "tcUrl": Optional("rtmp://10.0.0.95/live"), "capabilities": Optional(239), "app": Optional("live"), "fpad": Optional(false), "audioCodecs": Optional(1024), "videoCodecs": Optional(128), "videoFunction": Optional(1), "pageUrl": nil, "objectEncoding": Optional(0), "swfUrl": nil]),arguments: [],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:42:09.702 [Trace] [com.haishinkit.HaishinKit] [RTMPConnection.swift:520] listen(_:) > RTMPChunk{size: 128,type: zero,streamId: 2,message: Optional(RTMPWindowAcknowledgementSizeMessage{type: windowAck,length: 4,streamId: 0,timestamp: 0,payload: 4 bytes,size: 5000000}),fragmented: false,_data: 12 bytes}
2021-29-01 13:42:09.704 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: zero,streamId: 2,message: Optional(RTMPWindowAcknowledgementSizeMessage{type: windowAck,length: 16,streamId: 0,timestamp: 0,payload: 4 bytes,size: 5000000}),fragmented: false,_data: 12 bytes}
2021-29-01 13:42:09.705 [Trace] [com.haishinkit.HaishinKit] [RTMPConnection.swift:520] listen(_:) > RTMPChunk{size: 128,type: zero,streamId: 2,message: Optional(RTMPSetPeerBandwidthMessage{type: bandwidth,length: 5,streamId: 0,timestamp: 0,payload: 5 bytes,size: 5000000,limit: dynamic}),fragmented: false,_data: 12 bytes}
2021-29-01 13:42:09.707 [Trace] [com.haishinkit.HaishinKit] [RTMPConnection.swift:520] listen(_:) > RTMPChunk{size: 128,type: zero,streamId: 2,message: Optional(RTMPSetChunkSizeMessage{type: chunkSize,length: 4,streamId: 0,timestamp: 0,payload: 4 bytes,size: 60000}),fragmented: false,_data: 12 bytes}
2021-29-01 13:42:09.708 [Trace] [com.haishinkit.HaishinKit] [RTMPConnection.swift:520] listen(_:) > RTMPChunk{size: 60000,type: zero,streamId: 3,message: Optional(RTMPCommandMessage{type: amf0Command,length: 190,streamId: 0,timestamp: 0,payload: 190 bytes,objectEncoding: amf0,commandName: _result,transactionId: 1,commandObject: Optional(["capabilities": Optional(31.0), "fmsVer": Optional("FMS/3,0,1,123")]),arguments: [Optional(["level": Optional("status"), "code": Optional("NetConnection.Connect.Success"), "objectEncoding": Optional(0.0), "description": Optional("Connection succeeded.")])],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:42:09.709 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: zero,streamId: 2,message: Optional(RTMPSetChunkSizeMessage{type: chunkSize,length: 16,streamId: 0,timestamp: 0,payload: 4 bytes,size: 8192}),fragmented: false,_data: 12 bytes}
2021-29-01 13:42:09.711 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: zero,streamId: 3,message: Optional(RTMPCommandMessage{type: amf0Command,length: 37,streamId: 0,timestamp: 0,payload: 25 bytes,objectEncoding: amf0,commandName: createStream,transactionId: 2,commandObject: nil,arguments: [],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:42:09.712 [Info] [com.haishinkit.Exsample.iOS] [LiveViewController.swift:159] rtmpStatusHandler(_:) > NetConnection.Connect.Success
2021-29-01 13:42:09.721 [Trace] [com.haishinkit.HaishinKit] [RTMPConnection.swift:520] listen(_:) > RTMPChunk{size: 60000,type: zero,streamId: 3,message: Optional(RTMPCommandMessage{type: amf0Command,length: 29,streamId: 0,timestamp: 0,payload: 29 bytes,objectEncoding: amf0,commandName: _result,transactionId: 2,commandObject: Optional([:]),arguments: [Optional(1.0)],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:42:09.721 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: zero,streamId: 3,message: Optional(RTMPCommandMessage{type: amf0Command,length: 46,streamId: 0,timestamp: 0,payload: 34 bytes,objectEncoding: amf0,commandName: FCPublish,transactionId: 3,commandObject: nil,arguments: [Optional("Bk0rQdZxO")],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:42:09.722 [Trace] [com.haishinkit.HaishinKit] [RTMPSocket.swift:48] doOutput(chunk:locked:) > RTMPChunk{size: 0,type: zero,streamId: 4,message: Optional(RTMPCommandMessage{type: amf0Command,length: 51,streamId: 1,timestamp: 0,payload: 39 bytes,objectEncoding: amf0,commandName: publish,transactionId: 0,commandObject: nil,arguments: [Optional("Bk0rQdZxO"), Optional("live")],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:42:09.734 [Trace] [com.haishinkit.HaishinKit] [RTMPConnection.swift:520] listen(_:) > RTMPChunk{size: 60000,type: zero,streamId: 5,message: Optional(RTMPCommandMessage{type: amf0Command,length: 115,streamId: 1,timestamp: 0,payload: 115 bytes,objectEncoding: amf0,commandName: onStatus,transactionId: 0,commandObject: Optional([:]),arguments: [Optional(["code": Optional("NetStream.Publish.BadName"), "description": Optional("Stream already publishing"), "level": Optional("error")])],serializer: AMF0Serializer{data: 0 bytes,position: 0,reference: HaishinKit.AMFReference}}),fragmented: false,_data: 12 bytes}
2021-29-01 13:42:09.735 [Info] [com.haishinkit.Exsample.iOS] [LiveViewController.swift:159] rtmpStatusHandler(_:) > NetStream.Publish.BadName

Closing comment (2021-02-04T13:47:05Z): Close as duplicate #821.