diff --git a/examples/bin/promises-example.js b/examples/bin/promises-example.js old mode 100755 new mode 100644 index 6de6eff..bed0093 --- a/examples/bin/promises-example.js +++ b/examples/bin/promises-example.js @@ -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") { diff --git a/lib/tox.js b/lib/tox.js index d95dfc3..9d1af30 100644 --- a/lib/tox.js +++ b/lib/tox.js @@ -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&) [with node::encoding encoding = (node::encoding)5u]: Assertion `obj_data != __null' failed. + // void node::Buffer::StringSlice(const + // v8::FunctionCallbackInfo&) [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]"; @@ -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); } - ); + }); }; /** @@ -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); } - ); + }); }; /** @@ -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); } - ); + }); }; /** @@ -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); } - ); + }); }; /** @@ -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); } - ); + }); }; /** @@ -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) { @@ -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 @@ -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 @@ -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) { @@ -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 { @@ -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; //}