added removeServerConnectionConfig method

This commit is contained in:
Rasmus Krämer 2022-04-15 13:01:58 +02:00
parent 363bfd206c
commit 03c3f37e1e
No known key found for this signature in database
GPG key ID: EC9E510611BFDAA2
5 changed files with 35 additions and 12 deletions

View file

@ -10,6 +10,8 @@
CAP_PLUGIN(AbsDatabase, "AbsDatabase", CAP_PLUGIN(AbsDatabase, "AbsDatabase",
CAP_PLUGIN_METHOD(setCurrentServerConnectionConfig, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(setCurrentServerConnectionConfig, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(removeServerConnectionConfig, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(logout, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(logout, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getDeviceData, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(getDeviceData, CAPPluginReturnPromise);

View file

@ -51,6 +51,12 @@ public class AbsDatabase: CAPPlugin {
Store.serverConfig = config Store.serverConfig = config
call.resolve(convertServerConnectionConfigToJSON(config: config)) call.resolve(convertServerConnectionConfigToJSON(config: config))
} }
@objc func removeServerConnectionConfig(_ call: CAPPluginCall) {
let id = call.getString("serverConnectionConfigId", "")
Database.deleteServerConnectionConfig(id: id)
call.resolve()
}
@objc func logout(_ call: CAPPluginCall) { @objc func logout(_ call: CAPPluginCall) {
Store.serverConfig = nil Store.serverConfig = nil
call.resolve() call.resolve()

View file

@ -57,7 +57,6 @@ class AudioPlayer: NSObject {
playerItem.addObserver(self, forKeyPath: #keyPath(AVPlayerItem.status), options: .new, context: &playerItemContext) playerItem.addObserver(self, forKeyPath: #keyPath(AVPlayerItem.status), options: .new, context: &playerItemContext)
self.audioPlayer.replaceCurrentItem(with: playerItem) self.audioPlayer.replaceCurrentItem(with: playerItem)
seek(playbackSession.currentTime)
NSLog("Audioplayer ready") NSLog("Audioplayer ready")
} }
@ -259,6 +258,8 @@ class AudioPlayer: NSObject {
self.playWhenReady = false self.playWhenReady = false
self.play() self.play()
} }
seek(playbackSession.currentTime)
} }
} }
} else if context == &playerContext { } else if context == &playerContext {

View file

@ -12,7 +12,7 @@ class PlayerHandler {
private static var session: PlaybackSession? private static var session: PlaybackSession?
private static var timer: Timer? private static var timer: Timer?
private static var listningTimePassedSinceLastSync = 0.0 private static var listeningTimePassedSinceLastSync = 0.0
public static func startPlayback(session: PlaybackSession, playWhenReady: Bool) { public static func startPlayback(session: PlaybackSession, playWhenReady: Bool) {
if player != nil { if player != nil {
@ -26,9 +26,9 @@ class PlayerHandler {
player = AudioPlayer(playbackSession: session, playWhenReady: playWhenReady) player = AudioPlayer(playbackSession: session, playWhenReady: playWhenReady)
// DispatchQueue.main.sync { // DispatchQueue.main.sync {
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
self.tick() self.tick()
} }
// } // }
} }
public static func stopPlayback() { public static func stopPlayback() {
@ -101,10 +101,10 @@ class PlayerHandler {
private static func tick() { private static func tick() {
if !paused() { if !paused() {
listningTimePassedSinceLastSync += 1 listeningTimePassedSinceLastSync += 1
} }
if listningTimePassedSinceLastSync > 3 { if listeningTimePassedSinceLastSync > 3 {
syncProgress() syncProgress()
} }
} }
@ -113,10 +113,10 @@ class PlayerHandler {
return return
} }
let report = PlaybackReport(currentTime: player!.getCurrentTime(), duration: player!.getDuration(), timeListened: listningTimePassedSinceLastSync) let report = PlaybackReport(currentTime: player!.getCurrentTime(), duration: player!.getDuration(), timeListened: listeningTimePassedSinceLastSync)
session!.currentTime = player!.getCurrentTime() session!.currentTime = player!.getCurrentTime()
listningTimePassedSinceLastSync = 0 listeningTimePassedSinceLastSync = 0
// TODO: check if online // TODO: check if online
NSLog("sending playback report") NSLog("sending playback report")

View file

@ -11,9 +11,7 @@ import RealmSwift
class Database { class Database {
// All DB releated actions must be executed on "realm-queue" // All DB releated actions must be executed on "realm-queue"
public static let realmQueue = DispatchQueue(label: "realm-queue") public static let realmQueue = DispatchQueue(label: "realm-queue")
private static var instance: Realm = { private static var instance: Realm = try! Realm(queue: realmQueue)
try! Realm(queue: realmQueue)
}()
public static func setServerConnectionConfig(config: ServerConnectionConfig) { public static func setServerConnectionConfig(config: ServerConnectionConfig) {
var refrence: ThreadSafeReference<ServerConnectionConfig>? var refrence: ThreadSafeReference<ServerConnectionConfig>?
@ -57,6 +55,22 @@ class Database {
setLastActiveConfigIndex(index: config.index) setLastActiveConfigIndex(index: config.index)
} }
} }
public static func deleteServerConnectionConfig(id: String) {
realmQueue.sync {
let config = instance.object(ofType: ServerConnectionConfig.self, forPrimaryKey: id)
do {
try instance.write {
if config != nil {
instance.delete(config!)
}
}
} catch(let exception) {
NSLog("failed to delete server config")
debugPrint(exception)
}
}
}
public static func getServerConnectionConfigs() -> [ServerConnectionConfig] { public static func getServerConnectionConfigs() -> [ServerConnectionConfig] {
var refrences: [ThreadSafeReference<ServerConnectionConfig>] = [] var refrences: [ThreadSafeReference<ServerConnectionConfig>] = []