Skip to content

Commit

Permalink
Add the custom signature management
Browse files Browse the repository at this point in the history
  • Loading branch information
enricostara committed Apr 15, 2015
1 parent 02647a8 commit 3253a2b
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions lib/telegram.link.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var telegramMt = require('telegram-mt-node');
var auth = telegramMt.auth;
var utility = telegramMt.utility;
var net = telegramMt.net;
require('colors');
// ***

// This module is the entry-point of **Telegram.link** library and provides the highest-level **interface** to communicate
Expand Down Expand Up @@ -48,7 +49,7 @@ var net = telegramMt.net;

// The code:
function createClient(appId, primaryDC) {
var args = arguments;
var args = Array.prototype.slice.call(arguments);
var options = {};
var callback;
if (typeof args[2] === 'object') {
Expand Down Expand Up @@ -102,9 +103,9 @@ require('util').inherits(Client, require('events').EventEmitter);
// - **authKey**: the authentication key exchanged with Telegram

// The code:
Client.prototype.createAuthKey = function(callback) {
Client.prototype.createAuthKey = function (callback) {
if (callback) {
this.once(exports.EVENT.AUTH_KEY_CREATE, function(auth) {
this.once(exports.EVENT.AUTH_KEY_CREATE, function (auth) {
this._authKey = auth.key;
this._serverSalt = auth.serverSalt;
callback(auth);
Expand All @@ -128,7 +129,7 @@ Client.prototype.createAuthKey = function(callback) {
// The last parameter **callback** will be added as a listener for the `end` event

// The code:
Client.prototype.end = function(callback) {
Client.prototype.end = function (callback) {
if (callback) {
this.once(exports.EVENT.END, callback);
}
Expand All @@ -152,7 +153,7 @@ function connect() {

// The code:
function createEventEmitterCallback(event) {
return function(ex) {
return function (ex) {
if (ex) {
this.emit(exports.EVENT.ERROR, ex);
} else {
Expand Down Expand Up @@ -182,6 +183,20 @@ function createEventEmitterCallback(event) {

// ***

// Print the library version
module.exports = exports = function (signature) {
if (signature !== false) {
console.log('\n' + (signature || staticInfo.signature.cyan));
var caption = signature ?
'powered by telegram.link' :
('v.' + require('../package.json').version);
console.log(caption.gray + '\n');
}
return module.exports;
};

// ***

// Export the event names:
exports.EVENT = {
ERROR: 'error',
Expand All @@ -196,12 +211,6 @@ var staticInfo = require('./static');
exports.TEST_PRIMARY_DC = staticInfo.telegram.test.primaryDataCenter;
exports.PROD_PRIMARY_DC = staticInfo.telegram.prod.primaryDataCenter;

// ***

// Print the library version
console.log(staticInfo.signature);
console.log('v.%s', require('../package.json').version);

// Register the project name on the logging system
var getLogger = require('get-log');
getLogger.PROJECT_NAME = require('../package.json').name;

0 comments on commit 3253a2b

Please sign in to comment.