Add object detection, tracking, mobile notifications, and search to any security camera.
can stream without hardcoded link now
roryclearebc225ebca50
diff --git a/clearcam/DeviceStreamViewController.m b/clearcam/DeviceStreamViewController.mindex fb2e16d..a447155 100644--- a/clearcam/DeviceStreamViewController.m+++ b/clearcam/DeviceStreamViewController.m@@ -10,6 +10,7 @@@property (nonatomic, strong) NSTimer *downloadTimer;@property (nonatomic, strong) NSData *lastSegmentData;@property (nonatomic, assign) NSUInteger segmentIndex;+@property (nonatomic, strong) NSString *downloadLink;@end@implementation DeviceStreamViewController@@ -27,9 +28,61 @@[self.view.layer addSublayer:self.playerLayer];[self.player play];- [self downloadAndQueueSegment];- [self startDownloadTimer];- NSLog(@"device streaming from = %@",self.deviceName);+ [self fetchDownloadLinkAndStartStreaming];++ NSLog(@"device streaming from = %@", self.deviceName);+}++- (void)fetchDownloadLinkAndStartStreaming {+ NSString *deviceName = self.deviceName;+ NSString *sessionToken = [[StoreManager sharedInstance] retrieveSessionTokenFromKeychain];++ if (!deviceName || !sessionToken) {+ NSLog(@"❌ Missing device name or session token");+ return;+ }++ NSString *encodedDeviceName = [deviceName stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];+ NSString *encodedSessionToken = [sessionToken stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];++ NSURLComponents *components = [NSURLComponents componentsWithString:@"https://rors.ai/get_stream_download_link"];+ components.queryItems = @[+ [NSURLQueryItem queryItemWithName:@"name" value:encodedDeviceName],+ [NSURLQueryItem queryItemWithName:@"session_token" value:encodedSessionToken]+ ];++ NSURL *url = components.URL;++ NSURLSessionDataTask *linkTask = [[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {+ if (error) {+ NSLog(@"❌ Error fetching stream link: %@", error.localizedDescription);+ return;+ }+++ NSError *jsonError;+ NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];+ if (jsonError) {+ NSLog(@"⚠️ JSON Parsing Error: %@", jsonError.localizedDescription);+ return;+ }++ NSString *downloadLink = json[@"download_link"];+ if (![downloadLink isKindOfClass:[NSString class]] || downloadLink.length == 0) {+ NSLog(@"🚫 Invalid downloadLink link");+ return;+ } else {+ self.downloadLink = downloadLink;+ }++ NSLog(@"✅ Got download link: %@", self.downloadLink);++ dispatch_async(dispatch_get_main_queue(), ^{+ [self downloadAndQueueSegment];+ [self startDownloadTimer];+ });+ }];+ [linkTask resume];}- (void)startDownloadTimer {@@ -41,7 +94,7 @@}- (void)downloadAndQueueSegment {- NSString *urlString = @"";+ NSString *urlString = self.downloadLink;NSURL *remoteURL = [NSURL URLWithString:urlString];NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:remoteURLdiff --git a/clearcam/SceneState.m b/clearcam/SceneState.mindex 3f1c405..c6eda2f 100644--- a/clearcam/SceneState.m+++ b/clearcam/SceneState.m@@ -151,6 +151,7 @@- (void)sendnotification {if ([[NSUserDefaults standardUserDefaults] boolForKey:@"send_notif_enabled"] || !([[NSUserDefaults standardUserDefaults] boolForKey:@"isSubscribed"] || [[NSUserDefaults standardUserDefaults] boolForKey:@"use_own_server_enabled"])){ //todo add back other stuffNSDate *now = [NSDate date];+ [FileServer sharedInstance].last_req_time = [NSDate now]; //todo, this keep segment length 3 for a minNSDateComponents *components = [[NSCalendar currentCalendar] components:(NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitWeekday) fromDate:now];NSInteger currentTime = components.hour * 60 + components.minute;NSString *currentDay = @[@"Sun", @"Mon", @"Tue", @"Wed", @"Thu", @"Fri", @"Sat"][components.weekday - 1];@@ -164,7 +165,7 @@if (currentTime >= startTime && currentTime <= endTime) {[[notification sharedInstance] sendNotification];- if([FileServer sharedInstance].segment_length > 2) [FileServer sharedInstance].segment_length = 2;+ if([FileServer sharedInstance].segment_length > 1) [FileServer sharedInstance].segment_length = 3;NSTimeInterval start = [[NSDate dateWithTimeIntervalSinceNow:-7.5] timeIntervalSince1970];NSTimeInterval end = [[NSDate dateWithTimeIntervalSinceNow:7.5] timeIntervalSince1970];id context = [FileServer sharedInstance].context;diff --git a/clearcam/ViewController.m b/clearcam/ViewController.mindex 0b2f07d..acd891c 100644--- a/clearcam/ViewController.m+++ b/clearcam/ViewController.m@@ -957,11 +957,7 @@ NSMutableDictionary *classColorMap;// Save the context again after modificationsNSError *saveError = nil;- if ([self.backgroundContext save:&saveError]) {- NSLog(@"✅ Saved segment to Core Data");- } else {- NSLog(@"❌ Failed to save segment to Core Data: %@", saveError);- }+ [self.backgroundContext save:&saveError];}];dispatch_async(dispatch_get_main_queue(), ^{@@ -1253,16 +1249,13 @@ NSMutableDictionary *classColorMap;}NSTimeInterval elapsedTime = CMTimeGetSeconds(self.currentTime);- if (!self.isStreaming && [FileServer sharedInstance].segment_length < 60 && [[NSDate now] timeIntervalSinceDate:self.fileServer.last_req_time] > 60) {+ if (!self.isStreaming && [FileServer sharedInstance].segment_length < 60 && [[NSDate now] timeIntervalSinceDate:self.fileServer.last_req_time] > 60) { //todo, fix hack in SceneState[FileServer sharedInstance].segment_length = 60;}if ([[NSDate date] timeIntervalSince1970] - self.last_check_time > 10.0) {- NSLog(@"Making request at %.2f %.2f seconds", [[NSDate date] timeIntervalSince1970],self.last_check_time);self.last_check_time = [[NSDate date] timeIntervalSince1970];NSString *deviceName = [[NSUserDefaults standardUserDefaults] stringForKey:@"device_name"];NSString *sessionToken = [[StoreManager sharedInstance] retrieveSessionTokenFromKeychain];-- NSLog(@"session token = %@", sessionToken);NSString *encodedDeviceName = [deviceName stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];NSString *encodedSessionToken = [sessionToken stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];@@ -1273,7 +1266,6 @@ NSMutableDictionary *classColorMap;];NSURL *url = components.URL;- NSLog(@"Final URL: %@", url);NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:urlcompletionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {