-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample.js
80 lines (70 loc) · 2.64 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var Observer = require('./lib/observer.js')
, KeyframeParser = require('./lib/parser/keyframe.js')
, co = require('co')
var euw = new Observer('sk')
euw.getFeaturedGames(function (err, games) {
if(err) {
console.error(err)
return
}
/*games[0].getMetadata(function(err, data, game) {
console.log(game)
})*/
for(var i=0;i<games.length;i++)
spectate(games[i])
})
/*
euw.getGame('1265814599', 'EUW1', function(err, game) {
game.getMetadata()
})
*/
function spectate(game) {
var first = true
game
.on('keyframe.available', function(data) {
console.log('new keyframe: ', data.id)
var buffers = []
var stream = data.download()
stream.on('data', function(bfr) {
buffers.push(bfr)
})
stream.on('end', function() {
var full = Buffer.concat(buffers)
console.log('loaded keyframe ' + data.id + '#'+ game.id +' Bytes: ' + full.length)
try {
KeyframeParser().parse(full, dump);
}
catch(e) {
console.log(e)
}
function dump(data) {
console.log('time: ', data.time)
console.log('%s players:', data.players.length)
/*for(var pid in data.players) {
console.log("player data: %s - %s", data.players[pid].start, data.players[pid].end)
console.log("player[%s]: %s", data.players[pid].entity[0], data.players[pid].name)
//console.log(data.players[pid].rubish)
//console.log(data.players[pid].masteryPointsTotal)
//console.log(data.players[pid].items)
}*/
/*console.log('%s towers:', data.towers.length)
for(var tid in data.towers) {
if(data.towers[tid].itemHeader[1]) {
console.log(data.towers[tid].entity[0], data.towers[tid].name)
console.log(data.towers[tid].unknown)
console.log(data.towers[tid].itemHeader)
console.log(data.towers[tid].items)
}
}*/
}
})
})
.on('chunk.available', function(data) {
//console.log('new chunk: ', data.id)
})
.on('end', function(data) {
console.log('END')
})
.startSpectate()
console.log('spectating game: ' + game.id + ' ' + game.region)
}