Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add rx timestamp to rinfo payload #146

Merged
merged 1 commit into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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