Skip to content

Instantly share code, notes, and snippets.

@thirdy
Last active May 25, 2016 07:23
Show Gist options
  • Save thirdy/bcd34469b1ae92aeb40c322b294bc5b4 to your computer and use it in GitHub Desktop.
Save thirdy/bcd34469b1ae92aeb40c322b294bc5b4 to your computer and use it in GitHub Desktop.
<head>
<title>a streaming stash tab test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.6/socket.io.js"></script>
<script src="https://cdn.rawgit.com/broofa/node-uuid/master/uuid.js"></script>
<script>
var pwxid = uuid.v4();
var socket = io.connect('http://rtstashapi.exiletools.com', {query: 'pwxid=' + pwxid});
// Specify the filters here in a text format, we'll convert them to JSON. You can do this
// however you'd like in your own app obviously.
var filterText =
[{
"eq" : {
"attributes.league" : "Perandus",
"attributes.baseItemType" : "Jewelry",
"attributes.rarity" : "Rare",
"shop.hasPrice" : true
}
}, {
"eq" : {
"attributes.league" : "Standard",
"attributes.baseItemType" : "Armour",
"attributes.rarity" : "Rare",
"shop.hasPrice" : true
},
"gt" : {
"modsPseudo.+# Total to maximum Life" : 10
},
"lt" : {
"shop.chaosEquiv" : 100
}
}
]
;
// Convert the filter text to JSON
var filter = filterText//JSON.parse(filterText);
// On connect, verify the session and pwxid, then emit the filter object
// and notify locally of the filter sent for reference
socket.on("connect", function () {
var sessionid = socket.io.engine.id
console.log("Connected with session id " + sessionid + " and pwxid " + pwxid);
socket.emit('filter', filter);
console.log("Sent Filter: " + JSON.stringify(filter));
});
socket.on("item", function(item) {
console.log(item);
var et = item.attributes.equipType;
console.log(et);
var outputString = "<table border=1 cellspacing=0 cellpadding=5 width=100%><tr><td valign=top width=200>" + item.info.fullName + "</td><td width=400>";
if (item.mods[et].implicit) {
jQuery.each(item.mods[et].implicit, function(key, value) {
outputString += ("<b>" + key + " : " + value + "</b><br>");
});
}
if (item.mods[et].explicit) {
jQuery.each(item.mods[et].explicit, function(key, value) {
outputString += (key + " : " + value + "<br>");
});
}
$('#itemsDiv').prepend(outputString + "</td><td width=100>" + item.shop.sellerAccount + "</td><td width=100>" + item.shop.amount + " " + item.shop.currency + "</td><td width=250>" + new Date(item.shop.modified) + "</td></tr></table>");
});
socket.on('error', console.error.bind(console));
</script>
</head>
<body>
<h1>A test interface to streaming socket data</h1>
<p>There's nothing fancy here right now, it will just show a quick summary of every item modified
in the Stash Tab API. It is purely a proof of concept to show selected information from a JSON
object in a browser in real time.</p>
<div id='itemsDiv'></div>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment