Skip to content

Commit 47be19a

Browse files
committed
feat: add caching for blips and player selection
Blips are now only downloaded when the user clicks "refresh" and when the app is first loaded. User can now select a player that is online to "track". Still need to implement tracking,
1 parent db6bd45 commit 47be19a

File tree

3 files changed

+70
-20
lines changed

3 files changed

+70
-20
lines changed

index.php

+32-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
7373
// Set to the IP of the GTA server running "live_map" and change the port to the
7474
// number that is in the "server.lua" file
75-
var _SETTINGS_socketUrl = "wss://identityrp.co.uk:30121"
75+
var _SETTINGS_socketUrl = "ws://localhost:30121"
7676
7777
</script>
7878
@@ -144,6 +144,14 @@ function startMarkers(){
144144
145145
<li id="socket_error" class="label label-danger"></li>
146146
147+
<li style="height: 50px;">
148+
<a>
149+
Track Player
150+
<select id="playerSelect" class="input-large form-control pull-right" style="width: 65%">
151+
<option></option>
152+
</select>
153+
</li>
154+
147155
</ul>
148156
149157
<ul class="nav nav-list" style="margin-top: 10px;">
@@ -163,7 +171,24 @@ function startMarkers(){
163171
<script>
164172
var _invervalId;
165173
var _isLive = false;
174+
var _blips = [];
175+
var _blipCount = 0;
166176
var _showBlips = true;
177+
var _isConnected = false;
178+
var _trackPlayer = null;
179+
180+
function toggleBlips(){
181+
console.log("showing local blips");
182+
if (_showBlips){
183+
_blips.forEach(function(blip){
184+
var desc = blip.description == undefined ? "" : blip.description;
185+
var obj = new MarkerObject(blip.name, new Coordinates(blip.x, blip.y, blip.z), MarkerTypes[blip.type], desc, "", "");
186+
createMarker(false, false, obj, "");
187+
});
188+
}else{
189+
clearAllMarkers();
190+
}
191+
}
167192
168193
$(document).ready(function(){
169194
globalInit();
@@ -179,7 +204,8 @@ function startMarkers(){
179204
180205
_showBlips = !_showBlips;
181206
182-
webSocket.send("getBlips");
207+
//webSocket.send("getBlips");
208+
toggleBlips();
183209
184210
$("#blips_enabled").removeClass("label-success").removeClass("label-danger")
185211
.addClass( _showBlips ? "label-success" : "label-danger")
@@ -195,6 +221,10 @@ function startMarkers(){
195221
196222
$("#toggleLive").click(function(e){
197223
e.preventDefault();
224+
if(!_isConnected){
225+
// Not connected
226+
return;
227+
}
198228
199229
_isLive = !_isLive;
200230
@@ -209,7 +239,6 @@ function startMarkers(){
209239
}
210240
211241
});
212-
213242
});
214243
</script>
215244
</html>

js/socket.min.js

+11-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/src/socket.js

+27-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ function connect(){
2121
}
2222

2323
function onOpen(e){
24+
_isConnected = true;
25+
console.log("_isConnected: " + _isConnected);
2426
// Get blips?
2527
webSocket.send("getBlips");
28+
webSocket.send("getLocations"); // Get any players connected to the server
2629

2730
$("#connection").removeClass("label-danger")
2831
.removeClass("label-warning")
@@ -82,7 +85,7 @@ function onError(e){
8285
else if(event.code == 1015)
8386
reason = "The connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified).";
8487
else
85-
reason = "Unknown reason";
88+
reason = "Unknown reason (Server is probably down)";
8689

8790
$("#socket_error").text(reason);
8891

@@ -96,27 +99,35 @@ function onClose(e){
9699
.removeClass("label-warning")
97100
.addClass("label-danger").text("disconnected");
98101

102+
_isConnected = false;
99103
if (_isLive){
100104
clearInterval(_invervalId);
101105
}
102106

103107
}
104108

109+
function addBlip(blip, bool){
110+
//_blipCount++;
111+
}
112+
105113
function initBlips(blips){
106-
var count = 0;
114+
_blipCount = 0;
115+
_blips = [];
107116
clearAllMarkers();
108117

109118
if (_showBlips){
110119
blips.forEach(function(blip){
111120
var desc = blip.description == undefined ? "" : blip.description;
112121
var obj = new MarkerObject(blip.name, new Coordinates(blip.x, blip.y, blip.z), MarkerTypes[blip.type], desc, "", "");
122+
123+
_blips[_blipCount++] = blip;
124+
113125
createMarker(false, false, obj, "");
114-
count++;
115126
});
116127
}
117128

118-
console.log(count + " blips created");
119-
$("#blip_count").text(count);
129+
console.log(_blipCount + " blips created");
130+
$("#blip_count").text(_blipCount);
120131
}
121132

122133
var localCache = {};
@@ -126,6 +137,10 @@ function playerLeft(playerName){
126137
clearMarker(localCache[playerName].marker);
127138
localCache[playerName].marker = null;
128139
}
140+
141+
if ($("#playerSelect option[value='" + playerName + "']").length > 0){
142+
$("#playerSelect option[value='" + playerName + "']").remove();
143+
}
129144
}
130145

131146
function doPlayerUpdate(players){
@@ -134,6 +149,13 @@ function doPlayerUpdate(players){
134149
playerCount ++;
135150
if (plr == null) return;
136151

152+
if ($("#playerSelect option[value='" + plr.id + "']").length <= 0){
153+
$("#playerSelect").append($("<option>", {
154+
value: plr.id,
155+
text: plr.name
156+
}));
157+
}
158+
137159
if (plr.id in localCache){
138160

139161
//console.log(JSON.stringify(plr));

0 commit comments

Comments
 (0)