Skip to content

Instantly share code, notes, and snippets.

@nairihar
Created March 24, 2017 15:28
Show Gist options
  • Save nairihar/ad3f5ab046987586c0d3785ac04c6d9f to your computer and use it in GitHub Desktop.
Save nairihar/ad3f5ab046987586c0d3785ac04c6d9f to your computer and use it in GitHub Desktop.
file
var Lynx = require('lynx');
function _onError(err) {
console.log(err);
}
var _options = {
host : 'sfast-grafana.cloudapp.net',
port : 8125
};
var metrics = new Lynx(_options.host, _options.port, {on_error: _onError});
var timer = null;
function BlotMetrics(userId) {
var _roomId = null,
_gameId = null;
// ** calling findRoom() from room if user can play
this.findRoom = function(roomType) {
metrics.increment("bcclub.find_room");
metrics.set("bcclub.findRoomType", roomType);
};
// ** calling createRoom() from room when stack created rooms
this.createRoom = function(roomId) {
metrics.increment("bcclub.new_room_counter");
};
// ** calling startUserGame() from game when game is starting
this.startUserGame = function(gameId) {
_gameId = gameId;
metrics.set("bcclub.startgame_set", _gameId);
metrics.increment("bcclub.startgame_counter");
};
// ** calling endUserGame() from game when game is finished
this.endUserGame = function() {
if(!_gameId) {
metrics.increment("bcclub.endgame_null_gameid");
return;
}
metrics.increment("bcclub.endgame_counter");
metrics.set("bcclub.endgame_set", _gameId);
_gameId = null;
};
// ** calling recconenctRoom() from room when welcome rooom active
this.recconenctRoom = function() {
metrics.set("bcclub.reconnectRoom");
metrics.increment("bcclub.reconnect_room_counter");
};
// ** calling recconenctRoom() from socket when user will leave fromgame
this.leaveUserGame = function() {
if(!_gameId) {
metrics.increment("bcclub.leavegame_null_gameid");
return;
}
metrics.increment("bcclub.leavegame_counter");
metrics.set("bcclub.leavegame_set", _gameId);
if(timer) {
timer.stop();
timer = null;
}
_gameId = null;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment