Skip to content

Commit

Permalink
feat: Add rx timestamp to rinfo payload (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenne committed Dec 5, 2020
1 parent a8e124c commit c468a39
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions android/src/main/java/com/tradle/react/UdpSockets.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ public void run() {
*/
@Override
public void didReceiveData(final UdpSocketClient socket, final String data, final String host, final int port) {
final long ts = System.currentTimeMillis();
executorService.execute(new Thread(new Runnable() {
@Override
public void run() {
Expand All @@ -317,6 +318,8 @@ public void run() {
eventParams.putString("data", data);
eventParams.putString("address", host);
eventParams.putInt("port", port);
// Use string for ts since it's 64 bits and putInt is only 32
eventParams.putString("ts", Long.toString(ts));

ReactContext reactContext = UdpSockets.this.getReactApplicationContext();
reactContext
Expand Down
4 changes: 3 additions & 1 deletion ios/UdpSockets.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@ - (void)dealloc

- (void) onData:(UdpSocketClient*) client data:(NSData *)data host:(NSString *)host port:(uint16_t)port
{
long ts = (long)([[NSDate date] timeIntervalSince1970] * 1000);
NSNumber *clientID = [[_clients allKeysForObject:client] objectAtIndex:0];
NSString *base64String = [data base64EncodedStringWithOptions:0];
[self.bridge.eventDispatcher sendDeviceEventWithName:[NSString stringWithFormat:@"udp-%@-data", clientID]
body:@{
@"data": base64String,
@"address": host,
@"port": [NSNumber numberWithInt:port]
@"port": [NSNumber numberWithInt:port],
@"ts": [[NSNumber numberWithLong: ts] stringValue]
}
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/UdpSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default class UdpSocket extends EventEmitter {

/**
* @private
* @param {{ data: string; address: string; port: number; }} info
* @param {{ data: string; address: string; port: number; ts: number; }} info
*/
_onReceive(info) {
// from base64 string
Expand All @@ -170,6 +170,7 @@ export default class UdpSocket extends EventEmitter {
port: info.port,
family: 'IPv4',
size: buf.length,
ts: Number(info.ts),
}
this.emit('message', buf, rinfo)
}
Expand Down

0 comments on commit c468a39

Please sign in to comment.