Skip to content

Commit c468a39

Browse files
authored
feat: Add rx timestamp to rinfo payload (#146)
1 parent a8e124c commit c468a39

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

android/src/main/java/com/tradle/react/UdpSockets.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ public void run() {
297297
*/
298298
@Override
299299
public void didReceiveData(final UdpSocketClient socket, final String data, final String host, final int port) {
300+
final long ts = System.currentTimeMillis();
300301
executorService.execute(new Thread(new Runnable() {
301302
@Override
302303
public void run() {
@@ -317,6 +318,8 @@ public void run() {
317318
eventParams.putString("data", data);
318319
eventParams.putString("address", host);
319320
eventParams.putInt("port", port);
321+
// Use string for ts since it's 64 bits and putInt is only 32
322+
eventParams.putString("ts", Long.toString(ts));
320323

321324
ReactContext reactContext = UdpSockets.this.getReactApplicationContext();
322325
reactContext

ios/UdpSockets.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,15 @@ - (void)dealloc
127127

128128
- (void) onData:(UdpSocketClient*) client data:(NSData *)data host:(NSString *)host port:(uint16_t)port
129129
{
130+
long ts = (long)([[NSDate date] timeIntervalSince1970] * 1000);
130131
NSNumber *clientID = [[_clients allKeysForObject:client] objectAtIndex:0];
131132
NSString *base64String = [data base64EncodedStringWithOptions:0];
132133
[self.bridge.eventDispatcher sendDeviceEventWithName:[NSString stringWithFormat:@"udp-%@-data", clientID]
133134
body:@{
134135
@"data": base64String,
135136
@"address": host,
136-
@"port": [NSNumber numberWithInt:port]
137+
@"port": [NSNumber numberWithInt:port],
138+
@"ts": [[NSNumber numberWithLong: ts] stringValue]
137139
}
138140
];
139141
}

src/UdpSocket.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export default class UdpSocket extends EventEmitter {
160160

161161
/**
162162
* @private
163-
* @param {{ data: string; address: string; port: number; }} info
163+
* @param {{ data: string; address: string; port: number; ts: number; }} info
164164
*/
165165
_onReceive(info) {
166166
// from base64 string
@@ -170,6 +170,7 @@ export default class UdpSocket extends EventEmitter {
170170
port: info.port,
171171
family: 'IPv4',
172172
size: buf.length,
173+
ts: Number(info.ts),
173174
}
174175
this.emit('message', buf, rinfo)
175176
}

0 commit comments

Comments
 (0)