From ef25655365eb97d29295f8e0cb720b86a29c5e26 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 16 Apr 2016 11:47:03 +1200 Subject: Bind async connection to user id --- src/org/traccar/api/AsyncSocket.java | 10 +++++----- src/org/traccar/api/resource/PositionResource.java | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/org/traccar/api') diff --git a/src/org/traccar/api/AsyncSocket.java b/src/org/traccar/api/AsyncSocket.java index 5353a8d85..35e760613 100644 --- a/src/org/traccar/api/AsyncSocket.java +++ b/src/org/traccar/api/AsyncSocket.java @@ -33,26 +33,26 @@ public class AsyncSocket extends WebSocketAdapter implements ConnectionManager.U private static final String KEY_DEVICES = "devices"; private static final String KEY_POSITIONS = "positions"; - private Collection devices; + private long userId; public AsyncSocket(long userId) { - devices = Context.getPermissionsManager().getDevicePermissions(userId); + this.userId = userId; } @Override public void onWebSocketConnect(Session session) { super.onWebSocketConnect(session); - sendData(KEY_POSITIONS, Context.getConnectionManager().getInitialState(devices)); + sendData(KEY_POSITIONS, Context.getConnectionManager().getInitialState(userId)); - Context.getConnectionManager().addListener(devices, this); + Context.getConnectionManager().addListener(userId, this); } @Override public void onWebSocketClose(int statusCode, String reason) { super.onWebSocketClose(statusCode, reason); - Context.getConnectionManager().removeListener(devices, this); + Context.getConnectionManager().removeListener(userId, this); } @Override diff --git a/src/org/traccar/api/resource/PositionResource.java b/src/org/traccar/api/resource/PositionResource.java index 9c174625c..2da517d4f 100644 --- a/src/org/traccar/api/resource/PositionResource.java +++ b/src/org/traccar/api/resource/PositionResource.java @@ -39,8 +39,7 @@ public class PositionResource extends BaseResource { @QueryParam("deviceId") long deviceId, @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException { if (deviceId == 0) { - return Context.getConnectionManager().getInitialState( - Context.getPermissionsManager().getDevicePermissions(getUserId())); + return Context.getConnectionManager().getInitialState(getUserId()); } else { Context.getPermissionsManager().checkDevice(getUserId(), deviceId); return Context.getDataManager().getPositions( -- cgit v1.2.3