Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle Bump prettier from 2.0.5 to 2.5.1 #127

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions examples/bin/promises-example.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,18 @@ var initCallbacks = function (callback) {
getStatus = tox.getFriendStatusAsync(e.friend()),
getConnectionStatus = tox.getFriendConnectionStatusAsync(e.friend());

Promise.join(
getName,
getStatusMessage,
getStatus,
getConnectionStatus,
function (name, statusMessage, status, connectionStatus) {
console.log("Friend " + e.friend() + " profile:");
console.log(" Name: " + name);
console.log(" Status message: " + statusMessage);
console.log(" Status: " + status);
console.log(" Connection status: " + connectionStatus);
}
);
Promise.join(getName, getStatusMessage, getStatus, getConnectionStatus, function (
name,
statusMessage,
status,
connectionStatus
) {
console.log("Friend " + e.friend() + " profile:");
console.log(" Name: " + name);
console.log(" Status message: " + statusMessage);
console.log(" Status: " + status);
console.log(" Connection status: " + connectionStatus);
});
}

if (e.message() === "lastonline") {
Expand Down
139 changes: 68 additions & 71 deletions lib/tox.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ Tox.prototype.inspect = function () {
Object.keys(this).forEach(function (k) {
obj[k] = this[k];
// Hacky fix for StringSlice assert error:
// void node::Buffer::StringSlice(const v8::FunctionCallbackInfo<v8::Value>&) [with node::encoding encoding = (node::encoding)5u]: Assertion `obj_data != __null' failed.
// void node::Buffer::StringSlice(const
// v8::FunctionCallbackInfo<v8::Value>&) [with node::encoding encoding =
// (node::encoding)5u]: Assertion `obj_data != __null' failed.
if (k === "_options") {
// linting is weird and wants us to specifically `.toString()` this
obj[k.toString()] = "[ToxOptions]";
Expand Down Expand Up @@ -1032,18 +1034,16 @@ Tox.prototype.addFriendNoRequest = function (publicKey, callback) {
if (!this._checkHandle(callback)) return;
publicKey = fromHex(publicKey);
var eptr = ref.alloc(TOX_ERR_FRIEND_ADD);
this.getLibrary().tox_friend_add_norequest.async(
this.getHandle(),
publicKey,
eptr,
function (err, friend) {
var terr = errors.friendAdd(eptr.deref());
if (!err && terr) err = terr;
if (callback) {
callback(err, friend);
}
this.getLibrary().tox_friend_add_norequest.async(this.getHandle(), publicKey, eptr, function (
err,
friend
) {
var terr = errors.friendAdd(eptr.deref());
if (!err && terr) err = terr;
if (callback) {
callback(err, friend);
}
);
});
};

/**
Expand All @@ -1069,19 +1069,17 @@ Tox.prototype.addFriendNoRequestSync = function (publicKey) {
Tox.prototype.deleteFriend = function (friend, callback) {
if (!this._checkHandle(callback)) return;
var eptr = ref.alloc(TOX_ERR_FRIEND_DELETE);
this.getLibrary().tox_friend_delete.async(
this.getHandle(),
friend,
eptr,
function (err, success) {
var terr = errors.friendDelete(eptr.deref());
if (!err && terr) err = terr;
if (!err && !success) err = errors.unsuccessful();
if (callback) {
callback(err);
}
this.getLibrary().tox_friend_delete.async(this.getHandle(), friend, eptr, function (
err,
success
) {
var terr = errors.friendDelete(eptr.deref());
if (!err && terr) err = terr;
if (!err && !success) err = errors.unsuccessful();
if (callback) {
callback(err);
}
);
});
};

/**
Expand All @@ -1106,18 +1104,16 @@ Tox.prototype.getFriendByPublicKey = function (publicKey, callback) {
if (!this._checkHandle(callback)) return;
publicKey = fromHex(publicKey);
var eptr = ref.alloc(TOX_ERR_FRIEND_BY_PUBLIC_KEY);
this.getLibrary().tox_friend_by_public_key.async(
this.getHandle(),
publicKey,
eptr,
function (err, friend) {
var terr = errors.friendByPublicKey(eptr.deref());
if (!err && terr) err = terr;
if (callback) {
callback(err, friend);
}
this.getLibrary().tox_friend_by_public_key.async(this.getHandle(), publicKey, eptr, function (
err,
friend
) {
var terr = errors.friendByPublicKey(eptr.deref());
if (!err && terr) err = terr;
if (callback) {
callback(err, friend);
}
);
});
};

/**
Expand Down Expand Up @@ -1211,22 +1207,20 @@ Tox.prototype.hasFriendSync = function (friend) {
Tox.prototype.getFriendLastOnline = function (friend, callback) {
if (!this._checkHandle(callback)) return;
var eptr = ref.alloc(TOX_ERR_FRIEND_GET_LAST_ONLINE);
this.getLibrary().tox_friend_get_last_online.async(
this.getHandle(),
friend,
eptr,
function (err, timeval) {
var terr = errors.friendGetLastOnline(eptr.deref());
if (!err && terr) err = terr;
this.getLibrary().tox_friend_get_last_online.async(this.getHandle(), friend, eptr, function (
err,
timeval
) {
var terr = errors.friendGetLastOnline(eptr.deref());
if (!err && terr) err = terr;

var date;
if (!err) date = getDateFromUInt64(timeval);
var date;
if (!err) date = getDateFromUInt64(timeval);

if (callback) {
callback(err, date);
}
if (callback) {
callback(err, date);
}
);
});
};

/**
Expand Down Expand Up @@ -1538,20 +1532,17 @@ Tox.prototype.getTcpPortSync = function () {
Tox.prototype.setTyping = function (friend, typing, callback) {
if (!this._checkHandle(callback)) return;
var eptr = ref.alloc(TOX_ERR_SET_TYPING);
this.getLibrary().tox_self_set_typing.async(
this.getHandle(),
friend,
typing,
eptr,
function (err, success) {
var terr = errors.setTyping(eptr.deref());
if (!err && terr) err = terr;
if (!err && !success) err = errors.unsuccessful();
if (callback) {
callback(err);
}
this.getLibrary().tox_self_set_typing.async(this.getHandle(), friend, typing, eptr, function (
err,
success
) {
var terr = errors.setTyping(eptr.deref());
if (!err && terr) err = terr;
if (!err && !success) err = errors.unsuccessful();
if (callback) {
callback(err);
}
);
});
};

/**
Expand Down Expand Up @@ -2357,7 +2348,8 @@ Tox.prototype.getSecretKeyHexSync = function () {
/**
* Check if this Tox instance has a handle associated with it.
* @private
* @param {Tox~errorCallback} callback - Callback to pass Error object to if no handle
* @param {Tox~errorCallback} callback - Callback to pass Error object to if no
* handle
* @return {Boolean} true if has handle (no error), false if no handle (error)
*/
Tox.prototype._checkHandle = function (callback) {
Expand Down Expand Up @@ -2527,20 +2519,22 @@ Tox.prototype._fixFileControl = function (control) {
};

/**
* Fix a send lossless packet value. Adds magic byte(160) to the first byte of data
* Fix a send lossless packet value. Adds magic byte(160) to the first byte of
* data
* @private
* @param {Buffer} data
* @return {Buffer} new data
*/
Tox.prototype._fixSendLosslessPacket = function (data) {
//160: magic byte
// 160: magic byte
return Buffer.concat([Buffer.from([160]), data]);
};

/**
* Fix a lossless/lossy packet buffer by prepending an id byte.
* @private
* @param {Number} id - Byte to prepend, according to tox.h it should be in the range
* @param {Number} id - Byte to prepend, according to tox.h it should be in the
* range
* [160, 191] if lossless and [200, 254] if lossy.
* @param {Buffer} data - Data buffer to prepend to
* @return {Buffer} new data
Expand Down Expand Up @@ -2635,7 +2629,8 @@ Tox.prototype._setProxyToToxOptions = function (opts, options) {
};

/**
* Store an ffi.Callback. This is to prevent an annoying ffi garbage collection bug.
* Store an ffi.Callback. This is to prevent an annoying ffi garbage collection
* bug.
* @private
* @param {Object} key - Key
* @param {ffi.Callback} callback - Callback
Expand Down Expand Up @@ -2663,7 +2658,8 @@ Tox.prototype._toFFICallback = function (ffiFunc, callback) {
/////////////////////

/**
* Used in: Tox#bootstrap(), Tox#bootstrapSync(), Tox#addTCPRelay(), Tox#addTCPRelaySync().
* Used in: Tox#bootstrap(), Tox#bootstrapSync(), Tox#addTCPRelay(),
* Tox#addTCPRelaySync().
* @private
*/
Tox.prototype._performBootstrap = function (opts) {
Expand Down Expand Up @@ -3285,8 +3281,8 @@ Tox.prototype._initFileRecvChunkCb = function () {
cb: FileRecvChunkCallback,
name: "FileRecvChunkCallback",
wrapper: function (handle, friend, file, position, data, size, userdata) {
// Apparently data can sometimes be a NULL pointer, set data to undefined if so
// This should only happen on final chunk?
// Apparently data can sometimes be a NULL pointer, set data to undefined
// if so This should only happen on final chunk?
if (ref.address(data) !== 0) {
data = Buffer.from(ref.reinterpret(data, size)); // Copy to another Buffer
} else {
Expand All @@ -3308,9 +3304,10 @@ Tox.prototype._initFriendLosslessPacketCb = function () {
cb: FriendLosslessPacketCallback,
name: "FriendLosslessPacketCallback",
wrapper: function (handle, friend, data, length, userdata) {
//if(ref.address(data) !== 0) {
// if(ref.address(data) !== 0) {
// //first byte is magic byte(160) so ignore it
// data = Buffer.from(ref.reinterpret(data, (length - 1), 1)); // Copy to another Buffer
// data = Buffer.from(ref.reinterpret(data, (length - 1), 1)); // Copy to
// another Buffer
//} else {
// data = undefined;
//}
Expand Down