Skip to content

Commit

Permalink
fix(lib): call onDisconnect when user call stopStream
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Aug 5, 2022
1 parent 921afc8 commit 9708f21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Changelog
All changes to this project will be documented in this file.

## [1.0.0] - 2022-08-02
## [1.0.0] - 2022-08-15
- Allows nil initialVideoConfig and initialAudioConfig
- Fix landscape orientation
- Return onDisconnect when user call `stopStreaming`

## [0.2.1] - 2022-04-22
- Stop streaming on didEnterBackgroundNotification
Expand Down
16 changes: 7 additions & 9 deletions Sources/ApiVideoLiveStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,13 @@ public class ApiVideoLiveStream {
/// Stop your livestream
/// - Returns: Void
public func stopStreaming() {
let isConnected = rtmpConnection.connected
rtmpConnection.close()
rtmpConnection.removeEventListener(.rtmpStatus, selector: #selector(rtmpStatusHandler), observer: self)
rtmpConnection.removeEventListener(.ioError, selector: #selector(rtmpErrorHandler), observer: self)
if (isConnected) {
onDisconnect?()
}
}

@objc private func rtmpStatusHandler(_ notification: Notification) {
Expand All @@ -207,18 +211,12 @@ public class ApiVideoLiveStream {
}
switch code {
case RTMPConnection.Code.connectSuccess.rawValue:
if onConnectionSuccess != nil {
onConnectionSuccess!()
}
onConnectionSuccess?()
rtmpStream.publish(streamKey)
case RTMPConnection.Code.connectFailed.rawValue:
if onConnectionFailed != nil {
onConnectionFailed!(code)
}
onConnectionFailed?(code)
case RTMPConnection.Code.connectClosed.rawValue:
if onDisconnect != nil {
onDisconnect!()
}
onDisconnect?()
default:
break
}
Expand Down

0 comments on commit 9708f21

Please sign in to comment.