Skip to content

Commit

Permalink
* adding a beginning of audio support
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Mercadal committed Mar 4, 2010
1 parent 1f5b9b9 commit 23cfb34
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 23 deletions.
Binary file added Resources/Receive.mp3
Binary file not shown.
37 changes: 36 additions & 1 deletion TNStropheConnection.j
Expand Up @@ -93,12 +93,16 @@ TNStropheConnectionStatusDisconnected = @"TNStropheConnectionStatusDisconnec
@implementation TNStropheConnection: CPObject
{
CPString jid @accessors();
CPString resource @accessors();
CPString password @accessors();
id delegate @accessors();


CPString _boshService;
id _connection;
CPDictionary _registredHandlerDict;

id _audioTagReceive;
}

/*! instanciate a TNStropheConnection object
Expand All @@ -125,6 +129,11 @@ TNStropheConnectionStatusDisconnected = @"TNStropheConnectionStatusDisconnec
return [[TNStropheConnection alloc] initWithService:aService jid:aJid password:aPassword];
}

+ (TNStropheConnection)connectionWithService:(CPString)aService jid:(CPString)aJid resource:(CPString)aResource password:(CPString)aPassword
{
return [[TNStropheConnection alloc] initWithService:aService jid:aJid resource:aResource password:aPassword];
}


/*! initialize the TNStropheConnection
Expand All @@ -136,6 +145,15 @@ TNStropheConnectionStatusDisconnected = @"TNStropheConnectionStatusDisconnec
{
_boshService = aService;
_registredHandlerDict = [[CPDictionary alloc] init];
resource = @"controller";

var bundle = [CPBundle bundleForClass:[self class]];
var sound = [bundle pathForResource:@"Receive.mp3"];

_audioTagReceive = document.createElement('audio');
_audioTagReceive.setAttribute("src", sound);
document.body.appendChild(_audioTagReceive);

}

return self;
Expand All @@ -158,6 +176,18 @@ TNStropheConnectionStatusDisconnected = @"TNStropheConnectionStatusDisconnec
return self;
}

- (id)initWithService:(CPString)aService jid:(CPString)aJid resource:(CPString)aResource password:(CPString)aPassword
{
if (self = [self initWithService:aService])
{
[self setJid:aJid];
[self setPassword:aPassword];
[self setResource:aResource];
}

return self;
}


/*! connect to the XMPP Bosh Service. on different events, messages are sent to delegate and notification are sent
Expand All @@ -167,7 +197,7 @@ TNStropheConnectionStatusDisconnected = @"TNStropheConnectionStatusDisconnec
try
{
_connection = new Strophe.Connection(_boshService);
_connection.connect([self jid], [self password], function (status, errorCond)
_connection.connect([self jid] + @"/controller", [self password], function (status, errorCond)
{
var center = [CPNotificationCenter defaultCenter];

Expand Down Expand Up @@ -359,6 +389,11 @@ TNStropheConnectionStatusDisconnected = @"TNStropheConnectionStatusDisconnec
_connection.flush();
}


- (void)playReceivedSound
{
_audioTagReceive.play();
}
@end


Expand Down
48 changes: 26 additions & 22 deletions TNStropheContact.j
Expand Up @@ -133,11 +133,13 @@ TNStropheContactMessageSentNotification = @"TNStropheContactMessageSentNotif
{
[self setValue:TNStropheContactStatusOffline forKey:@"status"];
[self setValue:_imageOffline forKeyPath:@"statusIcon"];
_statusReminder = _imageOffline;
}
else
{
[self setValue:TNStropheContactStatusOnline forKey:@"status"];
[self setValue:_imageOnline forKeyPath:@"statusIcon"];
_statusReminder = _imageOnline;

show = [aStanza firstChildWithName:@"show"];
if (show)
Expand All @@ -147,16 +149,19 @@ TNStropheContactMessageSentNotification = @"TNStropheContactMessageSentNotif
{
[self setValue:TNStropheContactStatusBusy forKey:@"status"];
[self setValue:_imageBusy forKeyPath:@"statusIcon"];
_statusReminder = _imageBusy;
}
else if (textValue == TNStropheContactStatusAway)
{
[self setValue:TNStropheContactStatusAway forKey:@"status"];
[self setValue:_imageAway forKeyPath:@"statusIcon"];
_statusReminder = _imageAway;
}
else if (textValue == TNStropheContactStatusDND)
{
[self setValue:TNStropheContactStatusDND forKey:@"status"];
[self setValue:_imageDND forKeyPath:@"statusIcon"];
_statusReminder = _imageDND;
}
}
}
Expand Down Expand Up @@ -212,12 +217,12 @@ TNStropheContactMessageSentNotification = @"TNStropheContactMessageSentNotif

[[self messagesQueue] addObject:aStanza];

_statusReminder = [self statusIcon];
[self setValue:_imageNewMessage forKeyPath:@"statusIcon"]
[self setStatusIcon:_imageNewMessage];

[center postNotificationName:TNStropheContactMessageReceivedNotification object:self userInfo:userInfo];



[[self connection] playReceivedSound];

return YES;
}

Expand Down Expand Up @@ -278,33 +283,32 @@ TNStropheContactMessageSentNotification = @"TNStropheContactMessageSentNotif

- (TNStropheStanza)popMessagesQueue
{
var lastMessage = [[self messagesQueue] lastObject];

if (_statusReminder)
{
[self setValue:_statusReminder forKeyPath:@"statusIcon"]
_statusReminder = Nil;
if ([[self messagesQueue] count] == 0)
return Nil;

var center = [CPNotificationCenter defaultCenter];
[center postNotificationName:TNStropheContactMessageTreatedNotification object:self];
}
var lastMessage = [[self messagesQueue] objectAtIndex:0];
var center = [CPNotificationCenter defaultCenter];


[self setStatusIcon:_statusReminder];

[[self messagesQueue] removeLastObject];
[[self messagesQueue] removeObjectAtIndex:0];

[center postNotificationName:TNStropheContactMessageTreatedNotification object:self];

return lastMessage;
}

- (void)freeMessagesQueue
{
if (_statusReminder)
{
[self setValue:_statusReminder forKeyPath:@"statusIcon"]
_statusReminder = Nil;

var center = [CPNotificationCenter defaultCenter];
[center postNotificationName:TNStropheContactMessageTreatedNotification object:self];
}
var center = [CPNotificationCenter defaultCenter];


[self setStatusIcon:_statusReminder];

[[self messagesQueue] removeAllObjects];

[center postNotificationName:TNStropheContactMessageTreatedNotification object:self];
}


Expand Down

0 comments on commit 23cfb34

Please sign in to comment.