Skip to content

Commit

Permalink
Merge pull request #350 from salemove/dev
Browse files Browse the repository at this point in the history
Glia Widgets SDK 0.9.2
  • Loading branch information
dukhovnyi authored Jul 28, 2022
2 parents d5eab7a + 9047ed2 commit b43bcac
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 21 deletions.
1 change: 1 addition & 0 deletions GliaWidgets/Component/Bubble/BubbleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class BubbleView: UIView {
accessibilityTraits = [.button]
accessibilityLabel = style.accessibility.label
accessibilityHint = style.accessibility.hint
accessibilityIdentifier = "bubble_view"

update(kind)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ConnectStatusView: UIView {

firstLabel.accessibilityHint = style.accessibility.firstTextHint
secondLabel.accessibilityHint = style.accessibility.secondTextHint
secondLabel.accessibilityIdentifier = "call_duration_label"
setFontScalingEnabled(
style.accessibility.isFontScalingEnabled,
for: firstLabel
Expand Down
5 changes: 3 additions & 2 deletions GliaWidgets/Component/Header/Header.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ class Header: UIView {
rightItemContainer.spacing = 8
rightItemContainer.alignment = .center

closeButton.accessibilityIdentifier = "chat_close_button"
backButton.accessibilityIdentifier = "header_back_button"
closeButton.accessibilityIdentifier = "header_close_button"
closeButton.accessibilityLabel = style.closeButton.accessibility.label
endButton.accessibilityIdentifier = "chat_end_button"
endButton.accessibilityIdentifier = "header_end_button"
endButton.accessibilityLabel = style.endButton.accessibility.label
setFontScalingEnabled(
style.accessibility.isFontScalingEnabled,
Expand Down
2 changes: 1 addition & 1 deletion GliaWidgets/CoreSDKClient/CoreSDKClient.Interface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ extension CoreSdkClient {
typealias MediaType = SalemoveSDK.MediaType
typealias MediaUgradeOfferBlock = SalemoveSDK.MediaUgradeOfferBlock
typealias MediaUpgradeOffer = SalemoveSDK.MediaUpgradeOffer
typealias MediaUpdateBlock = SalemoveSDK.MediaUpdateBlock
typealias Message = SalemoveSDK.Message
typealias MessageSender = SalemoveSDK.MessageSender
typealias MessageBlock = SalemoveSDK.MessageBlock
Expand Down Expand Up @@ -177,5 +178,4 @@ extension CoreSdkClient {
typealias Site = SalemoveSDK.Site
typealias Survey = SalemoveSDK.Survey
typealias SurveyAnswerContainer = SalemoveSDK.Survey.Answer.ValueContainer
typealias MediaUpdateBlock = SalemoveSDK.MediaUpdateBlock
}
1 change: 1 addition & 0 deletions GliaWidgets/GCD.Live.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Dispatch
import Foundation

extension GCD {
static let live = Self(
Expand Down
13 changes: 7 additions & 6 deletions GliaWidgets/Interactor/Interactor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum InteractorEvent {
case messagesUpdated([CoreSdkClient.Message])
case typingStatusUpdated(CoreSdkClient.OperatorTypingStatus)
case upgradeOffer(CoreSdkClient.MediaUpgradeOffer, answer: CoreSdkClient.AnswerWithSuccessBlock)
case updateOffer(CoreSdkClient.MediaUpgradeOffer)
case audioStreamAdded(CoreSdkClient.AudioStreamable)
case audioStreamError(CoreSdkClient.SalemoveError)
case videoStreamAdded(CoreSdkClient.VideoStreamable)
Expand Down Expand Up @@ -244,12 +245,6 @@ extension Interactor {
}

extension Interactor: CoreSdkClient.Interactable {
var onEngagementTransferMediaUpdate: CoreSdkClient.MediaUpdateBlock {
{ _ in

}
}

var onScreenSharingOffer: CoreSdkClient.ScreenshareOfferBlock {
return { [weak self] answer in
self?.notify(.screenShareOffer(answer: answer))
Expand All @@ -262,6 +257,12 @@ extension Interactor: CoreSdkClient.Interactable {
}
}

var onEngagementTransferMediaUpdate: CoreSdkClient.MediaUpdateBlock {
return { [weak self] offer in
self?.notify(.updateOffer(offer))
}
}

var onEngagementRequest: CoreSdkClient.RequestOfferBlock {
return { [weak self] answer in
answer(self?.visitorContext, true) { _, _ in }
Expand Down
2 changes: 2 additions & 0 deletions GliaWidgets/Lib/Upload/FileUpload.Environment.Interface.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

extension FileUpload {
struct Environment {
var uploadFileToEngagement: CoreSdkClient.UploadFileToEngagement
Expand Down
3 changes: 3 additions & 0 deletions GliaWidgets/ViewModel/Call/CallViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ class CallViewModel: EngagementViewModel, ViewModel {
handleVideoStreamError(error)
case .upgradeOffer(let offer, answer: let answer):
offerMediaUpgrade(offer, answer: answer)
case .updateOffer(let offer):
call.upgrade(to: offer)
case .engagementTransferring:
onEngagementTransferring()
default:
Expand All @@ -266,6 +268,7 @@ class CallViewModel: EngagementViewModel, ViewModel {

extension CallViewModel {
private func onEngagementTransferring() {
endScreenSharing()
call.transfer()
durationCounter.stop()
action?(.transferring)
Expand Down
57 changes: 45 additions & 12 deletions GliaWidgetsTests/Sources/CallViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import XCTest

@testable import GliaWidgets

// swiftlint:disable type_body_length
class CallViewModelTests: XCTestCase {
var viewModel: CallViewModel!
var call: Call!

// swiftlint:disable function_body_length
func test_setCallOnHoldPausesLocalVideoAndMutesLocalAudio() throws {
var isVideoButtonEnabled: Bool = true
var isMuteButtonEnabled: Bool = true
Expand Down Expand Up @@ -36,7 +38,7 @@ class CallViewModelTests: XCTestCase {

case .mute:
isMuteButtonEnabled = isEnabled

default:
break
}
Expand All @@ -53,7 +55,7 @@ class CallViewModelTests: XCTestCase {
getIsRemoteFunc: { true },
setIsRemoteFunc: { _ in }
)

let remoteVideoStream = CoreSdkClient.MockVideoStreamable.mock(
getStreamViewFunc: { .init() },
playVideoFunc: {},
Expand All @@ -74,7 +76,7 @@ class CallViewModelTests: XCTestCase {
getIsRemoteFunc: { false },
setIsRemoteFunc: { _ in }
)

let localVideoStream = CoreSdkClient.MockVideoStreamable.mock(
getStreamViewFunc: { .init() },
playVideoFunc: {},
Expand All @@ -86,7 +88,7 @@ class CallViewModelTests: XCTestCase {
getIsRemoteFunc: { false },
setIsRemoteFunc: { _ in }
)

call.updateAudioStream(with: remoteAudioStream)
call.updateVideoStream(with: remoteVideoStream)
call.updateAudioStream(with: localAudioStream)
Expand All @@ -100,6 +102,7 @@ class CallViewModelTests: XCTestCase {
XCTAssertTrue(isLocalAudioStreamMuted)
}

// swiftlint:disable function_body_length
func test_toggleCallOnHoldRestoresPreviousLocalVideoAndAudioState() throws {
var isLocalAudioStreamMuted: Bool = false
var isLocalVideoStreamPaused: Bool = false
Expand Down Expand Up @@ -127,7 +130,7 @@ class CallViewModelTests: XCTestCase {
getIsRemoteFunc: { true },
setIsRemoteFunc: { _ in }
)

let remoteVideoStream = CoreSdkClient.MockVideoStreamable.mock(
getStreamViewFunc: { .init() },
playVideoFunc: {},
Expand All @@ -148,7 +151,7 @@ class CallViewModelTests: XCTestCase {
getIsRemoteFunc: { false },
setIsRemoteFunc: { _ in }
)

let localVideoStream = CoreSdkClient.MockVideoStreamable.mock(
getStreamViewFunc: { .init() },
playVideoFunc: {},
Expand All @@ -160,7 +163,7 @@ class CallViewModelTests: XCTestCase {
getIsRemoteFunc: { false },
setIsRemoteFunc: { _ in }
)

call.updateAudioStream(with: remoteAudioStream)
call.updateVideoStream(with: remoteVideoStream)
call.updateAudioStream(with: localAudioStream)
Expand All @@ -181,7 +184,7 @@ class CallViewModelTests: XCTestCase {
XCTAssertTrue(isLocalAudioStreamMuted)
XCTAssertTrue(isLocalVideoStreamPaused)
}

func test_engagementTransferringReleasesRemoteAndLocalVideoAndShowsConnectingState() throws {
enum Calls { case showConnecting }
var calls: [Calls] = []
Expand Down Expand Up @@ -209,10 +212,10 @@ class CallViewModelTests: XCTestCase {
switch action {
case .connecting:
calls.append(.showConnecting)

case .setRemoteVideo(let video):
XCTAssertNil(video)

case .setLocalVideo(let video):
XCTAssertNil(video)

Expand All @@ -225,7 +228,8 @@ class CallViewModelTests: XCTestCase {

XCTAssertEqual([.showConnecting], calls)
}


// swiftlint:disable function_body_length
func test_engagementTransferringReleasesStreams() throws {
var interactorEnv: Interactor.Environment = .failing
interactorEnv.gcd.mainQueue.asyncIfNeeded = { $0() }
Expand Down Expand Up @@ -294,12 +298,41 @@ class CallViewModelTests: XCTestCase {
XCTAssertFalse(call.audio.stream.value.remoteStream == nil)
XCTAssertFalse(call.video.stream.value.localStream == nil)
XCTAssertFalse(call.video.stream.value.remoteStream == nil)

interactor.notify(.engagementTransferring)

XCTAssertNil(call.video.stream.value.localStream)
XCTAssertNil(call.video.stream.value.remoteStream)
XCTAssertNil(call.audio.stream.value.localStream)
XCTAssertNil(call.audio.stream.value.remoteStream)
}

func test_interactorEventUpdatesCallMediaState() throws {
var interactorEnv: Interactor.Environment = .failing
interactorEnv.gcd.mainQueue.asyncIfNeeded = { $0() }
let interactor: Interactor = .mock(environment: interactorEnv)

let offer = try CoreSdkClient.MediaUpgradeOffer(type: .audio, direction: .oneWay)

call = .init(
.video(direction: .twoWay),
environment: .mock
)

viewModel = .init(
interactor: interactor,
alertConfiguration: .mock(),
screenShareHandler: ScreenShareHandler(),
environment: .mock,
call: call,
unreadMessages: .init(with: 0),
startWith: .engagement(mediaType: .video)
)

XCTAssertEqual(call.kind.value, .video(direction: .twoWay))

interactor.notify(.updateOffer(offer))

XCTAssertEqual(call.kind.value, .audio)
}
}

0 comments on commit b43bcac

Please sign in to comment.