Skip to content

Commit

Permalink
feat: webrtc basic
Browse files Browse the repository at this point in the history
  • Loading branch information
niranjannitesh committed Nov 6, 2024
1 parent 7b5f955 commit ecd953d
Show file tree
Hide file tree
Showing 18 changed files with 1,898 additions and 113 deletions.
14 changes: 2 additions & 12 deletions Kino.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@
mainGroup = 6DDA078C2CDA96850093CA06;
minimizedProjectReferenceProxies = 1;
packageReferences = (
6D3565262CDB87CA00297A87 /* XCRemoteSwiftPackageReference "WebRTC" */,
);
preferredProjectObjectVersion = 77;
productRefGroup = 6DDA07962CDA96850093CA06 /* Products */;
Expand Down Expand Up @@ -471,6 +470,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Kino/Kino.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Kino/Preview Content\"";
Expand Down Expand Up @@ -513,6 +513,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Kino/Kino.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Kino/Preview Content\"";
Expand Down Expand Up @@ -674,17 +675,6 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
6D3565262CDB87CA00297A87 /* XCRemoteSwiftPackageReference "WebRTC" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/stasel/WebRTC.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 130.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */
};
rootObject = 6DDA078D2CDA96850093CA06 /* Project object */;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>Kino.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
<integer>3</integer>
</dict>
</dict>
</dict>
Expand Down
15 changes: 0 additions & 15 deletions Kino.xcworkspace/xcshareddata/swiftpm/Package.resolved

This file was deleted.

2 changes: 2 additions & 0 deletions Kino/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>LSMultipleInstancesProhibited</key>
<false/>
</dict>
</plist>
77 changes: 77 additions & 0 deletions Kino/KinoApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,85 @@
//

import SwiftUI
import VLCKit

enum KinoScreen {
case home
case player
}

@Observable
class RoomViewModel {
private let webRTCService: WebRTCService
private var lastSyncTime: TimeInterval = 0
var isInternalStateChange = false

var roomCode: String = ""
var isHost: Bool = false
var isConnected: Bool = false
var error: String?

init() {
webRTCService = WebRTCService()
}

// Create a new room
func createRoom() async {
do {
isHost = true
roomCode = try await webRTCService.createRoom()
} catch {
self.error = "Failed to create room: \(error.localizedDescription)"
}
}

// Join existing room
func joinRoom(code: String) async {
do {
isHost = false
roomCode = code
try await webRTCService.joinRoom(code: code)
} catch {
self.error = "Failed to join room: \(error.localizedDescription)"
}
}


// Handle player state changes
func handlePlayerStateChange(state: PlayerState) {
guard !isInternalStateChange else { return }
let currentTime = Date().timeIntervalSince1970
webRTCService.sendPlayerState(state)
lastSyncTime = currentTime
}

func setPlayerDelegate(_ delegate: WebRTCServiceDelegate) {
webRTCService.delegate = delegate
}
}

@Observable
class KinoViewModel {
var roomViewModel = RoomViewModel()

var currentScreen: KinoScreen = .home
var showNewRoomSheet = false
var showJoinSheet = false
var roomName = ""
var displayName = ""

var isInRoom: Bool {
!roomViewModel.roomCode.isEmpty
}

// Leave room function
func leaveRoom() {
roomViewModel.roomCode = ""
roomViewModel.isHost = false
roomViewModel.isConnected = false
currentScreen = .home
}
}

@main
struct KinoApp: App {
Expand Down
Loading

0 comments on commit ecd953d

Please sign in to comment.