From 6caf717b59e7e26847a08892b155963dd1601091 Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Thu, 3 Jul 2014 14:44:42 +0200 Subject: [PATCH] Incomplete image transfert evolution --- Classes/ChatRoomViewController.h | 2 +- Classes/ChatRoomViewController.m | 45 +++++++++++++++++++++++++-- Classes/ImageSharing.m | 2 +- Classes/LinphoneManager.h | 8 +++++ Classes/LinphoneManager.m | 40 ++++++++++++++++++++++-- Resources/wizard_linphone_create.rc | 2 +- Resources/wizard_linphone_existing.rc | 2 +- 7 files changed, 91 insertions(+), 10 deletions(-) diff --git a/Classes/ChatRoomViewController.h b/Classes/ChatRoomViewController.h index 491accaf4..44f08cc3e 100644 --- a/Classes/ChatRoomViewController.h +++ b/Classes/ChatRoomViewController.h @@ -29,7 +29,7 @@ #include "linphone/linphonecore.h" -@interface ChatRoomViewController : UIViewController { +@interface ChatRoomViewController : UIViewController { LinphoneChatRoom *chatRoom; ImageSharing *imageSharing; OrderedDictionary *imageQualities; diff --git a/Classes/ChatRoomViewController.m b/Classes/ChatRoomViewController.m index cdfc82e09..a40462b45 100644 --- a/Classes/ChatRoomViewController.m +++ b/Classes/ChatRoomViewController.m @@ -26,7 +26,12 @@ #import #import "Utils.h" -@implementation ChatRoomViewController +@implementation ChatRoomViewController { + /* Message transfer transient storage */ + /* TODO: use this for data retrieval */ + NSData* image; + size_t offset_sent; +} @synthesize tableController; @synthesize sendButton; @@ -62,6 +67,9 @@ [NSNumber numberWithFloat:0.5], NSLocalizedString(@"Average", nil), [NSNumber numberWithFloat:0.0], NSLocalizedString(@"Minimum", nil), nil]; self->composingVisible = TRUE; + + self->image = nil; + self->offset_sent = 0; } return self; } @@ -625,8 +633,26 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta - (BOOL)chatRoomStartImageUpload:(UIImage*)image url:(NSURL*)url{ if(imageSharing == nil) { - NSString *urlString = [[LinphoneManager instance] lpConfigStringForKey:@"sharing_server_preference"]; - imageSharing = [ImageSharing newImageSharingUpload:[NSURL URLWithString:urlString] image:image delegate:self userInfo:url]; + NSData* jpegData = UIImageJPEGRepresentation(image, 1.0); + LinphoneContent content = {}; + content.type = "image"; + content.subtype = "jpeg"; + content.name = ms_strdup([[NSString stringWithFormat:@"%i-%f.jpg", [image hash],[NSDate timeIntervalSinceReferenceDate]] UTF8String]); + content.data = (void*)[jpegData bytes]; + content.size = [jpegData length]; + + LinphoneChatMessage* message = linphone_chat_room_create_file_transfer_message(chatRoom, &content); + linphone_chat_message_set_user_data(message, self); + + if ( url ) { + // internal url is saved in the appdata for display and later save + [LinphoneManager setValueInMessageAppData:[url absoluteString] forKey:@"localimage" inMessage:message]; + } + + linphone_chat_room_send_message2(chatRoom, message, message_status, self); + + [tableController addChatEntry:linphone_chat_message_ref(message)]; + [tableController scrollToBottom:true]; [messageView setHidden:TRUE]; [transferView setHidden:FALSE]; return TRUE; @@ -729,6 +755,19 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta [self chooseImageQuality:image url:url]; } +#pragma mark - LinphoneChatContentTransferDelegate + +- (void)onProgressReport:(LinphoneChatMessage *)msg forContent:(const LinphoneContent *)content percent:(int)percent { + [imageTransferProgressBar setProgress:percent]; +} + +- (void)onDataRequested:(LinphoneChatMessage *)msg forContent:(const LinphoneContent *)content buffer:(char *)buffer withSize:(size_t *)size { + // TODO +} + +- (void)onDataReceived:(LinphoneChatMessage *)msg forContent:(const LinphoneContent *)content buffer:(const char *)buffer withSize:(size_t)size { + // TODO +} #pragma mark - Keyboard Event Functions diff --git a/Classes/ImageSharing.m b/Classes/ImageSharing.m index 6ab27490e..bebc306d0 100644 --- a/Classes/ImageSharing.m +++ b/Classes/ImageSharing.m @@ -92,7 +92,7 @@ - (void)uploadImageTo:(NSURL*)url image:(UIImage*)image { - [LinphoneLogger log:LinphoneLoggerLog format:@"downloading [%@]", [url absoluteString]]; + [LinphoneLogger log:LinphoneLoggerLog format:@"uploading to [%@]", [url absoluteString]]; // setting up the request object now NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 6fa0e1fd7..6546807a3 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -96,6 +96,14 @@ struct NetworkReachabilityContext { }; @end +@protocol LinphoneChatContentTransferDelegate + +-(void)onProgressReport:(LinphoneChatMessage*)msg forContent:(const LinphoneContent*)content percent:(int)percent; +-(void)onDataRequested:(LinphoneChatMessage*)msg forContent:(const LinphoneContent*)content buffer:(char*)buffer withSize:(size_t*)size; +-(void)onDataReceived:(LinphoneChatMessage*)msg forContent:(const LinphoneContent*)content buffer:(const char*)buffer withSize:(size_t)size; + +@end + typedef struct _LinphoneManagerSounds { SystemSoundID call; SystemSoundID message; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 3a5927891..9f2a092f0 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -859,7 +859,29 @@ static void linphone_iphone_message_received(LinphoneCore *lc, LinphoneChatRoom [(LinphoneManager*)linphone_core_get_user_data(lc) onMessageReceived:lc room:room message:message]; } -#pragma mark - Message composition start +#pragma mark - FileTransfer functions + +static void linphone_iphone_file_transfer_recv(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size) { + id delegate = (id)linphone_chat_message_get_user_data(message); + [LinphoneLogger log:LinphoneLoggerLog format:@"Transfer of %s, incoming data (%d bytes)", content->name, size]; + [delegate onDataReceived:message forContent:content buffer:buff withSize:size]; +} + +static void linphone_iphone_file_transfer_send(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size){ + id delegate = (id)linphone_chat_message_get_user_data(message); + [LinphoneLogger log:LinphoneLoggerLog format:@"Transfer of %s, requesting data (%d bytes)", content->name, *size]; + [delegate onDataRequested:message forContent:content buffer:buff withSize:size]; +} + +static void linphone_iphone_file_transfer_progress(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, size_t progress){ + id delegate = (id)linphone_chat_message_get_user_data(message); + [LinphoneLogger log:LinphoneLoggerLog format:@"Progress of transfer %s: %d%%", content->name, progress]; + [delegate onProgressReport:message forContent:content percent:progress]; +} + + + +#pragma mark - Message composition start - (void)onMessageComposeReceived:(LinphoneCore*)core forRoom:(LinphoneChatRoom*)room { [[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneTextComposeEvent @@ -1022,7 +1044,7 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach } -#pragma mark - +#pragma mark - VTable static LinphoneCoreVTable linphonec_vtable = { .show =NULL, @@ -1041,9 +1063,15 @@ static LinphoneCoreVTable linphonec_vtable = { .transfer_state_changed=linphone_iphone_transfer_state_changed, .is_composing_received = linphone_iphone_is_composing_received, .configuring_status = linphone_iphone_configuring_status_changed, - .global_state_changed = linphone_iphone_global_state_changed + .global_state_changed = linphone_iphone_global_state_changed, + .file_transfer_received = linphone_iphone_file_transfer_recv, + .file_transfer_send = linphone_iphone_file_transfer_send, + .file_transfer_progress_indication = linphone_iphone_file_transfer_progress + }; +#pragma mark - + //scheduling loop - (void)iterate { linphone_core_iterate(theLinphoneCore); @@ -1111,6 +1139,12 @@ static LinphoneCoreVTable linphonec_vtable = { [self setupNetworkReachabilityCallback]; + NSString *urlString = [self lpConfigStringForKey:@"sharing_server_preference"]; + if( urlString ){ + linphone_core_set_file_transfer_server(theLinphoneCore, [urlString UTF8String]); + } + + NSString* path = [LinphoneManager bundleFile:@"nowebcamCIF.jpg"]; if (path) { const char* imagePath = [path cStringUsingEncoding:[NSString defaultCStringEncoding]]; diff --git a/Resources/wizard_linphone_create.rc b/Resources/wizard_linphone_create.rc index 53c05f61c..0780368e9 100644 --- a/Resources/wizard_linphone_create.rc +++ b/Resources/wizard_linphone_create.rc @@ -18,7 +18,7 @@
1 - https://www.linphone.org:444/upload.php + https://www.linphone.org:444/lft.php 1 stun.linphone.org 1 diff --git a/Resources/wizard_linphone_existing.rc b/Resources/wizard_linphone_existing.rc index 74b948d8a..6bbcf1a49 100644 --- a/Resources/wizard_linphone_existing.rc +++ b/Resources/wizard_linphone_existing.rc @@ -18,7 +18,7 @@
1 - https://www.linphone.org:444/upload.php + https://www.linphone.org:444/lft.php 1 stun.linphone.org 1