Skip to content

Commit

Permalink
Merge pull request #4 from JoaoCaixinha/master
Browse files Browse the repository at this point in the history
Ortc emoji support
  • Loading branch information
realtime-framework committed Oct 13, 2015
2 parents fc7ed65 + bd8cc73 commit 147cca1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
39 changes: 33 additions & 6 deletions RCTRealtimeMessaging/OrtcClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -1279,28 +1279,53 @@ - (void)opReceive:(NSString*) message {
[messagesBuffer setObject:msgSentDict forKey:messageId];
}
aMessage = [self escapeRecvChars:aMessage];
channelSubscription.onMessage(self, aChannel, aMessage);
}

aMessage = [self checkForEmoji:aMessage];
channelSubscription.onMessage(self, aChannel, aMessage);
}
}
}
}
}


- (NSString*)checkForEmoji:(NSString*)str{
for (int i = 0; i < str.length; i++) {
unichar ascii = [str characterAtIndex:i];
if(ascii == '\\'){
i = i + 1;
int next = [str characterAtIndex:i];

if(next == 'u'){
NSString *emoji = [str substringWithRange:NSMakeRange(i - 1, 12)];
NSData *pos = [emoji dataUsingEncoding:NSUTF8StringEncoding];
emoji = [[NSString alloc] initWithData:pos encoding:NSNonLossyASCIIStringEncoding];

str = [str stringByReplacingCharactersInRange:NSMakeRange(i - 1, 12) withString:emoji];
}
}
}
return str;
}

- (NSString*)escapeRecvChars:(NSString*) str{
str = [self simulateJsonParse:str];
str = [self simulateJsonParse:str];
return str;
}
- (NSString*)simulateJsonParse:(NSString*) str{

- (NSString*)simulateJsonParse:(NSString*)str{
NSMutableString *ms = [NSMutableString string];
for(int i =0; i < [str length]; i++){
unichar ascii = [str characterAtIndex:i];

if(ascii > 128){ //unicode
[ms appendFormat:@"%@", [NSString stringWithCharacters:&ascii length:1]];
} else { //ascii
}else { //ascii
if(ascii == '\\'){
i = i + 1;
int next = [str characterAtIndex:i];

if(next == '\\'){
[ms appendString:@"\\"];
} else if(next == 'n'){
Expand All @@ -1315,13 +1340,15 @@ - (NSString*)simulateJsonParse:(NSString*) str{
[ms appendString:@"\r"];
} else if(next == 't'){
[ms appendString:@"\t"];
}
} else if(next == 'u'){
[ms appendString:@"\\u"];
}
} else {
[ms appendFormat:@"%c", ascii];
}
}
}
return ms;
return ms ;
}

- (NSString*)generateId:(int) size
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-realtimemessaging-ios",
"version": "1.0.10",
"version": "1.0.11",
"description": "The Realtime Framework Cloud Messaging Pub/Sub client for React-Native",
"main": "RCTRealtimeMessagingIOS.js",
"scripts": {
Expand Down

0 comments on commit 147cca1

Please sign in to comment.