Incomplete image transfert evolution

This commit is contained in:
Guillaume BIENKOWSKI 2014-07-03 14:44:42 +02:00
parent 03b8d2b357
commit 6caf717b59
7 changed files with 91 additions and 10 deletions

View file

@ -29,7 +29,7 @@
#include "linphone/linphonecore.h"
@interface ChatRoomViewController : UIViewController<HPGrowingTextViewDelegate, UICompositeViewDelegate, ImagePickerDelegate, ImageSharingDelegate, ChatRoomDelegate> {
@interface ChatRoomViewController : UIViewController<HPGrowingTextViewDelegate, UICompositeViewDelegate, ImagePickerDelegate, ImageSharingDelegate, ChatRoomDelegate, LinphoneChatContentTransferDelegate> {
LinphoneChatRoom *chatRoom;
ImageSharing *imageSharing;
OrderedDictionary *imageQualities;

View file

@ -26,7 +26,12 @@
#import <MobileCoreServices/UTCoreTypes.h>
#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

View file

@ -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];

View file

@ -96,6 +96,14 @@ struct NetworkReachabilityContext {
};
@end
@protocol LinphoneChatContentTransferDelegate <NSObject>
-(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;

View file

@ -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 <LinphoneChatContentTransferDelegate> delegate = (id<LinphoneChatContentTransferDelegate>)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 <LinphoneChatContentTransferDelegate> delegate = (id<LinphoneChatContentTransferDelegate>)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 <LinphoneChatContentTransferDelegate> delegate = (id<LinphoneChatContentTransferDelegate>)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]];

View file

@ -18,7 +18,7 @@
<section name="app">
<entry name="pushnotification_preference" overwrite="true">1</entry>
<entry name="sharing_server_preference" overwrite="true">https://www.linphone.org:444/upload.php</entry>
<entry name="sharing_server_preference" overwrite="true">https://www.linphone.org:444/lft.php</entry>
<entry name="ice_preference" overwrite="true">1</entry>
<entry name="stun_preference" overwrite="true">stun.linphone.org</entry>
<entry name="random_port_preference" overwrite="true">1</entry>

View file

@ -18,7 +18,7 @@
<section name="app">
<entry name="pushnotification_preference" overwrite="true">1</entry>
<entry name="sharing_server_preference" overwrite="true">https://www.linphone.org:444/upload.php</entry>
<entry name="sharing_server_preference" overwrite="true">https://www.linphone.org:444/lft.php</entry>
<entry name="ice_preference" overwrite="true">1</entry>
<entry name="stun_preference" overwrite="true">stun.linphone.org</entry>
<entry name="random_port_preference" overwrite="true">1</entry>