Skip to content

Commit

Permalink
Merge pull request #2 from AgoraIO/doc-updates
Browse files Browse the repository at this point in the history
Function heading updates
  • Loading branch information
maxxfrazer authored Nov 13, 2023
2 parents 628540a + fd25224 commit cb435ba
Show file tree
Hide file tree
Showing 15 changed files with 401 additions and 109 deletions.
21 changes: 21 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -eo pipefail

# Get the path of the JSON file
JSON_FILE_PATH="./signaling-manager/config.json"

# Read the JSON file contents
JSON_CONTENTS=$(git show :${JSON_FILE_PATH})

# Extract the value of the "appId" key from the JSON
APP_ID_VALUE=$(echo "${JSON_CONTENTS}" | jq -r '.appId')

# Check if the "appId" value is not zero
if [ -n "${APP_ID_VALUE}" ]; then
echo "Error: The 'appId' value in the JSON file must be an empty string."
exit 1
fi

# Exit with a success status
exit 0
18 changes: 18 additions & 0 deletions .github/workflows/swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: swiftlint

on:
push:
branches:
- "main"
pull_request:
branches:
- "*"

jobs:
swiftlint:
runs-on: macos-latest
steps:
- name: Checkout 🛎
uses: actions/checkout@v3
- name: Swift Lint 🧹
run: swiftlint --strict
18 changes: 9 additions & 9 deletions Example-App/Example-App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
F32AF8C52A8BB97B00A27ED1 /* MessageInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F32AF8C22A8BB97B00A27ED1 /* MessageInputView.swift */; };
F32AF8C62A8BB97B00A27ED1 /* MessagesListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F32AF8C32A8BB97B00A27ED1 /* MessagesListView.swift */; };
F32AF8C92A8BB99D00A27ED1 /* View+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F32AF8C82A8BB99D00A27ED1 /* View+Extensions.swift */; };
F32AF8CC2A8BB9C400A27ED1 /* AgoraRtmKit-Swift in Frameworks */ = {isa = PBXBuildFile; productRef = F32AF8CB2A8BB9C400A27ED1 /* AgoraRtmKit-Swift */; };
F32AF8D02A8BBA1000A27ED1 /* GettingStartedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F32AF8CF2A8BBA1000A27ED1 /* GettingStartedView.swift */; };
F32AF8D32A8BBAB800A27ED1 /* ChannelInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F32AF8D22A8BBAB800A27ED1 /* ChannelInputView.swift */; };
F32AF8D62A8BC19400A27ED1 /* TokenAuthenticationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F32AF8D52A8BC19400A27ED1 /* TokenAuthenticationView.swift */; };
Expand All @@ -26,6 +25,7 @@
F360D0CB2AEBE81F00B0586C /* CloudProxyInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F360D0CA2AEBE81F00B0586C /* CloudProxyInputView.swift */; };
F360D0CD2AEBF23800B0586C /* DataEncryptionInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F360D0CC2AEBF23800B0586C /* DataEncryptionInputView.swift */; };
F36313292AC4728B0000F29E /* RemoteUsersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F36313282AC4728B0000F29E /* RemoteUsersView.swift */; };
F381E9C02AFA7E5600E8D0D5 /* AgoraRtmKit-Swift in Frameworks */ = {isa = PBXBuildFile; productRef = F381E9BF2AFA7E5600E8D0D5 /* AgoraRtmKit-Swift */; };
F3BB3B182AE92660009E00C6 /* CloudProxyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BB3B172AE92660009E00C6 /* CloudProxyView.swift */; };
F3BB3B1A2AE92669009E00C6 /* DataEncryptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BB3B192AE92669009E00C6 /* DataEncryptionView.swift */; };
F3BB3B1C2AE92676009E00C6 /* PresenceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BB3B1B2AE92676009E00C6 /* PresenceView.swift */; };
Expand Down Expand Up @@ -71,7 +71,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
F32AF8CC2A8BB9C400A27ED1 /* AgoraRtmKit-Swift in Frameworks */,
F381E9C02AFA7E5600E8D0D5 /* AgoraRtmKit-Swift in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -264,7 +264,7 @@
);
name = "Example-App";
packageProductDependencies = (
F32AF8CB2A8BB9C400A27ED1 /* AgoraRtmKit-Swift */,
F381E9BF2AFA7E5600E8D0D5 /* AgoraRtmKit-Swift */,
);
productName = "Example-App";
productReference = F32AF8AB2A8BB86200A27ED1 /* Example-App.app */;
Expand Down Expand Up @@ -295,7 +295,7 @@
);
mainGroup = F32AF8A22A8BB86200A27ED1;
packageReferences = (
F32AF8CA2A8BB9C400A27ED1 /* XCRemoteSwiftPackageReference "AgoraRtm" */,
F381E9BE2AFA7E5600E8D0D5 /* XCRemoteSwiftPackageReference "AgoraRtm_Apple" */,
);
productRefGroup = F32AF8AC2A8BB86200A27ED1 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -565,20 +565,20 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
F32AF8CA2A8BB9C400A27ED1 /* XCRemoteSwiftPackageReference "AgoraRtm" */ = {
F381E9BE2AFA7E5600E8D0D5 /* XCRemoteSwiftPackageReference "AgoraRtm_Apple" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/AgoraIO-Community/AgoraRtm.git";
repositoryURL = "https://github.com/AgoraIO/AgoraRtm_Apple.git";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = "2.1.6-beta";
minimumVersion = "2.1.7-beta.1";
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
F32AF8CB2A8BB9C400A27ED1 /* AgoraRtmKit-Swift */ = {
F381E9BF2AFA7E5600E8D0D5 /* AgoraRtmKit-Swift */ = {
isa = XCSwiftPackageProductDependency;
package = F32AF8CA2A8BB9C400A27ED1 /* XCRemoteSwiftPackageReference "AgoraRtm" */;
package = F381E9BE2AFA7E5600E8D0D5 /* XCRemoteSwiftPackageReference "AgoraRtm_Apple" */;
productName = "AgoraRtmKit-Swift";
};
/* End XCSwiftPackageProductDependency section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ struct CloudProxyInputView<Content: HasCloudProxyInput>: View {
}.onAppear {
channelId = DocsAppConfig.shared.channel
userId = DocsAppConfig.shared.uid
proxyUrl = DocsAppConfig.shared.proxyUrl
proxyPort = DocsAppConfig.shared.proxyPort
proxyAccount = DocsAppConfig.shared.proxyAccount
proxyPassword = DocsAppConfig.shared.proxyPassword
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ struct DataEncryptionInputView<Content: HasDataEncryptionInput>: View {
}.onAppear {
channelId = DocsAppConfig.shared.channel
userId = DocsAppConfig.shared.uid
encryptionKey = DocsAppConfig.shared.cipherKey
encryptionSalt = DocsAppConfig.shared.salt
}
}
}
Expand Down
34 changes: 32 additions & 2 deletions authentication-workflow/TokenAuthenticationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
//

import SwiftUI
import AgoraRtm

extension SignalingManager {
struct TokenResponse: Codable {
var token: String
}

var tokenUrl: String {
DocsAppConfig.shared.tokenUrl
}

func fetchToken(from urlString: String, username: String, channelName: String? = nil) async throws -> String {
guard let url = URL(string: urlString) else {
guard let url = URL(string: "\(urlString)/getToken") else {
throw URLError(.badURL)
}

Expand All @@ -39,6 +44,24 @@ extension SignalingManager {

return tokenResponse.token
}

func loginMessageChannel(tokenUrl: String, username: String) async throws {
let token = try await self.fetchToken(
from: tokenUrl, username: username
)

try await self.signalingEngine.login(byToken: token)
}

func loginStreamChannel(tokenUrl: String, username: String, streamChannel: String) async throws {
let token = try await self.fetchToken(
from: tokenUrl, username: username, channelName: streamChannel
)

let channel = try self.signalingEngine.createStreamChannel(streamChannel)
let joinOption = RtmJoinChannelOption(token: token, features: [.presence])
try await channel?.join(with: joinOption)
}
}

extension GetStartedSignalingManager {
Expand All @@ -47,6 +70,13 @@ extension GetStartedSignalingManager {

await self.loginAndSub(to: channel, with: token)
}

public func rtmKit(_ rtmClient: RtmClientKit, tokenPrivilegeWillExpire channel: String?) {
Task {
let token = try await self.fetchToken(from: self.tokenUrl, username: self.userId)
try await signalingEngine.renewToken(token)
}
}
}

// MARK: - UI
Expand Down Expand Up @@ -96,7 +126,7 @@ struct TokenAuthenticationView: View {
}

func publish(message: String) async {
await self.signalingManager.publish(
await self.signalingManager.publishAndRecord(
message: message, to: self.channelId
)
}
Expand Down
12 changes: 6 additions & 6 deletions cloud-proxy/CloudProxyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public class CloudProxyManager: GetStartedSignalingManager {
guard reason == .settingProxyServer else { return }

switch state {
case .disconnected: break
case .connecting: break
case .connected: break
case .reconnecting: break
case .failed: break
case .disconnected: print("proxy disconnected")
case .connecting: print("proxy connecting")
case .connected: print("proxy connected")
case .reconnecting: print("proxy reconnecting")
case .failed: print("proxy failed")
default: break
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ struct CloudProxyView: View {
// MARK: - Helpers and Setup

func publish(message: String) async {
await self.signalingManager.publish(
await self.signalingManager.publishAndRecord(
message: message, to: self.channelId
)
}
Expand Down
5 changes: 3 additions & 2 deletions data-encryption/DataEncryptionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class EncryptionSignalingManager: GetStartedSignalingManager {
let config = RtmClientConfig(appId: self.appId, userId: self.userId)

config.encryptionConfig = .aes128GCM(
key: encryptionKey, salt: encryptionSalt
key: encryptionKey,
salt: RtmClientConfig.encryptSaltString(salt: encryptionSalt)
)

guard let eng = try? RtmClientKit(
Expand Down Expand Up @@ -57,7 +58,7 @@ struct DataEncryptionView: View {
// MARK: - Helpers and Setup

func publish(message: String) async {
await self.signalingManager.publish(
await self.signalingManager.publishAndRecord(
message: message, to: self.channelId
)
}
Expand Down
15 changes: 4 additions & 11 deletions get-started-sdk/GettingStartedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,9 @@ public class GetStartedSignalingManager: SignalingManager, RtmClientDelegate {
/// - Parameters:
/// - message: String to be sent to the channel. UTF-8 suppported 👋.
/// - channel: Channel name to publish the message to.
public func publish(message: String, to channel: String) async {
do {
try await self.signalingEngine.publish(
message: message,
to: channel
)
} catch let err as RtmErrorInfo {
return await self.updateLabel(to: "Could not publish message: \(err.reason)")
} catch {
await self.updateLabel(to: "Unknown error: \(error.localizedDescription)")
public func publishAndRecord(message: String, to channel: String) async {
guard (try? await super.publish(message: message, to: channel)) != nil else {
return
}

DispatchQueue.main.async {
Expand Down Expand Up @@ -134,7 +127,7 @@ struct GettingStartedView: View {
// MARK: - Helpers and Setup

func publish(message: String) async {
await self.signalingManager.publish(
await self.signalingManager.publishAndRecord(
message: message, to: self.channelId
)
}
Expand Down
5 changes: 0 additions & 5 deletions manage-connection-states/ConnectionStatesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ public class ConnectionStatesManager: SignalingManager, RtmClientDelegate {

@Published var loggedIn: Bool = false

@discardableResult
func logout() async throws -> RtmCommonResponse {
try await self.signalingEngine.logout()
}

func subscribe(_ channel: String) async throws -> RtmCommonResponse {
try await self.signalingEngine.subscribe(toChannel: channel)
}
Expand Down
Loading

0 comments on commit cb435ba

Please sign in to comment.