From 1f0b0169a0ad4e57d7114f7904f0c8c2f08fa3db Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 6 Dec 2021 11:59:19 +0000 Subject: [PATCH 1/2] Restyled by clang-format --- examples/bin/promises-example.js | 122 +- lib/tox.js | 2215 ++++++++++++++++-------------- 2 files changed, 1211 insertions(+), 1126 deletions(-) mode change 100755 => 100644 examples/bin/promises-example.js diff --git a/examples/bin/promises-example.js b/examples/bin/promises-example.js old mode 100755 new mode 100644 index 6de6eff..940578e --- a/examples/bin/promises-example.js +++ b/examples/bin/promises-example.js @@ -21,14 +21,14 @@ var tox = new toxcore.Tox(); * Bootstrap tox via hardcoded nodes. * For more nodes, see: https://wiki.tox.chat/users/nodes */ -var bootstrap = function (callback) { +var bootstrap = function(callback) { // Define nodes to bootstrap from var nodes = [ { - maintainer: "Anthony Bilinski", - address: "tox.abilinski.com", - port: 33445, - key: "10C00EB250C3233E343E2AEBA07115A5C28920E9C8D29492F6D00B29049EDC7E", + maintainer : "Anthony Bilinski", + address : "tox.abilinski.com", + port : 33445, + key : "10C00EB250C3233E343E2AEBA07115A5C28920E9C8D29492F6D00B29049EDC7E", }, ]; @@ -59,49 +59,55 @@ var bootstrap = function (callback) { }); }; -var initProfile = function (callback) { +var initProfile = function(callback) { var setName = tox.setNameAsync("Promises Bot"), - setStatusMessage = tox.setStatusMessageAsync("node-toxcore promises bot example"); + setStatusMessage = + tox.setStatusMessageAsync("node-toxcore promises bot example"); Promise.join(setName, setStatusMessage, callback); }; -var initCallbacks = function (callback) { - tox.on("selfConnectionStatus", function (e) { - console.log(e.isConnected() ? "Connected" : "Disconnected"); - }); +var initCallbacks = function(callback) { + tox.on( + "selfConnectionStatus", + function( + e) { console.log(e.isConnected() ? "Connected" : "Disconnected"); }); - tox.on("friendName", function (e) { + tox.on("friendName", function(e) { console.log("Friend[" + e.friend() + "] changed their name: " + e.name()); }); - tox.on("friendStatusMessage", function (e) { - console.log("Friend[" + e.friend() + "] changed their status message: " + e.statusMessage()); + tox.on("friendStatusMessage", function(e) { + console.log("Friend[" + e.friend() + + "] changed their status message: " + e.statusMessage()); }); - tox.on("friendStatus", function (e) { - console.log("Friend[" + e.friend() + "] changed their status: " + e.status()); + tox.on("friendStatus", function(e) { + console.log("Friend[" + e.friend() + + "] changed their status: " + e.status()); }); - tox.on("friendConnectionStatus", function (e) { - console.log("Friend[" + e.friend() + "] is now " + (e.isConnected() ? "online" : "offline")); + tox.on("friendConnectionStatus", function(e) { + console.log("Friend[" + e.friend() + "] is now " + + (e.isConnected() ? "online" : "offline")); }); - tox.on("friendTyping", function (e) { - console.log("Friend[" + e.friend() + "] is " + (e.isTyping() ? "typing" : "not typing")); + tox.on("friendTyping", function(e) { + console.log("Friend[" + e.friend() + "] is " + + (e.isTyping() ? "typing" : "not typing")); }); - tox.on("friendReadReceipt", function (e) { + tox.on("friendReadReceipt", function(e) { console.log("Friend[" + e.friend() + "] receipt: " + e.receipt()); }); - tox.on("friendRequest", function (e) { - tox.addFriendNoRequest(e.publicKey(), function (err, friend) { + tox.on("friendRequest", function(e) { + tox.addFriendNoRequest(e.publicKey(), function(err, friend) { console.log("Received friend request: " + e.message()); console.log("Accepted friend request from " + e.publicKeyHex()); }); }); - tox.on("friendMessage", function (e) { + tox.on("friendMessage", function(e) { if (e.isAction()) { console.log("** Friend[" + e.friend() + "] " + e.message() + " **"); } else { @@ -111,49 +117,46 @@ var initCallbacks = function (callback) { tox.sendFriendMessageSync(e.friend(), e.message(), e.messageType()); if (e.message() === "typing on") { - tox.setTyping(e.friend(), true, function (err) { + tox.setTyping(e.friend(), true, function(err) { console.log("Started typing to friend[" + e.friend() + "]"); }); } else if (e.message() === "typing off") { - tox.setTyping(e.friend(), false, function (err) { + tox.setTyping(e.friend(), false, function(err) { console.log("Stopped typing to friend[" + e.friend() + "]"); }); } if (e.message() === "profile") { var getName = tox.getFriendNameAsync(e.friend()), - getStatusMessage = tox.getFriendStatusMessageAsync(e.friend()), - 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); - } - ); + getStatusMessage = tox.getFriendStatusMessageAsync(e.friend()), + 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); + }); } if (e.message() === "lastonline") { - tox.getFriendLastOnlineAsync(e.friend).then(function (lastOnline) { + tox.getFriendLastOnlineAsync(e.friend).then(function(lastOnline) { console.log("Last online: " + lastOnline.toString()); }); } if (e.message() === "namelen") { var getNameSize = tox.getFriendNameSizeAsync(e.friend()), - getStatusMessageSize = tox.getFriendStatusMessageSizeAsync(e.friend()); - Promise.join(getNameSize, getStatusMessageSize, function (nameSize, statusMessageSize) { - console.log("Name length: " + nameSize); - console.log("Status message length: " + statusMessageSize); - }); + getStatusMessageSize = + tox.getFriendStatusMessageSizeAsync(e.friend()); + Promise.join(getNameSize, getStatusMessageSize, + function(nameSize, statusMessageSize) { + console.log("Name length: " + nameSize); + console.log("Status message length: " + statusMessageSize); + }); } }); @@ -163,15 +166,14 @@ var initCallbacks = function (callback) { // Initialize everything + bootstrap from nodes, then when everything // is ready, start async.parallel( - [ - bootstrap, // Bootstrap - initProfile, // Name, status message - initCallbacks, // Initialize callbacks - ], - function () { - tox.getAddressHex(function (err, address) { - console.log("Address: " + address); - tox.start(); // Start + [ + bootstrap, // Bootstrap + initProfile, // Name, status message + initCallbacks, // Initialize callbacks + ], + function() { + tox.getAddressHex(function(err, address) { + console.log("Address: " + address); + tox.start(); // Start + }); }); - } -); diff --git a/lib/tox.js b/lib/tox.js index d95dfc3..86bb3c7 100644 --- a/lib/tox.js +++ b/lib/tox.js @@ -74,13 +74,15 @@ var TOX_ERR_SET_TYPING = CEnum; // Buffer sizes for callbacks var KeyBuffer = RefArray("uint8", consts.TOX_KEY_SIZE); var KeyBufferPtr = ref.refType(KeyBuffer); -var RequestMessageBuffer = RefArray("uint8", consts.TOX_MAX_FRIEND_REQUEST_LENGTH); +var RequestMessageBuffer = + RefArray("uint8", consts.TOX_MAX_FRIEND_REQUEST_LENGTH); var RequestMessageBufferPtr = ref.refType(RequestMessageBuffer); var MessageBuffer = RefArray("uint8", consts.TOX_MAX_MESSAGE_LENGTH); var MessageBufferPtr = ref.refType(MessageBuffer); var NameBuffer = RefArray("uint8", consts.TOX_MAX_NAME_LENGTH); var NameBufferPtr = ref.refType(NameBuffer); -var StatusMessageBuffer = RefArray("uint8", consts.TOX_MAX_STATUS_MESSAGE_LENGTH); +var StatusMessageBuffer = + RefArray("uint8", consts.TOX_MAX_STATUS_MESSAGE_LENGTH); var StatusMessageBufferPtr = ref.refType(StatusMessageBuffer); var FilenameBuffer = RefArray("uint8", consts.TOX_MAX_FILENAME_LENGTH); var FilenameBufferPtr = ref.refType(FilenameBuffer); @@ -90,7 +92,8 @@ var UnknownSizeBuffer = RefArray("uint8", 1); var UnknownSizeBufferPtr = ref.refType(UnknownSizeBuffer); // Tox callback types -var SelfConnectionStatusCallback = ffi.Function("void", [ToxPtr, TOX_CONNECTION, UserData]); +var SelfConnectionStatusCallback = + ffi.Function("void", [ ToxPtr, TOX_CONNECTION, UserData ]); var FriendNameCallback = ffi.Function("void", [ ToxPtr, "uint32", @@ -105,15 +108,18 @@ var FriendStatusMessageCallback = ffi.Function("void", [ "size_t", UserData, ]); -var FriendStatusCallback = ffi.Function("void", [ToxPtr, "uint32", TOX_USER_STATUS, UserData]); +var FriendStatusCallback = + ffi.Function("void", [ ToxPtr, "uint32", TOX_USER_STATUS, UserData ]); var FriendConnectionStatusCallback = ffi.Function("void", [ ToxPtr, "uint32", TOX_CONNECTION, UserData, ]); -var FriendTypingCallback = ffi.Function("void", [ToxPtr, "uint32", "bool", UserData]); -var FriendReadReceiptCallback = ffi.Function("void", [ToxPtr, "uint32", "uint32", UserData]); +var FriendTypingCallback = + ffi.Function("void", [ ToxPtr, "uint32", "bool", UserData ]); +var FriendReadReceiptCallback = + ffi.Function("void", [ ToxPtr, "uint32", "uint32", UserData ]); var FriendRequestCallback = ffi.Function("void", [ ToxPtr, KeyBufferPtr, @@ -183,8 +189,9 @@ var FriendLossyPacketCallback = ffi.Function("void", [ * @class * @param {Object} [opts] Options */ -var Tox = function (opts) { - if (!opts) opts = {}; +var Tox = function(opts) { + if (!opts) + opts = {}; var libpath = opts["path"]; this._emitter = new events.EventEmitter(); @@ -199,12 +206,14 @@ var Tox = function (opts) { * Return a string representation of the Tox instance using util.inspect. * @return {String} string representation */ -Tox.prototype.inspect = function () { +Tox.prototype.inspect = function() { var obj = {}; - Object.keys(this).forEach(function (k) { + 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]"; @@ -220,7 +229,7 @@ Tox.prototype.inspect = function () { * @param {Tox~toxCallback} [callback] * @todo Implement with async tox_new? */ -Tox.load = function (opts, callback) { +Tox.load = function(opts, callback) { // Handle Tox.load(callback) if (arguments.length === 1 && _.isFunction(opts)) { callback = opts; @@ -229,7 +238,7 @@ Tox.load = function (opts, callback) { var data = opts["data"]; if (_.isString(data)) { - fs.readFile(data, function (err, data) { + fs.readFile(data, function(err, data) { if (!err) { opts["data"] = data; // Overwrite data (path) with data (Buffer) var tox = new Tox(opts); @@ -254,42 +263,64 @@ Tox.load = function (opts, callback) { * @param {String} [libpath="libtoxcore"] - Path to libtoxcore * @return {ffi.Library} */ -Tox.prototype.createLibrary = function (libpath) { +Tox.prototype.createLibrary = function(libpath) { libpath = libpath || "libtoxcore"; return ffi.Library(libpath, { - tox_add_tcp_relay: [ + tox_add_tcp_relay : [ + "bool", + [ ToxPtr, Int8Ptr, "uint16", UInt8Ptr, ref.refType(TOX_ERR_BOOTSTRAP) ], + ], + tox_bootstrap : [ "bool", - [ToxPtr, Int8Ptr, "uint16", UInt8Ptr, ref.refType(TOX_ERR_BOOTSTRAP)], + [ ToxPtr, Int8Ptr, "uint16", UInt8Ptr, ref.refType(TOX_ERR_BOOTSTRAP) ] ], - tox_bootstrap: ["bool", [ToxPtr, Int8Ptr, "uint16", UInt8Ptr, ref.refType(TOX_ERR_BOOTSTRAP)]], - tox_callback_file_chunk_request: ["void", [ToxPtr, FileChunkRequestCallback, UserData]], - tox_callback_file_recv: ["void", [ToxPtr, FileRecvCallback, UserData]], - tox_callback_file_recv_chunk: ["void", [ToxPtr, FileRecvChunkCallback, UserData]], - tox_callback_file_recv_control: ["void", [ToxPtr, FileRecvControlCallback, UserData]], - tox_callback_friend_connection_status: [ + tox_callback_file_chunk_request : + [ "void", [ ToxPtr, FileChunkRequestCallback, UserData ] ], + tox_callback_file_recv : [ "void", [ ToxPtr, FileRecvCallback, UserData ] ], + tox_callback_file_recv_chunk : + [ "void", [ ToxPtr, FileRecvChunkCallback, UserData ] ], + tox_callback_file_recv_control : + [ "void", [ ToxPtr, FileRecvControlCallback, UserData ] ], + tox_callback_friend_connection_status : [ "void", - [ToxPtr, FriendConnectionStatusCallback, UserData], + [ ToxPtr, FriendConnectionStatusCallback, UserData ], ], - tox_callback_friend_message: ["void", [ToxPtr, FriendMessageCallback, UserData]], - tox_callback_friend_name: ["void", [ToxPtr, FriendNameCallback, UserData]], - tox_callback_friend_read_receipt: ["void", [ToxPtr, FriendReadReceiptCallback, UserData]], - tox_callback_friend_request: ["void", [ToxPtr, FriendRequestCallback, UserData]], - tox_callback_friend_status: ["void", [ToxPtr, FriendStatusCallback, UserData]], - tox_callback_friend_status_message: ["void", [ToxPtr, FriendStatusMessageCallback, UserData]], - tox_callback_friend_typing: ["void", [ToxPtr, FriendTypingCallback, UserData]], - tox_callback_self_connection_status: ["void", [ToxPtr, SelfConnectionStatusCallback, UserData]], - tox_callback_friend_lossless_packet: ["void", [ToxPtr, FriendLosslessPacketCallback, UserData]], - tox_callback_friend_lossy_packet: ["void", [ToxPtr, FriendLossyPacketCallback, UserData]], - tox_file_control: [ + tox_callback_friend_message : + [ "void", [ ToxPtr, FriendMessageCallback, UserData ] ], + tox_callback_friend_name : + [ "void", [ ToxPtr, FriendNameCallback, UserData ] ], + tox_callback_friend_read_receipt : + [ "void", [ ToxPtr, FriendReadReceiptCallback, UserData ] ], + tox_callback_friend_request : + [ "void", [ ToxPtr, FriendRequestCallback, UserData ] ], + tox_callback_friend_status : + [ "void", [ ToxPtr, FriendStatusCallback, UserData ] ], + tox_callback_friend_status_message : + [ "void", [ ToxPtr, FriendStatusMessageCallback, UserData ] ], + tox_callback_friend_typing : + [ "void", [ ToxPtr, FriendTypingCallback, UserData ] ], + tox_callback_self_connection_status : + [ "void", [ ToxPtr, SelfConnectionStatusCallback, UserData ] ], + tox_callback_friend_lossless_packet : + [ "void", [ ToxPtr, FriendLosslessPacketCallback, UserData ] ], + tox_callback_friend_lossy_packet : + [ "void", [ ToxPtr, FriendLossyPacketCallback, UserData ] ], + tox_file_control : [ "bool", - [ToxPtr, "uint32", "uint32", TOX_FILE_CONTROL, ref.refType(TOX_ERR_FILE_CONTROL)], + [ + ToxPtr, "uint32", "uint32", TOX_FILE_CONTROL, + ref.refType(TOX_ERR_FILE_CONTROL) + ], ], - tox_file_get_file_id: [ + tox_file_get_file_id : [ "bool", - [ToxPtr, "uint32", "uint32", UInt8Ptr, ref.refType(TOX_ERR_FILE_GET)], + [ ToxPtr, "uint32", "uint32", UInt8Ptr, ref.refType(TOX_ERR_FILE_GET) ], ], - tox_file_seek: ["bool", [ToxPtr, "uint32", "uint32", "uint64", ref.refType(TOX_ERR_FILE_SEEK)]], - tox_file_send: [ + tox_file_seek : [ + "bool", + [ ToxPtr, "uint32", "uint32", "uint64", ref.refType(TOX_ERR_FILE_SEEK) ] + ], + tox_file_send : [ "uint32", [ ToxPtr, @@ -302,7 +333,7 @@ Tox.prototype.createLibrary = function (libpath) { ref.refType(TOX_ERR_FILE_SEND), ], ], - tox_file_send_chunk: [ + tox_file_send_chunk : [ "bool", [ ToxPtr, @@ -314,49 +345,64 @@ Tox.prototype.createLibrary = function (libpath) { ref.refType(TOX_ERR_FILE_SEND_CHUNK), ], ], - tox_friend_add: [ + tox_friend_add : [ "uint32", - [ToxPtr, UInt8Ptr, UInt8Ptr, "size_t", ref.refType(TOX_ERR_FRIEND_ADD)], + [ ToxPtr, UInt8Ptr, UInt8Ptr, "size_t", ref.refType(TOX_ERR_FRIEND_ADD) ], ], - tox_friend_add_norequest: ["uint32", [ToxPtr, UInt8Ptr, ref.refType(TOX_ERR_FRIEND_ADD)]], - tox_friend_by_public_key: [ + tox_friend_add_norequest : + [ "uint32", [ ToxPtr, UInt8Ptr, ref.refType(TOX_ERR_FRIEND_ADD) ] ], + tox_friend_by_public_key : [ "uint32", - [ToxPtr, UInt8Ptr, ref.refType(TOX_ERR_FRIEND_BY_PUBLIC_KEY)], + [ ToxPtr, UInt8Ptr, ref.refType(TOX_ERR_FRIEND_BY_PUBLIC_KEY) ], ], - tox_friend_delete: ["bool", [ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_DELETE)]], - tox_friend_exists: ["bool", [ToxPtr, "uint32"]], - tox_friend_get_connection_status: [ + tox_friend_delete : + [ "bool", [ ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_DELETE) ] ], + tox_friend_exists : [ "bool", [ ToxPtr, "uint32" ] ], + tox_friend_get_connection_status : [ TOX_CONNECTION, - [ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY)], + [ ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY) ], ], - tox_friend_get_last_online: [ + tox_friend_get_last_online : [ "uint64", - [ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_GET_LAST_ONLINE)], + [ ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_GET_LAST_ONLINE) ], + ], + tox_friend_get_name : [ + "bool", [ ToxPtr, "uint32", UInt8Ptr, ref.refType(TOX_ERR_FRIEND_QUERY) ] ], - tox_friend_get_name: ["bool", [ToxPtr, "uint32", UInt8Ptr, ref.refType(TOX_ERR_FRIEND_QUERY)]], - tox_friend_get_name_size: ["size_t", [ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY)]], - tox_friend_get_public_key: [ + tox_friend_get_name_size : + [ "size_t", [ ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY) ] ], + tox_friend_get_public_key : [ "uint32", - [ToxPtr, "uint32", UInt8Ptr, ref.refType(TOX_ERR_FRIEND_GET_PUBLIC_KEY)], + [ + ToxPtr, "uint32", UInt8Ptr, ref.refType(TOX_ERR_FRIEND_GET_PUBLIC_KEY) + ], + ], + tox_friend_get_status : [ + TOX_USER_STATUS, [ ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY) ] ], - tox_friend_get_status: [TOX_USER_STATUS, [ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY)]], - tox_friend_get_status_message: [ + tox_friend_get_status_message : [ "bool", - [ToxPtr, "uint32", UInt8Ptr, ref.refType(TOX_ERR_FRIEND_QUERY)], + [ ToxPtr, "uint32", UInt8Ptr, ref.refType(TOX_ERR_FRIEND_QUERY) ], ], - tox_friend_get_status_message_size: [ + tox_friend_get_status_message_size : [ "size_t", - [ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY)], + [ ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY) ], ], - tox_friend_send_lossless_packet: [ + tox_friend_send_lossless_packet : [ "bool", - [ToxPtr, "uint32", UInt8Ptr, "size_t", ref.refType(TOX_ERR_FRIEND_CUSTOM_PACKET)], + [ + ToxPtr, "uint32", UInt8Ptr, "size_t", + ref.refType(TOX_ERR_FRIEND_CUSTOM_PACKET) + ], ], - tox_friend_send_lossy_packet: [ + tox_friend_send_lossy_packet : [ "bool", - [ToxPtr, "uint32", UInt8Ptr, "size_t", ref.refType(TOX_ERR_FRIEND_CUSTOM_PACKET)], + [ + ToxPtr, "uint32", UInt8Ptr, "size_t", + ref.refType(TOX_ERR_FRIEND_CUSTOM_PACKET) + ], ], - tox_friend_send_message: [ + tox_friend_send_message : [ "uint32", [ ToxPtr, @@ -367,41 +413,47 @@ Tox.prototype.createLibrary = function (libpath) { ref.refType(TOX_ERR_FRIEND_SEND_MESSAGE), ], ], - tox_hash: ["bool", [UInt8Ptr, UInt8Ptr, "size_t"]], - tox_iteration_interval: ["uint32", [ToxPtr]], - tox_iterate: ["void", [ToxPtr]], - tox_kill: ["void", [ToxPtr]], - tox_new: [ToxPtr, [ToxOptionsPtr, ref.refType(TOX_ERR_NEW)]], - tox_get_savedata: ["void", [ToxPtr, UInt8Ptr]], - tox_get_savedata_size: ["size_t", [ToxPtr]], - tox_options_default: ["void", [ToxOptionsPtr]], - tox_options_free: ["void", [ToxOptionsPtr]], - tox_options_new: [ToxOptionsPtr, [ref.refType(TOX_ERR_OPTIONS_NEW)]], - tox_self_get_address: ["void", [ToxPtr, UInt8Ptr]], - tox_self_get_connection_status: [TOX_CONNECTION, [ToxPtr]], - tox_self_get_friend_list: ["void", [ToxPtr, UInt32Ptr]], - tox_self_get_friend_list_size: ["size_t", [ToxPtr]], - tox_self_get_name: ["void", [ToxPtr, UInt8Ptr]], - tox_self_get_name_size: ["size_t", [ToxPtr]], - tox_self_get_nospam: ["uint32", [ToxPtr]], - tox_self_get_public_key: ["void", [ToxPtr, UInt8Ptr]], - tox_self_get_secret_key: ["void", [ToxPtr, UInt8Ptr]], - tox_self_get_status: [TOX_USER_STATUS, [ToxPtr]], - tox_self_get_status_message: ["void", [ToxPtr, UInt8Ptr]], - tox_self_get_status_message_size: ["size_t", [ToxPtr]], - tox_self_get_tcp_port: ["uint16", [ToxPtr, ref.refType(TOX_ERR_GET_PORT)]], - tox_self_get_udp_port: ["uint16", [ToxPtr, ref.refType(TOX_ERR_GET_PORT)]], - tox_self_set_name: ["bool", [ToxPtr, UInt8Ptr, "size_t", ref.refType(TOX_ERR_SET_INFO)]], - tox_self_set_nospam: ["void", [ToxPtr, "uint32"]], - tox_self_set_status: ["void", [ToxPtr, TOX_USER_STATUS]], - tox_self_set_status_message: [ + tox_hash : [ "bool", [ UInt8Ptr, UInt8Ptr, "size_t" ] ], + tox_iteration_interval : [ "uint32", [ ToxPtr ] ], + tox_iterate : [ "void", [ ToxPtr ] ], + tox_kill : [ "void", [ ToxPtr ] ], + tox_new : [ ToxPtr, [ ToxOptionsPtr, ref.refType(TOX_ERR_NEW) ] ], + tox_get_savedata : [ "void", [ ToxPtr, UInt8Ptr ] ], + tox_get_savedata_size : [ "size_t", [ ToxPtr ] ], + tox_options_default : [ "void", [ ToxOptionsPtr ] ], + tox_options_free : [ "void", [ ToxOptionsPtr ] ], + tox_options_new : [ ToxOptionsPtr, [ ref.refType(TOX_ERR_OPTIONS_NEW) ] ], + tox_self_get_address : [ "void", [ ToxPtr, UInt8Ptr ] ], + tox_self_get_connection_status : [ TOX_CONNECTION, [ ToxPtr ] ], + tox_self_get_friend_list : [ "void", [ ToxPtr, UInt32Ptr ] ], + tox_self_get_friend_list_size : [ "size_t", [ ToxPtr ] ], + tox_self_get_name : [ "void", [ ToxPtr, UInt8Ptr ] ], + tox_self_get_name_size : [ "size_t", [ ToxPtr ] ], + tox_self_get_nospam : [ "uint32", [ ToxPtr ] ], + tox_self_get_public_key : [ "void", [ ToxPtr, UInt8Ptr ] ], + tox_self_get_secret_key : [ "void", [ ToxPtr, UInt8Ptr ] ], + tox_self_get_status : [ TOX_USER_STATUS, [ ToxPtr ] ], + tox_self_get_status_message : [ "void", [ ToxPtr, UInt8Ptr ] ], + tox_self_get_status_message_size : [ "size_t", [ ToxPtr ] ], + tox_self_get_tcp_port : + [ "uint16", [ ToxPtr, ref.refType(TOX_ERR_GET_PORT) ] ], + tox_self_get_udp_port : + [ "uint16", [ ToxPtr, ref.refType(TOX_ERR_GET_PORT) ] ], + tox_self_set_name : [ + "bool", [ ToxPtr, UInt8Ptr, "size_t", ref.refType(TOX_ERR_SET_INFO) ] + ], + tox_self_set_nospam : [ "void", [ ToxPtr, "uint32" ] ], + tox_self_set_status : [ "void", [ ToxPtr, TOX_USER_STATUS ] ], + tox_self_set_status_message : [ "bool", - [ToxPtr, UInt8Ptr, "size_t", ref.refType(TOX_ERR_SET_INFO)], + [ ToxPtr, UInt8Ptr, "size_t", ref.refType(TOX_ERR_SET_INFO) ], ], - tox_self_set_typing: ["bool", [ToxPtr, "uint32", "bool", ref.refType(TOX_ERR_SET_TYPING)]], - tox_version_major: ["uint32", []], - tox_version_minor: ["uint32", []], - tox_version_patch: ["uint32", []], + tox_self_set_typing : [ + "bool", [ ToxPtr, "uint32", "bool", ref.refType(TOX_ERR_SET_TYPING) ] + ], + tox_version_major : [ "uint32", [] ], + tox_version_minor : [ "uint32", [] ], + tox_version_patch : [ "uint32", [] ], }); }; @@ -413,11 +465,11 @@ Tox.prototype.createLibrary = function (libpath) { * Asynchronous tox_version_major(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.versionMajor = function (callback) { +Tox.prototype.versionMajor = function(callback) { this._performVersion({ - api: this.getLibrary().tox_version_major.async, - async: true, - callback: callback, + api : this.getLibrary().tox_version_major.async, + async : true, + callback : callback, }); }; @@ -425,9 +477,9 @@ Tox.prototype.versionMajor = function (callback) { * Synchronous tox_version_major(3). * @return {Number} major version number */ -Tox.prototype.versionMajorSync = function (callback) { +Tox.prototype.versionMajorSync = function(callback) { return this._performVersion({ - api: this.getLibrary().tox_version_major, + api : this.getLibrary().tox_version_major, }); }; @@ -435,11 +487,11 @@ Tox.prototype.versionMajorSync = function (callback) { * Asynchronous tox_version_minor(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.versionMinor = function (callback) { +Tox.prototype.versionMinor = function(callback) { this._performVersion({ - api: this.getLibrary().tox_version_minor.async, - async: true, - callback: callback, + api : this.getLibrary().tox_version_minor.async, + async : true, + callback : callback, }); }; @@ -447,9 +499,9 @@ Tox.prototype.versionMinor = function (callback) { * Synchronous tox_version_minor(3). * @return {Number} minor version number */ -Tox.prototype.versionMinorSync = function (callback) { +Tox.prototype.versionMinorSync = function(callback) { return this._performVersion({ - api: this.getLibrary().tox_version_minor, + api : this.getLibrary().tox_version_minor, }); }; @@ -457,11 +509,11 @@ Tox.prototype.versionMinorSync = function (callback) { * Asynchronous tox_version_patch(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.versionPatch = function (callback) { +Tox.prototype.versionPatch = function(callback) { this._performVersion({ - api: this.getLibrary().tox_version_patch.async, - async: true, - callback: callback, + api : this.getLibrary().tox_version_patch.async, + async : true, + callback : callback, }); }; @@ -469,9 +521,9 @@ Tox.prototype.versionPatch = function (callback) { * Synchronous tox_version_patch(3). * @return {Number} patch version number */ -Tox.prototype.versionPatchSync = function (callback) { +Tox.prototype.versionPatchSync = function(callback) { return this._performVersion({ - api: this.getLibrary().tox_version_patch, + api : this.getLibrary().tox_version_patch, }); }; @@ -480,7 +532,7 @@ Tox.prototype.versionPatchSync = function (callback) { * @param {ToxOptions} opts * @param {Tox~errorCallback} [callback] */ -Tox.prototype.freeOptions = function (opts, callback) { +Tox.prototype.freeOptions = function(opts, callback) { this.getLibrary().tox_options_free.async(opts.ref(), callback); }; @@ -488,9 +540,8 @@ Tox.prototype.freeOptions = function (opts, callback) { * Synchronous tox_options_free(3). * @param {ToxOptions} opts */ -Tox.prototype.freeOptionsSync = function (opts) { - this.getLibrary().tox_options_free(opts.ref()); -}; +Tox.prototype.freeOptionsSync = function( + opts) { this.getLibrary().tox_options_free(opts.ref()); }; /** * Asynchronous tox_options_new(3). @@ -499,10 +550,11 @@ Tox.prototype.freeOptionsSync = function (opts) { * @return {ToxOptions} Options * @todo Error handling */ -Tox.prototype.newOptions = function (callback) { - this.getLibrary().tox_options_new.async(ref.NULL, function (err, options) { +Tox.prototype.newOptions = function(callback) { + this.getLibrary().tox_options_new.async(ref.NULL, function(err, options) { var opts; - if (!err) opts = options.deref(); + if (!err) + opts = options.deref(); if (callback) { callback(err, opts); } @@ -515,7 +567,7 @@ Tox.prototype.newOptions = function (callback) { * @return {ToxOptions} Options * @todo Error handling */ -Tox.prototype.newOptionsSync = function () { +Tox.prototype.newOptionsSync = function() { var options = this.getLibrary().tox_options_new(ref.NULL); return options.deref(); }; @@ -527,12 +579,13 @@ Tox.prototype.newOptionsSync = function () { * @param {(Buffer|String)} publicKey * @param {Tox~errorCallback} [callback] */ -Tox.prototype.bootstrap = function (address, port, publicKey, callback) { +Tox.prototype.bootstrap = function(address, port, publicKey, callback) { this._performBootstrap({ - api: this.getLibrary().tox_bootstrap.async.bind(undefined, this.getHandle()), - args: [address, port, publicKey], - async: true, - callback: callback, + api : + this.getLibrary().tox_bootstrap.async.bind(undefined, this.getHandle()), + args : [ address, port, publicKey ], + async : true, + callback : callback, }); }; @@ -543,11 +596,11 @@ Tox.prototype.bootstrap = function (address, port, publicKey, callback) { * @param {(Buffer|String)} publicKey * @throws Error if tox_bootstrap errors or returns false */ -Tox.prototype.bootstrapSync = function (address, port, publicKey) { +Tox.prototype.bootstrapSync = function(address, port, publicKey) { this._performBootstrap({ - api: this.getLibrary().tox_bootstrap.bind(undefined, this.getHandle()), - args: [address, port, publicKey], - async: false, + api : this.getLibrary().tox_bootstrap.bind(undefined, this.getHandle()), + args : [ address, port, publicKey ], + async : false, }); }; @@ -558,12 +611,13 @@ Tox.prototype.bootstrapSync = function (address, port, publicKey) { * @param {(Buffer|String)} publicKey * @param {Tox~errorCallback} [callback] */ -Tox.prototype.addTCPRelay = function (address, port, publicKey, callback) { +Tox.prototype.addTCPRelay = function(address, port, publicKey, callback) { this._performBootstrap({ - api: this.getLibrary().tox_add_tcp_relay.async.bind(undefined, this.getHandle()), - args: [address, port, publicKey], - async: true, - callback: callback, + api : this.getLibrary().tox_add_tcp_relay.async.bind(undefined, + this.getHandle()), + args : [ address, port, publicKey ], + async : true, + callback : callback, }); }; @@ -574,11 +628,11 @@ Tox.prototype.addTCPRelay = function (address, port, publicKey, callback) { * @param {(Buffer|String)} publicKey * @throws Error if tox_add_tcp_relay errors or returns false */ -Tox.prototype.addTCPRelaySync = function (address, port, publicKey) { +Tox.prototype.addTCPRelaySync = function(address, port, publicKey) { this._performBootstrap({ - api: this.getLibrary().tox_add_tcp_relay.bind(undefined, this.getHandle()), - args: [address, port, publicKey], - async: false, + api : this.getLibrary().tox_add_tcp_relay.bind(undefined, this.getHandle()), + args : [ address, port, publicKey ], + async : false, }); }; @@ -586,7 +640,7 @@ Tox.prototype.addTCPRelaySync = function (address, port, publicKey) { * Asynchronous tox_iteration_interval(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.iterationInterval = function (callback) { +Tox.prototype.iterationInterval = function(callback) { if (!this._checkHandle(callback)) { return; } @@ -598,7 +652,7 @@ Tox.prototype.iterationInterval = function (callback) { * Synchronous tox_iteration_interval(3). * @return {Number} milliseconds until the next tox_iterate should occur */ -Tox.prototype.iterationIntervalSync = function () { +Tox.prototype.iterationIntervalSync = function() { this._checkHandleSync(); return this.getLibrary().tox_iteration_interval(this.getHandle()); }; @@ -607,7 +661,7 @@ Tox.prototype.iterationIntervalSync = function () { * Asynchronous tox_iterate(3). * @param {Tox~errorCallback} [callback] */ -Tox.prototype.iterate = function (callback) { +Tox.prototype.iterate = function(callback) { if (!this._checkHandle(callback)) { return; } @@ -618,7 +672,7 @@ Tox.prototype.iterate = function (callback) { /** * Synchronous tox_iterate(3). */ -Tox.prototype.iterateSync = function () { +Tox.prototype.iterateSync = function() { this._checkHandleSync(); this.getLibrary().tox_iterate(this.getHandle()); }; @@ -627,13 +681,14 @@ Tox.prototype.iterateSync = function () { * Asynchronous tox_self_get_address(3). * @param {Tox~dataCallback} [callback] */ -Tox.prototype.getAddress = function (callback) { +Tox.prototype.getAddress = function(callback) { this._performGetter({ - api: this.getLibrary().tox_self_get_address.async.bind(undefined, this.getHandle()), - format: "raw", - size: consts.TOX_FRIEND_ADDRESS_SIZE, - async: true, - callback: callback, + api : this.getLibrary().tox_self_get_address.async.bind(undefined, + this.getHandle()), + format : "raw", + size : consts.TOX_FRIEND_ADDRESS_SIZE, + async : true, + callback : callback, }); }; @@ -641,11 +696,12 @@ Tox.prototype.getAddress = function (callback) { * Synchronous tox_self_get_address(3). * @return {Buffer} address */ -Tox.prototype.getAddressSync = function () { +Tox.prototype.getAddressSync = function() { return this._performGetter({ - api: this.getLibrary().tox_self_get_address.bind(undefined, this.getHandle()), - format: "raw", - size: consts.TOX_FRIEND_ADDRESS_SIZE, + api : this.getLibrary().tox_self_get_address.bind(undefined, + this.getHandle()), + format : "raw", + size : consts.TOX_FRIEND_ADDRESS_SIZE, }); }; @@ -653,11 +709,12 @@ Tox.prototype.getAddressSync = function () { * Asynchronous tox_self_get_connection_status(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getConnectionStatus = function (callback) { +Tox.prototype.getConnectionStatus = function(callback) { this._performNumberGetter({ - api: this.getLibrary().tox_self_get_connection_status.async.bind(undefined, this.getHandle()), - async: true, - callback: callback, + api : this.getLibrary().tox_self_get_connection_status.async.bind( + undefined, this.getHandle()), + async : true, + callback : callback, }); }; @@ -665,9 +722,10 @@ Tox.prototype.getConnectionStatus = function (callback) { * Synchronous tox_self_get_connection_status(3). * @return {Number} connection status */ -Tox.prototype.getConnectionStatusSync = function () { +Tox.prototype.getConnectionStatusSync = function() { return this._performNumberGetter({ - api: this.getLibrary().tox_self_get_connection_status.bind(undefined, this.getHandle()), + api : this.getLibrary().tox_self_get_connection_status.bind( + undefined, this.getHandle()), }); }; @@ -676,20 +734,22 @@ Tox.prototype.getConnectionStatusSync = function () { * @param {Number} nospam * @param {Tox~errorCallback} [callback] */ -Tox.prototype.setNospam = function (nospam, callback) { - if (!this._checkHandle(callback)) return; - this.getLibrary().tox_self_set_nospam.async(this.getHandle(), nospam, function (err) { - if (callback) { - callback(err); - } - }); +Tox.prototype.setNospam = function(nospam, callback) { + if (!this._checkHandle(callback)) + return; + this.getLibrary().tox_self_set_nospam.async(this.getHandle(), nospam, + function(err) { + if (callback) { + callback(err); + } + }); }; /** * Synchronous tox_self_set_nospam(3). * @param {Number} nospam */ -Tox.prototype.setNospamSync = function (nospam) { +Tox.prototype.setNospamSync = function(nospam) { this._checkHandleSync(); this.getLibrary().tox_self_set_nospam(this.getHandle(), nospam); }; @@ -698,20 +758,22 @@ Tox.prototype.setNospamSync = function (nospam) { * Asynchronous tox_self_get_nospam(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getNospam = function (callback) { - if (!this._checkHandle(callback)) return; - this.getLibrary().tox_self_get_nospam.async(this.getHandle(), function (err, nospam) { - if (callback) { - callback(err, nospam); - } - }); +Tox.prototype.getNospam = function(callback) { + if (!this._checkHandle(callback)) + return; + this.getLibrary().tox_self_get_nospam.async(this.getHandle(), + function(err, nospam) { + if (callback) { + callback(err, nospam); + } + }); }; /** * Synchronous tox_self_get_nospam(3). * @return {Number} nospam */ -Tox.prototype.getNospamSync = function () { +Tox.prototype.getNospamSync = function() { this._checkHandleSync(); return this.getLibrary().tox_self_get_nospam(this.getHandle()); }; @@ -720,13 +782,14 @@ Tox.prototype.getNospamSync = function () { * Asynchronous tox_self_get_public_key(3). * @param {Tox~dataCallback} [callback] */ -Tox.prototype.getPublicKey = function (callback) { +Tox.prototype.getPublicKey = function(callback) { this._performGetter({ - api: this.getLibrary().tox_self_get_public_key.async.bind(undefined, this.getHandle()), - format: "raw", - size: consts.TOX_PUBLIC_KEY_SIZE, - async: true, - callback: callback, + api : this.getLibrary().tox_self_get_public_key.async.bind( + undefined, this.getHandle()), + format : "raw", + size : consts.TOX_PUBLIC_KEY_SIZE, + async : true, + callback : callback, }); }; @@ -734,11 +797,12 @@ Tox.prototype.getPublicKey = function (callback) { * Synchronous tox_self_get_public_key(3). * @return {Buffer} public key */ -Tox.prototype.getPublicKeySync = function () { +Tox.prototype.getPublicKeySync = function() { return this._performGetter({ - api: this.getLibrary().tox_self_get_public_key.bind(undefined, this.getHandle()), - format: "raw", - size: consts.TOX_PUBLIC_KEY_SIZE, + api : this.getLibrary().tox_self_get_public_key.bind(undefined, + this.getHandle()), + format : "raw", + size : consts.TOX_PUBLIC_KEY_SIZE, }); }; @@ -746,13 +810,14 @@ Tox.prototype.getPublicKeySync = function () { * Asynchronous tox_self_get_secret_key(3). * @param {Tox~dataCallback} [callback] */ -Tox.prototype.getSecretKey = function (callback) { +Tox.prototype.getSecretKey = function(callback) { this._performGetter({ - api: this.getLibrary().tox_self_get_secret_key.async.bind(undefined, this.getHandle()), - format: "raw", - size: consts.TOX_PUBLIC_KEY_SIZE, - async: true, - callback: callback, + api : this.getLibrary().tox_self_get_secret_key.async.bind( + undefined, this.getHandle()), + format : "raw", + size : consts.TOX_PUBLIC_KEY_SIZE, + async : true, + callback : callback, }); }; @@ -760,11 +825,12 @@ Tox.prototype.getSecretKey = function (callback) { * Synchronous tox_self_get_secret_key(3). * @return {Buffer} secret key */ -Tox.prototype.getSecretKeySync = function () { +Tox.prototype.getSecretKeySync = function() { return this._performGetter({ - api: this.getLibrary().tox_self_get_secret_key.bind(undefined, this.getHandle()), - format: "raw", - size: consts.TOX_SECRET_KEY_SIZE, + api : this.getLibrary().tox_self_get_secret_key.bind(undefined, + this.getHandle()), + format : "raw", + size : consts.TOX_SECRET_KEY_SIZE, }); }; @@ -773,13 +839,14 @@ Tox.prototype.getSecretKeySync = function () { * @param {String} name * @param {Tox~errorCallback} [callback] */ -Tox.prototype.setName = function (name, callback) { +Tox.prototype.setName = function(name, callback) { this._performSetter({ - api: this.getLibrary().tox_self_set_name.async.bind(undefined, this.getHandle()), - data: name, - error: errors.setInfo, - async: true, - callback: callback, + api : this.getLibrary().tox_self_set_name.async.bind(undefined, + this.getHandle()), + data : name, + error : errors.setInfo, + async : true, + callback : callback, }); }; @@ -787,11 +854,11 @@ Tox.prototype.setName = function (name, callback) { * Synchronous tox_self_set_name(3). * @param {String} name */ -Tox.prototype.setNameSync = function (name) { +Tox.prototype.setNameSync = function(name) { this._performSetter({ - api: this.getLibrary().tox_self_set_name.bind(undefined, this.getHandle()), - error: errors.setInfo, - data: name, + api : this.getLibrary().tox_self_set_name.bind(undefined, this.getHandle()), + error : errors.setInfo, + data : name, }); }; @@ -799,11 +866,12 @@ Tox.prototype.setNameSync = function (name) { * Asynchronous tox_self_get_name_size(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getNameSize = function (callback) { +Tox.prototype.getNameSize = function(callback) { this._performSizeGetter({ - api: this.getLibrary().tox_self_get_name_size.async.bind(undefined, this.getHandle()), - async: true, - callback: callback, + api : this.getLibrary().tox_self_get_name_size.async.bind(undefined, + this.getHandle()), + async : true, + callback : callback, }); }; @@ -811,9 +879,10 @@ Tox.prototype.getNameSize = function (callback) { * Synchronous tox_self_get_name_size(3). * @return {Number} name size */ -Tox.prototype.getNameSizeSync = function () { +Tox.prototype.getNameSizeSync = function() { return this._performSizeGetter({ - api: this.getLibrary().tox_self_get_name_size.bind(undefined, this.getHandle()), + api : this.getLibrary().tox_self_get_name_size.bind(undefined, + this.getHandle()), }); }; @@ -821,13 +890,14 @@ Tox.prototype.getNameSizeSync = function () { * Asynchronous tox_self_get_name(3). * @param {Tox~stringCallback} [callback] */ -Tox.prototype.getName = function (callback) { +Tox.prototype.getName = function(callback) { this._performGetter({ - api: this.getLibrary().tox_self_get_name.async.bind(undefined, this.getHandle()), - format: "string", - size: Tox.prototype.getNameSize.bind(this), - async: true, - callback: callback, + api : this.getLibrary().tox_self_get_name.async.bind(undefined, + this.getHandle()), + format : "string", + size : Tox.prototype.getNameSize.bind(this), + async : true, + callback : callback, }); }; @@ -835,11 +905,11 @@ Tox.prototype.getName = function (callback) { * Synchronous tox_self_get_name(3). * @return {String} name */ -Tox.prototype.getNameSync = function () { +Tox.prototype.getNameSync = function() { return this._performGetter({ - api: this.getLibrary().tox_self_get_name.bind(undefined, this.getHandle()), - format: "string", - size: Tox.prototype.getNameSizeSync.bind(this), + api : this.getLibrary().tox_self_get_name.bind(undefined, this.getHandle()), + format : "string", + size : Tox.prototype.getNameSizeSync.bind(this), }); }; @@ -848,13 +918,14 @@ Tox.prototype.getNameSync = function () { * @param {String} status_message * @param {Tox~errorCallback} [callback] */ -Tox.prototype.setStatusMessage = function (statusMessage, callback) { +Tox.prototype.setStatusMessage = function(statusMessage, callback) { this._performSetter({ - api: this.getLibrary().tox_self_set_status_message.async.bind(undefined, this.getHandle()), - data: statusMessage, - error: errors.setInfo, - async: true, - callback: callback, + api : this.getLibrary().tox_self_set_status_message.async.bind( + undefined, this.getHandle()), + data : statusMessage, + error : errors.setInfo, + async : true, + callback : callback, }); }; @@ -862,11 +933,12 @@ Tox.prototype.setStatusMessage = function (statusMessage, callback) { * Synchronous tox_self_set_status_message(3). * @param {String} status_message */ -Tox.prototype.setStatusMessageSync = function (statusMessage) { +Tox.prototype.setStatusMessageSync = function(statusMessage) { this._performSetter({ - api: this.getLibrary().tox_self_set_status_message.bind(undefined, this.getHandle()), - error: errors.setInfo, - data: statusMessage, + api : this.getLibrary().tox_self_set_status_message.bind(undefined, + this.getHandle()), + error : errors.setInfo, + data : statusMessage, }); }; @@ -874,11 +946,12 @@ Tox.prototype.setStatusMessageSync = function (statusMessage) { * Asynchronous tox_self_get_status_message_size(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getStatusMessageSize = function (callback) { +Tox.prototype.getStatusMessageSize = function(callback) { this._performSizeGetter({ - api: this.getLibrary().tox_self_get_status_message_size.async.bind(undefined, this.getHandle()), - async: true, - callback: callback, + api : this.getLibrary().tox_self_get_status_message_size.async.bind( + undefined, this.getHandle()), + async : true, + callback : callback, }); }; @@ -886,9 +959,10 @@ Tox.prototype.getStatusMessageSize = function (callback) { * Synchronous tox_self_get_status_message_size(3). * @return {Number} status_message size */ -Tox.prototype.getStatusMessageSizeSync = function () { +Tox.prototype.getStatusMessageSizeSync = function() { return this._performSizeGetter({ - api: this.getLibrary().tox_self_get_status_message_size.bind(undefined, this.getHandle()), + api : this.getLibrary().tox_self_get_status_message_size.bind( + undefined, this.getHandle()), }); }; @@ -896,13 +970,14 @@ Tox.prototype.getStatusMessageSizeSync = function () { * Asynchronous tox_self_get_status_message(3). * @param {Tox~stringCallback} [callback] */ -Tox.prototype.getStatusMessage = function (callback) { +Tox.prototype.getStatusMessage = function(callback) { this._performGetter({ - api: this.getLibrary().tox_self_get_status_message.async.bind(undefined, this.getHandle()), - format: "string", - size: Tox.prototype.getStatusMessageSize.bind(this), - async: true, - callback: callback, + api : this.getLibrary().tox_self_get_status_message.async.bind( + undefined, this.getHandle()), + format : "string", + size : Tox.prototype.getStatusMessageSize.bind(this), + async : true, + callback : callback, }); }; @@ -910,11 +985,12 @@ Tox.prototype.getStatusMessage = function (callback) { * Synchronous tox_self_get_status_message(3). * @return {String} status message */ -Tox.prototype.getStatusMessageSync = function () { +Tox.prototype.getStatusMessageSync = function() { return this._performGetter({ - api: this.getLibrary().tox_self_get_status_message.bind(undefined, this.getHandle()), - format: "string", - size: Tox.prototype.getStatusMessageSizeSync.bind(this), + api : this.getLibrary().tox_self_get_status_message.bind(undefined, + this.getHandle()), + format : "string", + size : Tox.prototype.getStatusMessageSizeSync.bind(this), }); }; @@ -923,12 +999,13 @@ Tox.prototype.getStatusMessageSync = function () { * @param {Number} status * @param {Tox~errorCallback} [callback] */ -Tox.prototype.setStatus = function (status, callback) { +Tox.prototype.setStatus = function(status, callback) { this._performNumberSetter({ - api: this.getLibrary().tox_self_set_status.async.bind(undefined, this.getHandle()), - value: status, - async: true, - callback: callback, + api : this.getLibrary().tox_self_set_status.async.bind(undefined, + this.getHandle()), + value : status, + async : true, + callback : callback, }); }; @@ -936,10 +1013,11 @@ Tox.prototype.setStatus = function (status, callback) { * Synchronous tox_self_set_status(3). * @param {Number} status */ -Tox.prototype.setStatusSync = function (status) { +Tox.prototype.setStatusSync = function(status) { this._performNumberSetter({ - api: this.getLibrary().tox_self_set_status.bind(undefined, this.getHandle()), - value: status, + api : + this.getLibrary().tox_self_set_status.bind(undefined, this.getHandle()), + value : status, }); }; @@ -947,11 +1025,12 @@ Tox.prototype.setStatusSync = function (status) { * Asynchronous tox_self_get_status(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getStatus = function (callback) { +Tox.prototype.getStatus = function(callback) { this._performNumberGetter({ - api: this.getLibrary().tox_self_get_status.async.bind(undefined, this.getHandle()), - async: true, - callback: callback, + api : this.getLibrary().tox_self_get_status.async.bind(undefined, + this.getHandle()), + async : true, + callback : callback, }); }; @@ -959,9 +1038,10 @@ Tox.prototype.getStatus = function (callback) { * Synchronous tox_self_get_status(3). * @return {Number} status */ -Tox.prototype.getStatusSync = function () { +Tox.prototype.getStatusSync = function() { return this._performNumberGetter({ - api: this.getLibrary().tox_self_get_status.bind(undefined, this.getHandle()), + api : + this.getLibrary().tox_self_get_status.bind(undefined, this.getHandle()), }); }; @@ -971,8 +1051,9 @@ Tox.prototype.getStatusSync = function () { * @param {(Buffer|String)} message * @param {Tox~numberCallback} [callback] */ -Tox.prototype.addFriend = function (address, message, callback) { - if (!this._checkHandle(callback)) return; +Tox.prototype.addFriend = function(address, message, callback) { + if (!this._checkHandle(callback)) + return; address = fromHex(address); if (_.isString(message)) { @@ -981,19 +1062,15 @@ Tox.prototype.addFriend = function (address, message, callback) { var eptr = ref.alloc(TOX_ERR_FRIEND_ADD); this.getLibrary().tox_friend_add.async( - this.getHandle(), - address, - message, - size_t(message.length), - eptr, - function (err, friend) { - var terr = errors.friendAdd(eptr.deref()); - if (!err && terr) err = terr; - if (callback) { - callback(err, friend); - } - } - ); + this.getHandle(), address, message, size_t(message.length), eptr, + function(err, friend) { + var terr = errors.friendAdd(eptr.deref()); + if (!err && terr) + err = terr; + if (callback) { + callback(err, friend); + } + }); }; /** @@ -1002,7 +1079,7 @@ Tox.prototype.addFriend = function (address, message, callback) { * @param {(Buffer|String)} message * @return {Number} friend number */ -Tox.prototype.addFriendSync = function (address, message) { +Tox.prototype.addFriendSync = function(address, message) { this._checkHandleSync(); address = fromHex(address); @@ -1011,15 +1088,11 @@ Tox.prototype.addFriendSync = function (address, message) { } var eptr = ref.alloc(TOX_ERR_FRIEND_ADD), - friend = this.getLibrary().tox_friend_add( - this.getHandle(), - address, - message, - size_t(message.length), - eptr - ), - err = errors.friendAdd(eptr.deref()); - if (err) throw err; + friend = this.getLibrary().tox_friend_add( + this.getHandle(), address, message, size_t(message.length), eptr), + err = errors.friendAdd(eptr.deref()); + if (err) + throw err; return friend; }; @@ -1028,22 +1101,20 @@ Tox.prototype.addFriendSync = function (address, message) { * @param {(Buffer|String)} publicKey * @param {Tox~numberCallback} [callback] */ -Tox.prototype.addFriendNoRequest = function (publicKey, callback) { - if (!this._checkHandle(callback)) return; +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.getHandle(), publicKey, eptr, function(err, friend) { + var terr = errors.friendAdd(eptr.deref()); + if (!err && terr) + err = terr; + if (callback) { + callback(err, friend); + } + }); }; /** @@ -1051,13 +1122,15 @@ Tox.prototype.addFriendNoRequest = function (publicKey, callback) { * @param {(Buffer|String)} publicKey * @return {Number} friend number */ -Tox.prototype.addFriendNoRequestSync = function (publicKey) { +Tox.prototype.addFriendNoRequestSync = function(publicKey) { this._checkHandleSync(); publicKey = fromHex(publicKey); var eptr = ref.alloc(TOX_ERR_FRIEND_ADD), - friend = this.getLibrary().tox_friend_add_norequest(this.getHandle(), publicKey, eptr), - err = errors.friendAdd(eptr.deref()); - if (err) throw err; + friend = this.getLibrary().tox_friend_add_norequest(this.getHandle(), + publicKey, eptr), + err = errors.friendAdd(eptr.deref()); + if (err) + throw err; return friend; }; @@ -1066,35 +1139,37 @@ Tox.prototype.addFriendNoRequestSync = function (publicKey) { * @param {Number} friend * @param {Tox~errorCallback} [callback] */ -Tox.prototype.deleteFriend = function (friend, callback) { - if (!this._checkHandle(callback)) return; +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.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); + } + }); }; /** * Synchronous tox_friend_delete(3). * @param {Number} friend */ -Tox.prototype.deleteFriendSync = function (friend) { +Tox.prototype.deleteFriendSync = function(friend) { this._checkHandle(); var eptr = ref.alloc(TOX_ERR_FRIEND_DELETE), - success = this.getLibrary().tox_friend_delete(this.getHandle(), friend, eptr); + success = + this.getLibrary().tox_friend_delete(this.getHandle(), friend, eptr); var err = errors.friendDelete(eptr.deref()); - if (err) throw err; - if (!success) throw errors.unsuccessful(); + if (err) + throw err; + if (!success) + throw errors.unsuccessful(); }; /** @@ -1102,22 +1177,20 @@ Tox.prototype.deleteFriendSync = function (friend) { * @param {(Buffer|String)} publicKey * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getFriendByPublicKey = function (publicKey, callback) { - if (!this._checkHandle(callback)) return; +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.getHandle(), publicKey, eptr, function(err, friend) { + var terr = errors.friendByPublicKey(eptr.deref()); + if (!err && terr) + err = terr; + if (callback) { + callback(err, friend); + } + }); }; /** @@ -1125,13 +1198,15 @@ Tox.prototype.getFriendByPublicKey = function (publicKey, callback) { * @param {(Buffer|String)} publicKey * @return {Number} friend number */ -Tox.prototype.getFriendByPublicKeySync = function (publicKey) { +Tox.prototype.getFriendByPublicKeySync = function(publicKey) { this._checkHandle(); publicKey = fromHex(publicKey); var eptr = ref.alloc(TOX_ERR_FRIEND_BY_PUBLIC_KEY), - friend = this.getLibrary().tox_friend_by_public_key(this.getHandle(), publicKey, eptr); + friend = this.getLibrary().tox_friend_by_public_key(this.getHandle(), + publicKey, eptr); var err = errors.friendByPublicKey(eptr.deref()); - if (err) throw err; + if (err) + throw err; return friend; }; @@ -1140,23 +1215,20 @@ Tox.prototype.getFriendByPublicKeySync = function (publicKey) { * @param {Number} friend * @param {Tox~dataCallback} [callback] */ -Tox.prototype.getFriendPublicKey = function (friend, callback) { - if (!this._checkHandle(callback)) return; +Tox.prototype.getFriendPublicKey = function(friend, callback) { + if (!this._checkHandle(callback)) + return; var eptr = ref.alloc(TOX_ERR_FRIEND_GET_PUBLIC_KEY), - buffer = Buffer.alloc(consts.TOX_PUBLIC_KEY_SIZE); + buffer = Buffer.alloc(consts.TOX_PUBLIC_KEY_SIZE); this.getLibrary().tox_friend_get_public_key.async( - this.getHandle(), - friend, - buffer, - eptr, - function (err, friend) { - var terr = errors.friendGetPublicKey(eptr.deref()); - if (!err && terr) err = terr; - if (callback) { - callback(err, buffer); - } - } - ); + this.getHandle(), friend, buffer, eptr, function(err, friend) { + var terr = errors.friendGetPublicKey(eptr.deref()); + if (!err && terr) + err = terr; + if (callback) { + callback(err, buffer); + } + }); }; /** @@ -1164,14 +1236,17 @@ Tox.prototype.getFriendPublicKey = function (friend, callback) { * @param {Number} friend * @return {Buffer} public key */ -Tox.prototype.getFriendPublicKeySync = function (friend) { +Tox.prototype.getFriendPublicKeySync = function(friend) { this._checkHandle(); var eptr = ref.alloc(TOX_ERR_FRIEND_GET_PUBLIC_KEY), - buffer = Buffer.alloc(consts.TOX_PUBLIC_KEY_SIZE), - success = this.getLibrary().tox_friend_get_public_key(this.getHandle(), friend, buffer, eptr); + buffer = Buffer.alloc(consts.TOX_PUBLIC_KEY_SIZE), + success = this.getLibrary().tox_friend_get_public_key( + this.getHandle(), friend, buffer, eptr); var err = errors.friendGetPublicKey(eptr.deref()); - if (err) throw err; - if (!success) throw errors.unsuccessful(); + if (err) + throw err; + if (!success) + throw errors.unsuccessful(); return buffer; }; @@ -1180,13 +1255,15 @@ Tox.prototype.getFriendPublicKeySync = function (friend) { * @param {Number} friend * @param {Tox~booleanCallback} [callback] */ -Tox.prototype.hasFriend = function (friend, callback) { - if (!this._checkHandle(callback)) return; - this.getLibrary().tox_friend_exists.async(this.getHandle(), friend, function (err, exists) { - if (callback) { - callback(err, exists); - } - }); +Tox.prototype.hasFriend = function(friend, callback) { + if (!this._checkHandle(callback)) + return; + this.getLibrary().tox_friend_exists.async(this.getHandle(), friend, + function(err, exists) { + if (callback) { + callback(err, exists); + } + }); }; /** @@ -1194,7 +1271,7 @@ Tox.prototype.hasFriend = function (friend, callback) { * @param {Number} friend * @return {Boolean} true if has friend, false if not */ -Tox.prototype.hasFriendSync = function (friend) { +Tox.prototype.hasFriendSync = function(friend) { this._checkHandleSync(); return this.getLibrary().tox_friend_exists(this.getHandle(), friend); }; @@ -1208,25 +1285,24 @@ Tox.prototype.hasFriendSync = function (friend) { * doubles and "considered accurate up to 15 digits" * www.w3schools.com/js/js_numbers.asp */ -Tox.prototype.getFriendLastOnline = function (friend, callback) { - if (!this._checkHandle(callback)) return; +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.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); + } + }); }; /** @@ -1235,12 +1311,14 @@ Tox.prototype.getFriendLastOnline = function (friend, callback) { * @return {Date} last online date, may be backed by NaN * @note See note for Tox#getFriendLastOnline() */ -Tox.prototype.getFriendLastOnlineSync = function (friend) { +Tox.prototype.getFriendLastOnlineSync = function(friend) { this._checkHandle(); var eptr = ref.alloc(TOX_ERR_FRIEND_GET_LAST_ONLINE), - timeval = this.getLibrary().tox_friend_get_last_online(this.getHandle(), friend, eptr); + timeval = this.getLibrary().tox_friend_get_last_online(this.getHandle(), + friend, eptr); var err = errors.friendGetLastOnline(eptr.deref()); - if (err) throw err; + if (err) + throw err; return getDateFromUInt64(timeval); }; @@ -1248,11 +1326,12 @@ Tox.prototype.getFriendLastOnlineSync = function (friend) { * Asynchronous tox_self_get_friend_list_size(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getFriendListSize = function (callback) { +Tox.prototype.getFriendListSize = function(callback) { this._performSizeGetter({ - api: this.getLibrary().tox_self_get_friend_list_size.async.bind(undefined, this.getHandle()), - async: true, - callback: callback, + api : this.getLibrary().tox_self_get_friend_list_size.async.bind( + undefined, this.getHandle()), + async : true, + callback : callback, }); }; @@ -1260,9 +1339,10 @@ Tox.prototype.getFriendListSize = function (callback) { * Synchronous tox_self_get_friend_list_size(3). * @return {Number} friend count */ -Tox.prototype.getFriendListSizeSync = function () { +Tox.prototype.getFriendListSizeSync = function() { return this._performSizeGetter({ - api: this.getLibrary().tox_self_get_friend_list_size.bind(undefined, this.getHandle()), + api : this.getLibrary().tox_self_get_friend_list_size.bind( + undefined, this.getHandle()), }); }; @@ -1272,26 +1352,27 @@ Tox.prototype.getFriendListSizeSync = function () { * @note Between getting the size and calling tox_self_get_friend_list, * we may have another friend leading to an overflow. */ -Tox.prototype.getFriendList = function (callback) { - if (!this._checkHandle(callback)) return; +Tox.prototype.getFriendList = function(callback) { + if (!this._checkHandle(callback)) + return; var _this = this; - this.getFriendListSize(function (err, size) { + this.getFriendListSize(function(err, size) { if (!err) { var arr = new RefArray("uint32")(size); - _this - .getLibrary() - .tox_self_get_friend_list.async(_this.getHandle(), arr.buffer, function (err) { - // RefArray -> Javascript Array - // @todo Make this RefArrayToArray()? - var nums = []; - if (!err) { - for (var i = 0; i < arr.length; i++) nums.push(arr[i]); - } - - if (callback) { - callback(err, nums); - } - }); + _this.getLibrary().tox_self_get_friend_list.async( + _this.getHandle(), arr.buffer, function(err) { + // RefArray -> Javascript Array + // @todo Make this RefArrayToArray()? + var nums = []; + if (!err) { + for (var i = 0; i < arr.length; i++) + nums.push(arr[i]); + } + + if (callback) { + callback(err, nums); + } + }); } else if (callback) { callback(err); } @@ -1303,15 +1384,15 @@ Tox.prototype.getFriendList = function (callback) { * @return {Number[]} array of friend numbers * @note See overflow note for Tox#getFriendList() */ -Tox.prototype.getFriendListSync = function () { +Tox.prototype.getFriendListSync = function() { this._checkHandleSync(); - var size = this.getFriendListSizeSync(), - arr = new RefArray("uint32")(size); + var size = this.getFriendListSizeSync(), arr = new RefArray("uint32")(size); this.getLibrary().tox_self_get_friend_list(this.getHandle(), arr.buffer); // RefArray -> Javascript Array var nums = []; - for (var i = 0; i < arr.length; i++) nums.push(arr[i]); + for (var i = 0; i < arr.length; i++) + nums.push(arr[i]); return nums; }; @@ -1321,12 +1402,13 @@ Tox.prototype.getFriendListSync = function () { * @param {Number} friend * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getFriendNameSize = function (friend, callback) { +Tox.prototype.getFriendNameSize = function(friend, callback) { this._performFriendNumberGetter({ - api: this.getLibrary().tox_friend_get_name_size.async.bind(undefined, this.getHandle()), - friend: friend, - async: true, - callback: callback, + api : this.getLibrary().tox_friend_get_name_size.async.bind( + undefined, this.getHandle()), + friend : friend, + async : true, + callback : callback, }); }; @@ -1335,10 +1417,11 @@ Tox.prototype.getFriendNameSize = function (friend, callback) { * @param {Number} friend * @return {Number} name size */ -Tox.prototype.getFriendNameSizeSync = function (friend) { +Tox.prototype.getFriendNameSizeSync = function(friend) { return this._performFriendNumberGetter({ - api: this.getLibrary().tox_friend_get_name_size.bind(undefined, this.getHandle()), - friend: friend, + api : this.getLibrary().tox_friend_get_name_size.bind(undefined, + this.getHandle()), + friend : friend, }); }; @@ -1347,14 +1430,15 @@ Tox.prototype.getFriendNameSizeSync = function (friend) { * @param {Number} friend * @param {Tox~stringCallback} [callback] */ -Tox.prototype.getFriendName = function (friend, callback) { +Tox.prototype.getFriendName = function(friend, callback) { this._performFriendGetter({ - api: this.getLibrary().tox_friend_get_name.async.bind(undefined, this.getHandle()), - format: "string", - friend: friend, - size: consts.TOX_MAX_NAME_LENGTH, - async: true, - callback: callback, + api : this.getLibrary().tox_friend_get_name.async.bind(undefined, + this.getHandle()), + format : "string", + friend : friend, + size : consts.TOX_MAX_NAME_LENGTH, + async : true, + callback : callback, }); }; @@ -1363,12 +1447,13 @@ Tox.prototype.getFriendName = function (friend, callback) { * @param {Number} friend * @return {String} friend name */ -Tox.prototype.getFriendNameSync = function (friend) { +Tox.prototype.getFriendNameSync = function(friend) { return this._performFriendGetter({ - api: this.getLibrary().tox_friend_get_name.bind(undefined, this.getHandle()), - format: "string", - friend: friend, - size: consts.TOX_MAX_NAME_LENGTH, + api : + this.getLibrary().tox_friend_get_name.bind(undefined, this.getHandle()), + format : "string", + friend : friend, + size : consts.TOX_MAX_NAME_LENGTH, }); }; @@ -1377,15 +1462,13 @@ Tox.prototype.getFriendNameSync = function (friend) { * @param {Number} friend * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getFriendStatusMessageSize = function (friend, callback) { +Tox.prototype.getFriendStatusMessageSize = function(friend, callback) { this._performFriendNumberGetter({ - api: this.getLibrary().tox_friend_get_status_message_size.async.bind( - undefined, - this.getHandle() - ), - friend: friend, - async: true, - callback: callback, + api : this.getLibrary().tox_friend_get_status_message_size.async.bind( + undefined, this.getHandle()), + friend : friend, + async : true, + callback : callback, }); }; @@ -1394,10 +1477,11 @@ Tox.prototype.getFriendStatusMessageSize = function (friend, callback) { * @param {Number} friend * @return {Number} status message size */ -Tox.prototype.getFriendStatusMessageSizeSync = function (friend) { +Tox.prototype.getFriendStatusMessageSizeSync = function(friend) { return this._performFriendNumberGetter({ - api: this.getLibrary().tox_friend_get_status_message_size.bind(undefined, this.getHandle()), - friend: friend, + api : this.getLibrary().tox_friend_get_status_message_size.bind( + undefined, this.getHandle()), + friend : friend, }); }; @@ -1406,14 +1490,15 @@ Tox.prototype.getFriendStatusMessageSizeSync = function (friend) { * @param {Number} friend * @param {Tox~stringCallback} [callback] */ -Tox.prototype.getFriendStatusMessage = function (friend, callback) { +Tox.prototype.getFriendStatusMessage = function(friend, callback) { this._performFriendGetter({ - api: this.getLibrary().tox_friend_get_status_message.async.bind(undefined, this.getHandle()), - format: "string", - friend: friend, - size: consts.TOX_MAX_STATUS_MESSAGE_LENGTH, - async: true, - callback: callback, + api : this.getLibrary().tox_friend_get_status_message.async.bind( + undefined, this.getHandle()), + format : "string", + friend : friend, + size : consts.TOX_MAX_STATUS_MESSAGE_LENGTH, + async : true, + callback : callback, }); }; @@ -1422,12 +1507,13 @@ Tox.prototype.getFriendStatusMessage = function (friend, callback) { * @param {Number} friend * @return {String} friend status message */ -Tox.prototype.getFriendStatusMessageSync = function (friend) { +Tox.prototype.getFriendStatusMessageSync = function(friend) { return this._performFriendGetter({ - api: this.getLibrary().tox_friend_get_status_message.bind(undefined, this.getHandle()), - format: "string", - friend: friend, - size: consts.TOX_MAX_STATUS_MESSAGE_LENGTH, + api : this.getLibrary().tox_friend_get_status_message.bind( + undefined, this.getHandle()), + format : "string", + friend : friend, + size : consts.TOX_MAX_STATUS_MESSAGE_LENGTH, }); }; @@ -1436,12 +1522,13 @@ Tox.prototype.getFriendStatusMessageSync = function (friend) { * @param {Number} friend * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getFriendStatus = function (friend, callback) { +Tox.prototype.getFriendStatus = function(friend, callback) { this._performFriendNumberGetter({ - api: this.getLibrary().tox_friend_get_status.async.bind(undefined, this.getHandle()), - friend: friend, - async: true, - callback: callback, + api : this.getLibrary().tox_friend_get_status.async.bind(undefined, + this.getHandle()), + friend : friend, + async : true, + callback : callback, }); }; @@ -1450,10 +1537,11 @@ Tox.prototype.getFriendStatus = function (friend, callback) { * @param {Number} friend * @return {Number} friend status */ -Tox.prototype.getFriendStatusSync = function (friend) { +Tox.prototype.getFriendStatusSync = function(friend) { return this._performFriendNumberGetter({ - api: this.getLibrary().tox_friend_get_status.bind(undefined, this.getHandle()), - friend: friend, + api : this.getLibrary().tox_friend_get_status.bind(undefined, + this.getHandle()), + friend : friend, }); }; @@ -1462,12 +1550,13 @@ Tox.prototype.getFriendStatusSync = function (friend) { * @param {Number} friend * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getFriendConnectionStatus = function (friend, callback) { +Tox.prototype.getFriendConnectionStatus = function(friend, callback) { this._performFriendNumberGetter({ - api: this.getLibrary().tox_friend_get_connection_status.async.bind(undefined, this.getHandle()), - friend: friend, - async: true, - callback: callback, + api : this.getLibrary().tox_friend_get_connection_status.async.bind( + undefined, this.getHandle()), + friend : friend, + async : true, + callback : callback, }); }; @@ -1476,10 +1565,11 @@ Tox.prototype.getFriendConnectionStatus = function (friend, callback) { * @param {Number} friend * @return {Number} friend status */ -Tox.prototype.getFriendConnectionStatusSync = function (friend) { +Tox.prototype.getFriendConnectionStatusSync = function(friend) { return this._performFriendNumberGetter({ - api: this.getLibrary().tox_friend_get_connection_status.bind(undefined, this.getHandle()), - friend: friend, + api : this.getLibrary().tox_friend_get_connection_status.bind( + undefined, this.getHandle()), + friend : friend, }); }; @@ -1487,11 +1577,12 @@ Tox.prototype.getFriendConnectionStatusSync = function (friend) { * Asynchronous tox_self_get_udp_port(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getUdpPort = function (callback) { +Tox.prototype.getUdpPort = function(callback) { this._performGetPort({ - api: this.getLibrary().tox_self_get_udp_port.async.bind(undefined, this.getHandle()), - async: true, - callback: callback, + api : this.getLibrary().tox_self_get_udp_port.async.bind(undefined, + this.getHandle()), + async : true, + callback : callback, }); }; @@ -1500,9 +1591,10 @@ Tox.prototype.getUdpPort = function (callback) { * @returns {Number} Port * @throws Error if TOX_ERR_GET_PORT set. */ -Tox.prototype.getUdpPortSync = function () { +Tox.prototype.getUdpPortSync = function() { return this._performGetPort({ - api: this.getLibrary().tox_self_get_udp_port.bind(undefined, this.getHandle()), + api : this.getLibrary().tox_self_get_udp_port.bind(undefined, + this.getHandle()), }); }; @@ -1510,11 +1602,12 @@ Tox.prototype.getUdpPortSync = function () { * Asynchronous tox_self_get_tcp_port(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getTcpPort = function (callback) { +Tox.prototype.getTcpPort = function(callback) { this._performGetPort({ - api: this.getLibrary().tox_self_get_tcp_port.async.bind(undefined, this.getHandle()), - async: true, - callback: callback, + api : this.getLibrary().tox_self_get_tcp_port.async.bind(undefined, + this.getHandle()), + async : true, + callback : callback, }); }; @@ -1523,9 +1616,10 @@ Tox.prototype.getTcpPort = function (callback) { * @returns {Number} Port * @throws Error if TOX_ERR_GET_PORT set. */ -Tox.prototype.getTcpPortSync = function () { +Tox.prototype.getTcpPortSync = function() { return this._performGetPort({ - api: this.getLibrary().tox_self_get_tcp_port.bind(undefined, this.getHandle()), + api : this.getLibrary().tox_self_get_tcp_port.bind(undefined, + this.getHandle()), }); }; @@ -1535,23 +1629,21 @@ Tox.prototype.getTcpPortSync = function () { * @param {Boolean} typing * @param {Tox~errorCallback} [callback] */ -Tox.prototype.setTyping = function (friend, typing, callback) { - if (!this._checkHandle(callback)) return; +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.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); + } + }); }; /** @@ -1559,14 +1651,17 @@ Tox.prototype.setTyping = function (friend, typing, callback) { * @param {Number} friend * @param {Boolean} typing */ -Tox.prototype.setTypingSync = function (friend, typing) { +Tox.prototype.setTypingSync = function(friend, typing) { this._checkHandleSync(); var eptr = ref.alloc(TOX_ERR_SET_TYPING), - success = this.getLibrary().tox_self_set_typing(this.getHandle(), friend, typing, eptr); + success = this.getLibrary().tox_self_set_typing(this.getHandle(), friend, + typing, eptr); var err = errors.setTyping(eptr.deref()); - if (err) throw err; - if (!success) throw errors.unsuccessful(); + if (err) + throw err; + if (!success) + throw errors.unsuccessful(); }; /** @@ -1576,8 +1671,9 @@ Tox.prototype.setTypingSync = function (friend, typing) { * @param {(Boolean|Number|String)} [type] - If boolean, assumed isAction * @param {Tox~numberCallback} [callback] */ -Tox.prototype.sendFriendMessage = function (friend, message, type, callback) { - if (!this._checkHandle(callback)) return; +Tox.prototype.sendFriendMessage = function(friend, message, type, callback) { + if (!this._checkHandle(callback)) + return; // If #sendFriendMessage(friend, message, callback), use default type if (arguments.length === 3 && _.isFunction(type)) { @@ -1585,27 +1681,20 @@ Tox.prototype.sendFriendMessage = function (friend, message, type, callback) { type = undefined; } - var args = this._fixSendMessageArgs(friend, message, type), - friend = args[0], - message = args[1], - type = args[2], - eptr = ref.alloc(TOX_ERR_FRIEND_SEND_MESSAGE); + var args = this._fixSendMessageArgs(friend, message, type), friend = args[0], + message = args[1], type = args[2], + eptr = ref.alloc(TOX_ERR_FRIEND_SEND_MESSAGE); this.getLibrary().tox_friend_send_message.async( - this.getHandle(), - friend, - type, - message, - message.length, - eptr, - function (err, mid) { - var terr = errors.friendSendMessage(eptr.deref()); - if (!err && terr) err = terr; - if (callback) { - callback(err, mid); - } - } - ); + this.getHandle(), friend, type, message, message.length, eptr, + function(err, mid) { + var terr = errors.friendSendMessage(eptr.deref()); + if (!err && terr) + err = terr; + if (callback) { + callback(err, mid); + } + }); }; /** @@ -1615,25 +1704,18 @@ Tox.prototype.sendFriendMessage = function (friend, message, type, callback) { * @param {(Boolean|Number|String)} [type] - If boolean, assumed isAction * @return {Number} message id */ -Tox.prototype.sendFriendMessageSync = function (friend, message, type) { +Tox.prototype.sendFriendMessageSync = function(friend, message, type) { this._checkHandleSync(); - var args = this._fixSendMessageArgs(friend, message, type), - friend = args[0], - message = args[1], - type = args[2], - eptr = ref.alloc(TOX_ERR_FRIEND_SEND_MESSAGE); + var args = this._fixSendMessageArgs(friend, message, type), friend = args[0], + message = args[1], type = args[2], + eptr = ref.alloc(TOX_ERR_FRIEND_SEND_MESSAGE); var mid = this.getLibrary().tox_friend_send_message( - this.getHandle(), - friend, - type, - message, - message.length, - eptr - ); + this.getHandle(), friend, type, message, message.length, eptr); var err = errors.friendSendMessage(eptr.deref()); - if (err) throw err; + if (err) + throw err; return mid; }; @@ -1642,15 +1724,18 @@ Tox.prototype.sendFriendMessageSync = function (friend, message, type) { * @param {(Buffer|String)} data * @param {Tox~dataCallback} [callback] */ -Tox.prototype.hash = function (data, callback) { - if (_.isString(data)) data = Buffer.from(data); +Tox.prototype.hash = function(data, callback) { + if (_.isString(data)) + data = Buffer.from(data); var hash = Buffer.alloc(consts.TOX_HASH_LENGTH); - this.getLibrary().tox_hash.async(hash, data, data.length, function (err, success) { - if (!err && !success) err = errors.unsuccessful(); - if (callback) { - callback(err, hash); - } - }); + this.getLibrary().tox_hash.async(hash, data, data.length, + function(err, success) { + if (!err && !success) + err = errors.unsuccessful(); + if (callback) { + callback(err, hash); + } + }); }; /** @@ -1658,11 +1743,13 @@ Tox.prototype.hash = function (data, callback) { * @param {(Buffer|String)} data * @return {Buffer} hash */ -Tox.prototype.hashSync = function (data) { - if (_.isString(data)) data = Buffer.from(data); +Tox.prototype.hashSync = function(data) { + if (_.isString(data)) + data = Buffer.from(data); var hash = Buffer.alloc(consts.TOX_HASH_LENGTH), - success = this.getLibrary().tox_hash(hash, data, data.length); - if (!success) throw errors.unsuccessful(); + success = this.getLibrary().tox_hash(hash, data, data.length); + if (!success) + throw errors.unsuccessful(); return hash; }; @@ -1673,25 +1760,23 @@ Tox.prototype.hashSync = function (data) { * @param {Number} control * @param {Tox~errorCallback} [callback] */ -Tox.prototype.controlFile = function (friendnum, filenum, control, callback) { - if (!this._checkHandle(callback)) return; +Tox.prototype.controlFile = function(friendnum, filenum, control, callback) { + if (!this._checkHandle(callback)) + return; control = this._fixFileControl(control); var eptr = ref.alloc(TOX_ERR_FILE_CONTROL); this.getLibrary().tox_file_control.async( - this.getHandle(), - friendnum, - filenum, - control, - eptr, - function (err, success) { - var terr = errors.fileControl(eptr.deref()); - if (!err && terr) err = terr; - if (!err && !success) err = errors.unsuccessful(); - if (callback) { - callback(err); - } - } - ); + this.getHandle(), friendnum, filenum, control, eptr, + function(err, success) { + var terr = errors.fileControl(eptr.deref()); + if (!err && terr) + err = terr; + if (!err && !success) + err = errors.unsuccessful(); + if (callback) { + callback(err); + } + }); }; /** @@ -1700,20 +1785,17 @@ Tox.prototype.controlFile = function (friendnum, filenum, control, callback) { * @param {Number} filenum * @param {Number} control */ -Tox.prototype.controlFileSync = function (friendnum, filenum, control) { +Tox.prototype.controlFileSync = function(friendnum, filenum, control) { this._checkHandleSync(); control = this._fixFileControl(control); var eptr = ref.alloc(TOX_ERR_FILE_CONTROL), - success = this.getLibrary().tox_file_control( - this.getHandle(), - friendnum, - filenum, - control, - eptr - ); + success = this.getLibrary().tox_file_control(this.getHandle(), friendnum, + filenum, control, eptr); var err = errors.fileControl(eptr.deref()); - if (err) throw err; - if (!success) throw errors.unsuccessful(); + if (err) + throw err; + if (!success) + throw errors.unsuccessful(); }; /** @@ -1723,24 +1805,22 @@ Tox.prototype.controlFileSync = function (friendnum, filenum, control) { * @param {Number} position * @param {Tox~errorCallback} [callback] */ -Tox.prototype.seekFile = function (friendnum, filenum, position, callback) { - if (!this._checkHandle(callback)) return; +Tox.prototype.seekFile = function(friendnum, filenum, position, callback) { + if (!this._checkHandle(callback)) + return; var eptr = ref.alloc(TOX_ERR_FILE_SEEK); - this.getLibrary().tox_file_seek.async( - this.getHandle(), - friendnum, - filenum, - position, - eptr, - function (err, success) { - var terr = errors.fileSeek(eptr.deref()); - if (!err && terr) err = terr; - if (!err && !success) err = errors.unsuccessful(); - if (callback) { - callback(err); - } - } - ); + this.getLibrary().tox_file_seek.async(this.getHandle(), friendnum, filenum, + position, eptr, function(err, success) { + var terr = + errors.fileSeek(eptr.deref()); + if (!err && terr) + err = terr; + if (!err && !success) + err = errors.unsuccessful(); + if (callback) { + callback(err); + } + }); }; /** @@ -1749,13 +1829,16 @@ Tox.prototype.seekFile = function (friendnum, filenum, position, callback) { * @param {Number} filenum * @param {Number} position */ -Tox.prototype.seekFileSync = function (friendnum, filenum, position) { +Tox.prototype.seekFileSync = function(friendnum, filenum, position) { this._checkHandleSync(); var eptr = ref.alloc(TOX_ERR_FILE_SEEK), - success = this.getLibrary().tox_file_seek(this.getHandle(), friendnum, filenum, position, eptr); + success = this.getLibrary().tox_file_seek(this.getHandle(), friendnum, + filenum, position, eptr); var err = errors.fileSeek(eptr.deref()); - if (err) throw err; - if (!success) throw errors.unsuccessful(); + if (err) + throw err; + if (!success) + throw errors.unsuccessful(); }; /** @@ -1764,25 +1847,23 @@ Tox.prototype.seekFileSync = function (friendnum, filenum, position) { * @param {Number} filenum * @param {Tox~dataCallback} [callback] */ -Tox.prototype.getFileId = function (friendnum, filenum, callback) { - if (!this._checkHandle(callback)) return; +Tox.prototype.getFileId = function(friendnum, filenum, callback) { + if (!this._checkHandle(callback)) + return; var eptr = ref.alloc(TOX_ERR_FILE_GET), - fileid = Buffer.alloc(consts.TOX_FILE_ID_LENGTH); + fileid = Buffer.alloc(consts.TOX_FILE_ID_LENGTH); this.getLibrary().tox_file_get_file_id.async( - this.getHandle(), - friendnum, - filenum, - fileid, - eptr, - function (err, success) { - var terr = errors.fileGet(eptr.deref()); - if (!err && terr) err = terr; - if (!err && !success) err = errors.unsuccessful(); - if (callback) { - callback(err, fileid); - } - } - ); + this.getHandle(), friendnum, filenum, fileid, eptr, + function(err, success) { + var terr = errors.fileGet(eptr.deref()); + if (!err && terr) + err = terr; + if (!err && !success) + err = errors.unsuccessful(); + if (callback) { + callback(err, fileid); + } + }); }; /** @@ -1791,20 +1872,17 @@ Tox.prototype.getFileId = function (friendnum, filenum, callback) { * @param {Number} filenum * @return {Buffer} file id */ -Tox.prototype.getFileIdSync = function (friendnum, filenum) { +Tox.prototype.getFileIdSync = function(friendnum, filenum) { this._checkHandleSync(); var eptr = ref.alloc(TOX_ERR_FILE_GET), - fileid = Buffer.alloc(consts.TOX_FILE_ID_LENGTH), - success = this.getLibrary().tox_file_get_file_id( - this.getHandle(), - friendnum, - filenum, - fileid, - eptr - ); + fileid = Buffer.alloc(consts.TOX_FILE_ID_LENGTH), + success = this.getLibrary().tox_file_get_file_id( + this.getHandle(), friendnum, filenum, fileid, eptr); var err = errors.fileGet(eptr.deref()); - if (err) throw err; - if (!success) throw errors.unsuccessful(); + if (err) + throw err; + if (!success) + throw errors.unsuccessful(); return fileid; }; @@ -1817,34 +1895,30 @@ Tox.prototype.getFileIdSync = function (friendnum, filenum) { * @param {Buffer} [fileid] * @param {Tox~numberCallback} [callback] */ -Tox.prototype.sendFile = function (friendnum, kind, filename, size, fileid, callback) { - if (!this._checkHandle(callback)) return; +Tox.prototype.sendFile = function(friendnum, kind, filename, size, fileid, + callback) { + if (!this._checkHandle(callback)) + return; if (arguments.length === 5 && _.isFunction(fileid)) { callback = fileid; fileid = undefined; } - if (!fileid) fileid = ref.NULL; + if (!fileid) + fileid = ref.NULL; if (_.isString(filename)) { filename = Buffer.from(filename); } var eptr = ref.alloc(TOX_ERR_FILE_SEND); this.getLibrary().tox_file_send.async( - this.getHandle(), - friendnum, - kind, - size, - fileid, - filename, - filename.length, - eptr, - function (err, filenum) { - var terr = errors.fileSend(eptr.deref()); - if (!err && terr) err = terr; - if (callback) { - callback(err, filenum); - } - } - ); + this.getHandle(), friendnum, kind, size, fileid, filename, + filename.length, eptr, function(err, filenum) { + var terr = errors.fileSend(eptr.deref()); + if (!err && terr) + err = terr; + if (callback) { + callback(err, filenum); + } + }); }; /** @@ -1856,25 +1930,20 @@ Tox.prototype.sendFile = function (friendnum, kind, filename, size, fileid, call * @param {Buffer} [fileid] * @return {Number} file number */ -Tox.prototype.sendFileSync = function (friendnum, kind, filename, size, fileid) { +Tox.prototype.sendFileSync = function(friendnum, kind, filename, size, fileid) { this._checkHandleSync(); - if (!fileid) fileid = ref.NULL; + if (!fileid) + fileid = ref.NULL; if (_.isString(filename)) { filename = Buffer.from(filename); } var eptr = ref.alloc(TOX_ERR_FILE_SEND), - filenum = this.getLibrary().tox_file_send( - this.getHandle(), - friendnum, - kind, - size, - fileid, - filename, - filename.length, - eptr - ); + filenum = this.getLibrary().tox_file_send(this.getHandle(), friendnum, + kind, size, fileid, filename, + filename.length, eptr); var err = errors.fileSend(eptr.deref()); - if (err) throw err; + if (err) + throw err; return filenum; }; @@ -1886,26 +1955,23 @@ Tox.prototype.sendFileSync = function (friendnum, kind, filename, size, fileid) * @param {Buffer} data * @param {Tox~errorCallback} [callback] */ -Tox.prototype.sendFileChunk = function (friendnum, filenum, position, data, callback) { - if (!this._checkHandle(callback)) return; +Tox.prototype.sendFileChunk = function(friendnum, filenum, position, data, + callback) { + if (!this._checkHandle(callback)) + return; var eptr = ref.alloc(TOX_ERR_FILE_SEND_CHUNK); this.getLibrary().tox_file_send_chunk.async( - this.getHandle(), - friendnum, - filenum, - position, - data, - data.length, - eptr, - function (err, success) { - var terr = errors.fileSendChunk(eptr.deref()); - if (!err && terr) err = terr; - if (!err && !success) err = errors.unsuccessful(); - if (callback) { - callback(err); - } - } - ); + this.getHandle(), friendnum, filenum, position, data, data.length, eptr, + function(err, success) { + var terr = errors.fileSendChunk(eptr.deref()); + if (!err && terr) + err = terr; + if (!err && !success) + err = errors.unsuccessful(); + if (callback) { + callback(err); + } + }); }; /** @@ -1915,21 +1981,17 @@ Tox.prototype.sendFileChunk = function (friendnum, filenum, position, data, call * @param {Number} position * @param {Buffer} data */ -Tox.prototype.sendFileChunkSync = function (friendnum, filenum, position, data) { +Tox.prototype.sendFileChunkSync = function(friendnum, filenum, position, data) { this._checkHandleSync(); var eptr = ref.alloc(TOX_ERR_FILE_SEND_CHUNK), - success = this.getLibrary().tox_file_send_chunk( - this.getHandle(), - friendnum, - filenum, - position, - data, - data.length, - eptr - ); + success = this.getLibrary().tox_file_send_chunk( + this.getHandle(), friendnum, filenum, position, data, data.length, + eptr); var err = errors.fileSendChunk(eptr.deref()); - if (err) throw err; - if (!success) throw errors.unsuccessful(); + if (err) + throw err; + if (!success) + throw errors.unsuccessful(); }; /** @@ -1939,7 +2001,7 @@ Tox.prototype.sendFileChunkSync = function (friendnum, filenum, position, data) * @param {Buffer} data * @param {Tox~errorCallback} [callback] */ -Tox.prototype.sendLosslessPacket = function (friendnum, id, data, callback) { +Tox.prototype.sendLosslessPacket = function(friendnum, id, data, callback) { if (_.isNumber(id)) { data = this._fixPacketBuffer(id, data); } else { @@ -1948,11 +2010,12 @@ Tox.prototype.sendLosslessPacket = function (friendnum, id, data, callback) { } this._performSendPacket({ - api: this.getLibrary().tox_friend_send_lossless_packet.async.bind(undefined, this.getHandle()), - data: data, - friend: friendnum, - async: true, - callback: callback, + api : this.getLibrary().tox_friend_send_lossless_packet.async.bind( + undefined, this.getHandle()), + data : data, + friend : friendnum, + async : true, + callback : callback, }); }; @@ -1964,7 +2027,7 @@ Tox.prototype.sendLosslessPacket = function (friendnum, id, data, callback) { * @throws Error if TOX_ERR_FRIEND_CUSTOM_PACKET set * @throws Error if tox_friend_send_lossless_packet returns false */ -Tox.prototype.sendLosslessPacketSync = function (friendnum, id, data) { +Tox.prototype.sendLosslessPacketSync = function(friendnum, id, data) { if (_.isNumber(id)) { data = this._fixPacketBuffer(id, data); } else { @@ -1972,9 +2035,10 @@ Tox.prototype.sendLosslessPacketSync = function (friendnum, id, data) { } this._performSendPacket({ - api: this.getLibrary().tox_friend_send_lossless_packet.bind(undefined, this.getHandle()), - data: data, - friend: friendnum, + api : this.getLibrary().tox_friend_send_lossless_packet.bind( + undefined, this.getHandle()), + data : data, + friend : friendnum, }); }; @@ -1986,7 +2050,7 @@ Tox.prototype.sendLosslessPacketSync = function (friendnum, id, data) { * @param {Buffer} data * @param {Tox~errorCallback} [callback] */ -Tox.prototype.sendLossyPacket = function (friendnum, data, callback) { +Tox.prototype.sendLossyPacket = function(friendnum, data, callback) { if (_.isNumber(id)) { data = this._fixPacketBuffer(id, data); } else { @@ -1995,11 +2059,12 @@ Tox.prototype.sendLossyPacket = function (friendnum, data, callback) { } this._performSendPacket({ - api: this.getLibrary().tox_friend_send_lossy_packet.async.bind(undefined, this.getHandle()), - data: data, - friend: friendnum, - async: true, - callback: callback, + api : this.getLibrary().tox_friend_send_lossy_packet.async.bind( + undefined, this.getHandle()), + data : data, + friend : friendnum, + async : true, + callback : callback, }); }; @@ -2012,7 +2077,7 @@ Tox.prototype.sendLossyPacket = function (friendnum, data, callback) { * @throws Error if TOX_ERR_FRIEND_CUSTOM_PACKET set * @throws Error if tox_friend_send_lossy_packet returns false */ -Tox.prototype.sendLossyPacketSync = function (friendnum, id, data) { +Tox.prototype.sendLossyPacketSync = function(friendnum, id, data) { if (_.isNumber(id)) { data = this._fixPacketBuffer(id, data); } else { @@ -2020,9 +2085,10 @@ Tox.prototype.sendLossyPacketSync = function (friendnum, id, data) { } this._performSendPacket({ - api: this.getLibrary().tox_friend_send_lossy_packet.bind(undefined, this.getHandle()), - data: data, - friend: friendnum, + api : this.getLibrary().tox_friend_send_lossy_packet.bind(undefined, + this.getHandle()), + data : data, + friend : friendnum, }); }; @@ -2030,13 +2096,13 @@ Tox.prototype.sendLossyPacketSync = function (friendnum, id, data) { * Asynchronous tox_kill(3). Will also set handle to undefined. * @param {Tox~errorCallback} [callback] */ -Tox.prototype.kill = function (callback) { +Tox.prototype.kill = function(callback) { if (!this._checkHandle(callback)) { return; } var _this = this; - this.getLibrary().tox_kill.async(this.getHandle(), function (err) { + this.getLibrary().tox_kill.async(this.getHandle(), function(err) { if (!err) { _this._handle = undefined; } @@ -2050,7 +2116,7 @@ Tox.prototype.kill = function (callback) { /** * Synchronous tox_kill(3). Will also set handle to undefined. */ -Tox.prototype.killSync = function () { +Tox.prototype.killSync = function() { this._checkHandleSync(); this.getLibrary().tox_kill(this.getHandle()); this._handle = undefined; @@ -2060,11 +2126,12 @@ Tox.prototype.killSync = function () { * Asynchronous tox_get_savedata_size(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getSavedataSize = function (callback) { +Tox.prototype.getSavedataSize = function(callback) { this._performSizeGetter({ - api: this.getLibrary().tox_get_savedata_size.async.bind(undefined, this.getHandle()), - async: true, - callback: callback, + api : this.getLibrary().tox_get_savedata_size.async.bind(undefined, + this.getHandle()), + async : true, + callback : callback, }); }; @@ -2072,9 +2139,10 @@ Tox.prototype.getSavedataSize = function (callback) { * Synchronous tox_get_savedata_size(3). * @return {Number} savedata size */ -Tox.prototype.getSavedataSizeSync = function (callback) { +Tox.prototype.getSavedataSizeSync = function(callback) { return this._performSizeGetter({ - api: this.getLibrary().tox_get_savedata_size.bind(undefined, this.getHandle()), + api : this.getLibrary().tox_get_savedata_size.bind(undefined, + this.getHandle()), }); }; @@ -2082,13 +2150,14 @@ Tox.prototype.getSavedataSizeSync = function (callback) { * Asynchronous tox_get_savedata(3). * @param {Tox~dataCallback} [callback] */ -Tox.prototype.getSavedata = function (callback) { +Tox.prototype.getSavedata = function(callback) { this._performGetter({ - api: this.getLibrary().tox_get_savedata.async.bind(undefined, this.getHandle()), - format: "raw", - size: Tox.prototype.getSavedataSize.bind(this), - async: true, - callback: callback, + api : this.getLibrary().tox_get_savedata.async.bind(undefined, + this.getHandle()), + format : "raw", + size : Tox.prototype.getSavedataSize.bind(this), + async : true, + callback : callback, }); }; @@ -2096,11 +2165,11 @@ Tox.prototype.getSavedata = function (callback) { * Synchronous tox_get_savedata(3). * @return {Buffer} savedata */ -Tox.prototype.getSavedataSync = function () { +Tox.prototype.getSavedataSync = function() { return this._performGetter({ - api: this.getLibrary().tox_get_savedata.bind(undefined, this.getHandle()), - format: "raw", - size: Tox.prototype.getSavedataSizeSync.bind(this), + api : this.getLibrary().tox_get_savedata.bind(undefined, this.getHandle()), + format : "raw", + size : Tox.prototype.getSavedataSizeSync.bind(this), }); }; @@ -2113,46 +2182,37 @@ Tox.prototype.getSavedataSync = function () { * if any. * @return {ToxEncryptSave} Crypto handler */ -Tox.prototype.crypto = function () { - return this._crypto; -}; +Tox.prototype.crypto = function() { return this._crypto; }; /** * Get the handle object. * @return {Object} */ -Tox.prototype.getHandle = function () { - return this._handle; -}; +Tox.prototype.getHandle = function() { return this._handle; }; /** * Whether or not this Tox instance has a crypto handler. * @return {Boolean} true if it has a crypto handler, false if not */ -Tox.prototype.hasCrypto = function () { - return this._crypto instanceof ToxEncryptSave; -}; +Tox.prototype.hasCrypto = + function() { return this._crypto instanceof ToxEncryptSave; }; /** * Whether or not this Tox instance has a handle. * @return {Boolean} true if handle, false if none */ -Tox.prototype.hasHandle = function () { - return !!this.getHandle(); -}; +Tox.prototype.hasHandle = function() { return !!this.getHandle(); }; /** * Get the internal Library instance. * @return {ffi.Library} */ -Tox.prototype.getLibrary = function () { - return this._library; -}; +Tox.prototype.getLibrary = function() { return this._library; }; /** * Frees the ToxOptions and calls tox_kill synchronously. */ -Tox.prototype.free = function () { +Tox.prototype.free = function() { this.freeOptionsSync(this._options); this._options = undefined; this.killSync(); @@ -2162,33 +2222,33 @@ Tox.prototype.free = function () { * Get the event emitter. * @return {EventEmitter} emitter */ -Tox.prototype.getEmitter = function () { - return this._emitter; -}; +Tox.prototype.getEmitter = function() { return this._emitter; }; /** * Get the ToxOptions as an object. * @return {Object} object */ -Tox.prototype.getOptions = function () { +Tox.prototype.getOptions = function() { var options = this._options; var proxyAddress = undefined; if (ref.address(options.proxy_address) !== 0) { - proxyAddress = ref.reinterpretUntilZeros(options.proxy_address, ref.types.char.size).toString(); + proxyAddress = + ref.reinterpretUntilZeros(options.proxy_address, ref.types.char.size) + .toString(); } return { - ipv6_enabled: options.ipv6_enabled, - udp_enabled: options.udp_enabled, - proxy_type: options.proxy_type, - proxy_address: proxyAddress, - proxy_port: options.proxy_port, - start_port: options.start_port, - end_port: options.end_port, - savedata_type: options.savedata_type, - savedata_data: ref.address(options.savedata_data), - savedata_length: options.savedata_length, + ipv6_enabled : options.ipv6_enabled, + udp_enabled : options.udp_enabled, + proxy_type : options.proxy_type, + proxy_address : proxyAddress, + proxy_port : options.proxy_port, + start_port : options.start_port, + end_port : options.end_port, + savedata_type : options.savedata_type, + savedata_data : ref.address(options.savedata_data), + savedata_length : options.savedata_length, }; }; @@ -2196,15 +2256,13 @@ Tox.prototype.getOptions = function () { * Check whether or not an iterateSync loop is running. * @return {Boolean} true if loop running, false if not */ -Tox.prototype.isStarted = function () { - return !!this._interval; -}; +Tox.prototype.isStarted = function() { return !!this._interval; }; /** * Checks if listening on a tcp port. * @return {Boolean} true if tcp, false if not */ -Tox.prototype.isTcp = function () { +Tox.prototype.isTcp = function() { try { this.getTcpPortSync(); return true; @@ -2217,7 +2275,7 @@ Tox.prototype.isTcp = function () { * Checks if listening on a udp port. * @return {Boolean} true if udp, false if not */ -Tox.prototype.isUdp = function () { +Tox.prototype.isUdp = function() { try { this.getUdpPortSync(); return true; @@ -2229,27 +2287,26 @@ Tox.prototype.isUdp = function () { /** * Wrapper method for _emitter.removeListener. */ -Tox.prototype.off = function () { +Tox.prototype.off = function() { this._emitter.removeListener.apply(this._emitter, arguments); }; /** * Wrapper method for _emitter.on. */ -Tox.prototype.on = function () { - this._emitter.on.apply(this._emitter, arguments); -}; +Tox.prototype.on = + function() { this._emitter.on.apply(this._emitter, arguments); }; /** * Asynchronously save state to a tox file. * @param {String} filepath * @param {Tox~errorCallback} [callback] */ -Tox.prototype.saveToFile = function (filepath, callback) { - this.getSavedata(function (err, buffer) { +Tox.prototype.saveToFile = function(filepath, callback) { + this.getSavedata(function(err, buffer) { if (!err) { // Using hex number because "grunt jsdoc" doesn't understand octal. - fs.writeFile(filepath, buffer, { mode: 0x180 /* 0600 */ }, callback); + fs.writeFile(filepath, buffer, {mode : 0x180 /* 0600 */}, callback); } else if (callback) { callback(err); } @@ -2260,10 +2317,10 @@ Tox.prototype.saveToFile = function (filepath, callback) { * Synchronously save state to a tox file. * @param {String} filepath */ -Tox.prototype.saveToFileSync = function (filepath) { +Tox.prototype.saveToFileSync = function(filepath) { // Using hex number because "grunt jsdoc" doesn't understand octal. fs.writeFileSync(filepath, this.getSavedataSync(), { - mode: 0x180 /* 0600 */, + mode : 0x180 /* 0600 */, }); }; @@ -2273,9 +2330,10 @@ Tox.prototype.saveToFileSync = function (filepath) { * @todo Maybe do one iterateSync(), then iterationIntervalSync(), and use that * value as "wait"? */ -Tox.prototype.start = function (wait) { +Tox.prototype.start = function(wait) { if (!this.isStarted()) { - if (isNaN(wait) || wait <= 0) wait = 40; // Default milliseconds to wait + if (isNaN(wait) || wait <= 0) + wait = 40; // Default milliseconds to wait this._interval = setInterval(Tox.prototype.iterateSync.bind(this), wait); } }; @@ -2283,7 +2341,7 @@ Tox.prototype.start = function (wait) { /** * Stop the iterateSync loop if there is one running. */ -Tox.prototype.stop = function () { +Tox.prototype.stop = function() { if (this._interval) { clearInterval(this._interval); this._interval = undefined; @@ -2293,22 +2351,20 @@ Tox.prototype.stop = function () { /** * Asynchronously get the address as a hex string. */ -Tox.prototype.getAddressHex = function (callback) { - util.hexify(this.getAddress.bind(this), callback); -}; +Tox.prototype.getAddressHex = function( + callback) { util.hexify(this.getAddress.bind(this), callback); }; /** * Synchronously get the address as a hex string. * @return {String} Address hex string */ -Tox.prototype.getAddressHexSync = function () { - return util.hexifySync(this.getAddressSync.bind(this)); -}; +Tox.prototype.getAddressHexSync = + function() { return util.hexifySync(this.getAddressSync.bind(this)); }; /** * Asynchronously get the public key of a friend as a hex string. */ -Tox.prototype.getFriendPublicKeyHex = function (friend, callback) { +Tox.prototype.getFriendPublicKeyHex = function(friend, callback) { util.hexify(this.getFriendPublicKey.bind(this, friend), callback); }; @@ -2316,39 +2372,35 @@ Tox.prototype.getFriendPublicKeyHex = function (friend, callback) { * Synchronously get the public key of a friend as a hex string. * @return {String} Friend public key hex string */ -Tox.prototype.getFriendPublicKeyHexSync = function (friend) { +Tox.prototype.getFriendPublicKeyHexSync = function(friend) { return util.hexifySync(this.getFriendPublicKeySync.bind(this, friend)); }; /** * Asynchronously get the public key as a hex string. */ -Tox.prototype.getPublicKeyHex = function (callback) { - util.hexify(this.getPublicKey.bind(this), callback); -}; +Tox.prototype.getPublicKeyHex = function( + callback) { util.hexify(this.getPublicKey.bind(this), callback); }; /** * Synchronously get the public key as a hex string. * @return {String} Public key hex string */ -Tox.prototype.getPublicKeyHexSync = function () { - return util.hexifySync(this.getPublicKeySync.bind(this)); -}; +Tox.prototype.getPublicKeyHexSync = + function() { return util.hexifySync(this.getPublicKeySync.bind(this)); }; /** * Asynchronously get the secret key as a hex string. */ -Tox.prototype.getSecretKeyHex = function (callback) { - util.hexify(this.getSecretKey.bind(this), callback); -}; +Tox.prototype.getSecretKeyHex = function( + callback) { util.hexify(this.getSecretKey.bind(this), callback); }; /** * Synchronously get the secret key as a hex string. * @return {String} Secret key hex string */ -Tox.prototype.getSecretKeyHexSync = function () { - return util.hexifySync(this.getSecretKeySync.bind(this)); -}; +Tox.prototype.getSecretKeyHexSync = + function() { return util.hexifySync(this.getSecretKeySync.bind(this)); }; ////////////////////////// //> Private helper methods @@ -2357,10 +2409,11 @@ 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) { +Tox.prototype._checkHandle = function(callback) { if (!this.hasHandle()) { var err = new Error("No toxcore handle"); err.code = "NO_HANDLE"; @@ -2381,7 +2434,7 @@ Tox.prototype._checkHandle = function (callback) { * @private * @throws Error if no handle */ -Tox.prototype._checkHandleSync = function () { +Tox.prototype._checkHandleSync = function() { if (!this.hasHandle()) { var err = new Error("No toxcore handle"); err.code = "NO_HANDLE"; @@ -2398,22 +2451,16 @@ Tox.prototype._checkHandleSync = function () { * @param {Object} opts * @return {ToxOptions} Options */ -Tox.prototype._createToxOptions = function (opts) { - var toxopts = this.newOptionsSync(), - ipv6 = opts["ipv6"], - udp = opts["udp"], - startPort = opts["startPort"], - endPort = opts["endPort"], - data = opts["data"], - pass = opts["pass"]; +Tox.prototype._createToxOptions = function(opts) { + var toxopts = this.newOptionsSync(), ipv6 = opts["ipv6"], udp = opts["udp"], + startPort = opts["startPort"], endPort = opts["endPort"], + data = opts["data"], pass = opts["pass"]; // If pass is a string or Buffer, have pass be a function that returns // the string or Buffer if (_.isString(pass) || Buffer.isBuffer(pass)) { var passData = pass; - pass = function () { - return passData; - }; + pass = function() { return passData; }; } // If "data" is a string, assume filepath to read data from @@ -2422,7 +2469,8 @@ Tox.prototype._createToxOptions = function (opts) { } if (data) { - if (this.hasCrypto() && _.isFunction(pass) && this.crypto().isDataEncryptedSync(data)) { + if (this.hasCrypto() && _.isFunction(pass) && + this.crypto().isDataEncryptedSync(data)) { var passphrase = pass(); data = this.crypto().decryptSync(data, passphrase); } @@ -2468,42 +2516,43 @@ Tox.prototype._createToxOptions = function (opts) { * Wrapper method for _emitter.emit. * @private */ -Tox.prototype._emit = function () { - this._emitter.emit.apply(this._emitter, arguments); -}; +Tox.prototype._emit = + function() { this._emitter.emit.apply(this._emitter, arguments); }; /** * Fix arguments passed to bootstrap functions. * @private */ -Tox.prototype._fixBootstrapArgs = function (address, port, publicKey) { +Tox.prototype._fixBootstrapArgs = function(address, port, publicKey) { address = Buffer.from(address + "\0"); if (_.isString(publicKey)) { publicKey = Buffer.from(publicKey, "hex"); } - return [address, port, publicKey]; + return [ address, port, publicKey ]; }; /** * Fix arguments passed to send-message functions. * @private */ -Tox.prototype._fixSendMessageArgs = function (to, message, type) { +Tox.prototype._fixSendMessageArgs = function(to, message, type) { if (_.isString(message)) { message = Buffer.from(message); } if (_.isBoolean(type)) { - type = type ? consts.TOX_MESSAGE_TYPE_ACTION : consts.TOX_MESSAGE_TYPE_NORMAL; + type = + type ? consts.TOX_MESSAGE_TYPE_ACTION : consts.TOX_MESSAGE_TYPE_NORMAL; } else if (_.isString(type)) { - type = /^action$/i.test(type) ? consts.TOX_MESSAGE_TYPE_ACTION : consts.TOX_MESSAGE_TYPE_NORMAL; + type = /^action$/i.test(type) ? consts.TOX_MESSAGE_TYPE_ACTION + : consts.TOX_MESSAGE_TYPE_NORMAL; } else if (!_.isNumber(type)) { type = consts.TOX_MESSAGE_TYPE_NORMAL; } - return [to, message, type]; + return [ to, message, type ]; }; /** @@ -2513,7 +2562,7 @@ Tox.prototype._fixSendMessageArgs = function (to, message, type) { * @param {(Number|String)} control * @return {Number} control value */ -Tox.prototype._fixFileControl = function (control) { +Tox.prototype._fixFileControl = function(control) { if (_.isString(control)) { if (/^resume$/i.test(control)) { return consts.TOX_FILE_CONTROL_RESUME; @@ -2527,26 +2576,28 @@ 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 - return Buffer.concat([Buffer.from([160]), data]); +Tox.prototype._fixSendLosslessPacket = function(data) { + // 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 */ -Tox.prototype._fixPacketBuffer = function (id, data) { - return Buffer.concat([Buffer.from([id]), data]); +Tox.prototype._fixPacketBuffer = function(id, data) { + return Buffer.concat([ Buffer.from([ id ]), data ]); }; /** @@ -2554,7 +2605,7 @@ Tox.prototype._fixPacketBuffer = function (id, data) { * @param {Object} opts - Tox constructor options object * @private */ -Tox.prototype._initCrypto = function (opts) { +Tox.prototype._initCrypto = function(opts) { var crypto = opts["crypto"]; if (crypto === undefined || crypto === true) { // If not given, use a default instance @@ -2581,7 +2632,7 @@ Tox.prototype._initCrypto = function (opts) { * @param {(Buffer|String)} [data] * @todo Take one param (opts map) */ -Tox.prototype._initNew = function (options, data) { +Tox.prototype._initNew = function(options, data) { var eptr = ref.alloc(TOX_ERR_NEW); if (options) { @@ -2603,7 +2654,7 @@ Tox.prototype._initNew = function (options, data) { * @param {ToxOptions} options * @todo Update for char* proxy_host, instead of char[256] proxy_host */ -Tox.prototype._setProxyToToxOptions = function (opts, options) { +Tox.prototype._setProxyToToxOptions = function(opts, options) { var proxy = opts["proxy"]; if (_.isString(proxy)) { @@ -2613,8 +2664,10 @@ Tox.prototype._setProxyToToxOptions = function (opts, options) { if (_.isObject(proxy)) { if (_.isString(proxy.type)) { - if (/^http$/i.test(proxy.type)) options.proxy_type = consts.TOX_PROXY_TYPE_HTTP; - else if (/^socks5?$/i.test(proxy.type)) options.proxy_type = consts.TOX_PROXY_TYPE_SOCKS5; + if (/^http$/i.test(proxy.type)) + options.proxy_type = consts.TOX_PROXY_TYPE_HTTP; + else if (/^socks5?$/i.test(proxy.type)) + options.proxy_type = consts.TOX_PROXY_TYPE_SOCKS5; } if (options.proxy_type !== consts.TOX_PROXY_TYPE_NONE) { @@ -2635,16 +2688,20 @@ 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 */ -Tox.prototype._storeFFICallback = function (key, callback) { - if (!this._ffiCallbacks) this._ffiCallbacks = {}; +Tox.prototype._storeFFICallback = function(key, callback) { + if (!this._ffiCallbacks) + this._ffiCallbacks = {}; - if (this._ffiCallbacks[key] === undefined) this._ffiCallbacks[key] = [callback]; - else this._ffiCallbacks[key].push(callback); + if (this._ffiCallbacks[key] === undefined) + this._ffiCallbacks[key] = [ callback ]; + else + this._ffiCallbacks[key].push(callback); }; /** @@ -2654,7 +2711,7 @@ Tox.prototype._storeFFICallback = function (key, callback) { * @param {Function} callback - Callback function * @return {ffi.Callback} ffi callback */ -Tox.prototype._toFFICallback = function (ffiFunc, callback) { +Tox.prototype._toFFICallback = function(ffiFunc, callback) { return ffi.Callback(ffiFunc.retType, ffiFunc.argTypes, callback); }; @@ -2663,17 +2720,14 @@ 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) { - var api = opts["api"], - args = opts["args"], - async = opts["async"], - callback = opts["callback"], - address = args[0], - port = args[1], - publicKey = args[2]; +Tox.prototype._performBootstrap = function(opts) { + var api = opts["api"], args = opts["args"], async = opts["async"], + callback = opts["callback"], address = args[0], port = args[1], + publicKey = args[2]; // Fix address and public key address = Buffer.from(address + "\0"); @@ -2684,11 +2738,14 @@ Tox.prototype._performBootstrap = function (opts) { var eptr = ref.alloc(TOX_ERR_BOOTSTRAP); if (async) { - if (!this._checkHandle(callback)) return; - api(address, port, publicKey, eptr, function (err, success) { + if (!this._checkHandle(callback)) + return; + api(address, port, publicKey, eptr, function(err, success) { var terr = errors.bootstrap(eptr.deref()); - if (!err && terr) err = terr; - if (!err && !success) err = errors.unsuccessful(); + if (!err && terr) + err = terr; + if (!err && !success) + err = errors.unsuccessful(); if (callback) { callback(err); } @@ -2697,8 +2754,10 @@ Tox.prototype._performBootstrap = function (opts) { this._checkHandleSync(); var success = api(address, port, publicKey, eptr); var err = errors.bootstrap(eptr.deref()); - if (err) throw err; - if (!success) throw errors.unsuccessful(); + if (err) + throw err; + if (!success) + throw errors.unsuccessful(); } }; @@ -2708,39 +2767,37 @@ Tox.prototype._performBootstrap = function (opts) { * @todo Custom error type/function, ex. TOX_ERR_FRIEND_GET_PUBLIC_KEY * @private */ -Tox.prototype._performFriendGetter = function (opts) { - var api = opts["api"], - friend = opts["friend"], - raw = opts["format"] === "raw", - _size = opts["size"], - async = opts["async"], - callback = opts["callback"]; +Tox.prototype._performFriendGetter = function(opts) { + var api = opts["api"], friend = opts["friend"], + raw = opts["format"] === "raw", _size = opts["size"], + async = opts["async"], callback = opts["callback"]; if (_.isNumber(_size)) { var size; if (async) - size = function (cb) { - cb(undefined, _size); - }; + size = function(cb) { cb(undefined, _size); }; else - size = function () { - return _size; - }; - } else size = _size; // Assumes size is a Function + size = function() { return _size; }; + } else + size = _size; // Assumes size is a Function var eptr = ref.alloc(TOX_ERR_FRIEND_QUERY); if (async) { - if (!this._checkHandle(callback)) return; - size(function (err, size) { + if (!this._checkHandle(callback)) + return; + size(function(err, size) { if (!err) { var buffer = Buffer.alloc(size); buffer.fill(0); - api(friend, buffer, eptr, function (err, success) { + api(friend, buffer, eptr, function(err, success) { var terr = errors.friendQuery(eptr.deref()); - if (!err && terr) err = terr; - if (!err && !success) err = errors.unsuccessful(); - if (!err && !raw) buffer = buffer.toString("utf8"); + if (!err && terr) + err = terr; + if (!err && !success) + err = errors.unsuccessful(); + if (!err && !raw) + buffer = buffer.toString("utf8"); if (callback) { callback(err, buffer); } @@ -2756,9 +2813,12 @@ Tox.prototype._performFriendGetter = function (opts) { buffer.fill(0); var success = api(friend, buffer, eptr); var err = errors.friendQuery(eptr.deref()); - if (err) throw err; - if (!success) throw errors.unsuccessful(); - if (!raw) buffer = buffer.toString("utf8"); + if (err) + throw err; + if (!success) + throw errors.unsuccessful(); + if (!raw) + buffer = buffer.toString("utf8"); return buffer; } }; @@ -2768,20 +2828,21 @@ Tox.prototype._performFriendGetter = function (opts) { * a Number. * @private */ -Tox.prototype._performFriendNumberGetter = function (opts) { - var api = opts["api"], - friend = opts["friend"], - async = opts["async"], - callback = opts["callback"]; +Tox.prototype._performFriendNumberGetter = function(opts) { + var api = opts["api"], friend = opts["friend"], async = opts["async"], + callback = opts["callback"]; var eptr = ref.alloc(TOX_ERR_FRIEND_QUERY); if (async) { - if (!this._checkHandle(callback)) return; - api(friend, eptr, function (err, size) { + if (!this._checkHandle(callback)) + return; + api(friend, eptr, function(err, size) { var terr = errors.friendQuery(eptr.deref()); - if (!err && terr) err = terr; - if (!err) size = Number(size); + if (!err && terr) + err = terr; + if (!err) + size = Number(size); if (callback) { callback(err, size); } @@ -2790,7 +2851,8 @@ Tox.prototype._performFriendNumberGetter = function (opts) { this._checkHandleSync(); var size = api(friend, eptr); var err = errors.friendQuery(eptr.deref()); - if (err) throw err; + if (err) + throw err; return Number(size); } }; @@ -2803,32 +2865,28 @@ Tox.prototype._performFriendNumberGetter = function (opts) { * a Buffer of that size) and trying to move data to that Buffer. * @private */ -Tox.prototype._performGetter = function (opts) { - var api = opts["api"], - raw = opts["format"] === "raw", - _size = opts["size"], - async = opts["async"], - callback = opts["callback"]; +Tox.prototype._performGetter = function(opts) { + var api = opts["api"], raw = opts["format"] === "raw", _size = opts["size"], + async = opts["async"], callback = opts["callback"]; if (_.isNumber(_size)) { var size; if (async) - size = function (cb) { - cb(undefined, _size); - }; + size = function(cb) { cb(undefined, _size); }; else - size = function () { - return _size; - }; - } else size = _size; // Assumes size is a Function + size = function() { return _size; }; + } else + size = _size; // Assumes size is a Function if (async) { - if (!this._checkHandle(callback)) return; - size(function (err, size) { + if (!this._checkHandle(callback)) + return; + size(function(err, size) { if (!err) { var buffer = Buffer.alloc(size); - api(buffer, function (err) { - if (!err && !raw) buffer = buffer.toString("utf8"); + api(buffer, function(err) { + if (!err && !raw) + buffer = buffer.toString("utf8"); if (callback) { callback(err, buffer); } @@ -2842,7 +2900,8 @@ Tox.prototype._performGetter = function (opts) { size = size(); var buffer = Buffer.alloc(size); api(buffer); - if (!raw) buffer = buffer.toString("utf8"); + if (!raw) + buffer = buffer.toString("utf8"); return buffer; } }; @@ -2851,15 +2910,15 @@ Tox.prototype._performGetter = function (opts) { * Helper wrapper function for api functions that return a Number. * @private */ -Tox.prototype._performNumberGetter = function (opts) { - var api = opts["api"], - async = opts["async"], - callback = opts["callback"]; +Tox.prototype._performNumberGetter = function(opts) { + var api = opts["api"], async = opts["async"], callback = opts["callback"]; if (async) { - if (!this._checkHandle(callback)) return; - api(function (err, size) { - if (!err) size = Number(size); + if (!this._checkHandle(callback)) + return; + api(function(err, size) { + if (!err) + size = Number(size); if (callback) { callback(err, size); } @@ -2874,15 +2933,14 @@ Tox.prototype._performNumberGetter = function (opts) { /** * @private */ -Tox.prototype._performNumberSetter = function (opts) { - var api = opts["api"], - value = opts["value"], - async = opts["async"], - callback = opts["callback"]; +Tox.prototype._performNumberSetter = function(opts) { + var api = opts["api"], value = opts["value"], async = opts["async"], + callback = opts["callback"]; if (async) { - if (!this._checkHandle(callback)) return; - api(value, function (err) { + if (!this._checkHandle(callback)) + return; + api(value, function(err) { if (callback) { callback(err); } @@ -2897,21 +2955,17 @@ Tox.prototype._performNumberSetter = function (opts) { * Helper wrapper function for api functions that get a size_t. * @private */ -Tox.prototype._performSizeGetter = function (opts) { - return this._performNumberGetter(opts); -}; +Tox.prototype._performSizeGetter = function( + opts) { return this._performNumberGetter(opts); }; /** * Helper wrapper function for api functions that take a buffer * (char*, uint8_t*) or a string of some size and use it to set data. * @private */ -Tox.prototype._performSetter = function (opts) { - var api = opts["api"], - data = opts["data"], - errorCheck = opts["error"], - async = opts["async"], - callback = opts["callback"]; +Tox.prototype._performSetter = function(opts) { + var api = opts["api"], data = opts["data"], errorCheck = opts["error"], + async = opts["async"], callback = opts["callback"]; if (_.isString(data)) { data = Buffer.from(data); @@ -2920,11 +2974,14 @@ Tox.prototype._performSetter = function (opts) { var eptr = ref.alloc(CEnum); // @todo: Make this more specific? if (async) { - if (!this._checkHandle(callback)) return; - api(data, size_t(data.length), eptr, function (err, success) { + if (!this._checkHandle(callback)) + return; + api(data, size_t(data.length), eptr, function(err, success) { var terr = errorCheck(eptr.deref()); - if (!err && terr) err = terr; - if (!err && !success) err = errors.unsuccessful(); + if (!err && terr) + err = terr; + if (!err && !success) + err = errors.unsuccessful(); if (callback) { callback(err); } @@ -2932,9 +2989,11 @@ Tox.prototype._performSetter = function (opts) { } else { this._checkHandleSync(); var success = api(data, size_t(data.length), eptr), - err = errorCheck(eptr.deref()); - if (err) throw err; - if (!success) throw errors.unsuccessful(); + err = errorCheck(eptr.deref()); + if (err) + throw err; + if (!success) + throw errors.unsuccessful(); } }; @@ -2943,21 +3002,21 @@ Tox.prototype._performSetter = function (opts) { * Buffer to send a packet. * @private */ -Tox.prototype._performSendPacket = function (opts) { - var api = opts["api"], - data = opts["data"], - friendnum = opts["friend"], - async = opts["async"], - callback = opts["callback"]; +Tox.prototype._performSendPacket = function(opts) { + var api = opts["api"], data = opts["data"], friendnum = opts["friend"], + async = opts["async"], callback = opts["callback"]; var eptr = ref.alloc(TOX_ERR_FRIEND_CUSTOM_PACKET); if (async) { - if (!this._checkHandle(callback)) return; - api(friendnum, data, size_t(data.length), eptr, function (err, res) { + if (!this._checkHandle(callback)) + return; + api(friendnum, data, size_t(data.length), eptr, function(err, res) { var terr = errors.friendCustomPacket(eptr.deref()); - if (!err && terr) err = terr; - if (!err && !res) err = errors.unsuccessful(); + if (!err && terr) + err = terr; + if (!err && !res) + err = errors.unsuccessful(); if (callback) { callback(err); } @@ -2965,9 +3024,11 @@ Tox.prototype._performSendPacket = function (opts) { } else { this._checkHandleSync(); var success = api(friendnum, data, size_t(data.length), eptr), - err = errors.friendCustomPacket(eptr.deref()); - if (err) throw err; - if (!success) throw errors.unsuccessful(); + err = errors.friendCustomPacket(eptr.deref()); + if (err) + throw err; + if (!success) + throw errors.unsuccessful(); } }; @@ -2975,18 +3036,18 @@ Tox.prototype._performSendPacket = function (opts) { * Helper wrapper function for api functions that get a port. * @private */ -Tox.prototype._performGetPort = function (opts) { - var api = opts["api"], - async = opts["async"], - callback = opts["callback"]; +Tox.prototype._performGetPort = function(opts) { + var api = opts["api"], async = opts["async"], callback = opts["callback"]; var eptr = ref.alloc(TOX_ERR_GET_PORT); if (async) { - if (!this._checkHandle(callback)) return; - api(eptr, function (err, port) { + if (!this._checkHandle(callback)) + return; + api(eptr, function(err, port) { var terr = errors.getPort(eptr.deref()); - if (!err && terr) err = terr; + if (!err && terr) + err = terr; if (callback) { callback(err, port); } @@ -2995,7 +3056,8 @@ Tox.prototype._performGetPort = function (opts) { this._checkHandleSync(); var port = api(eptr); var err = errors.getPort(eptr.deref()); - if (err) throw err; + if (err) + throw err; return port; } }; @@ -3004,12 +3066,10 @@ Tox.prototype._performGetPort = function (opts) { * Helper wrapper function for version api functions. * @private */ -Tox.prototype._performVersion = function (opts) { - var api = opts["api"], - async = opts["async"], - callback = opts["callback"]; +Tox.prototype._performVersion = function(opts) { + var api = opts["api"], async = opts["async"], callback = opts["callback"]; if (async) { - api(function (err, version) { + api(function(err, version) { if (callback) { callback(err, version); } @@ -3027,7 +3087,7 @@ Tox.prototype._performVersion = function (opts) { * Initialize all callbacks. * @private */ -Tox.prototype._initCallbacks = function () { +Tox.prototype._initCallbacks = function() { this._initSelfConnectionStatusCb(); this._initFriendNameCb(); this._initFriendStatusMessageCb(); @@ -3049,13 +3109,12 @@ Tox.prototype._initCallbacks = function () { * Helper function for initializing tox callbacks. * @private */ -Tox.prototype._initCallback = function (opts) { +Tox.prototype._initCallback = function(opts) { this._checkHandleSync(); var api = opts["api"], - cb = opts["cb"], // Callback type - name = opts["name"], - wrapper = opts["wrapper"]; + cb = opts["cb"], // Callback type + name = opts["name"], wrapper = opts["wrapper"]; var x = this._toFFICallback(cb, wrapper); this._storeFFICallback(name, x); // Store for GC issues @@ -3066,14 +3125,16 @@ Tox.prototype._initCallback = function (opts) { * Initialize the selfConnectionStatus event callback. * @private */ -Tox.prototype._initSelfConnectionStatusCb = function () { +Tox.prototype._initSelfConnectionStatusCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_self_connection_status.bind(undefined, this.getHandle()), - cb: SelfConnectionStatusCallback, - name: "SelfConnectionStatus", - wrapper: function (handle, connection, userdata) { - _this._emit("selfConnectionStatus", new toxEvents.SelfConnectionStatusEvent(connection)); + api : this.getLibrary().tox_callback_self_connection_status.bind( + undefined, this.getHandle()), + cb : SelfConnectionStatusCallback, + name : "SelfConnectionStatus", + wrapper : function(handle, connection, userdata) { + _this._emit("selfConnectionStatus", + new toxEvents.SelfConnectionStatusEvent(connection)); }, }); }; @@ -3082,13 +3143,14 @@ Tox.prototype._initSelfConnectionStatusCb = function () { * Initialize the friendName event callback. * @private */ -Tox.prototype._initFriendNameCb = function () { +Tox.prototype._initFriendNameCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_friend_name.bind(undefined, this.getHandle()), - cb: FriendNameCallback, - name: "FriendName", - wrapper: function (handle, friend, buffer, size, userdata) { + api : this.getLibrary().tox_callback_friend_name.bind(undefined, + this.getHandle()), + cb : FriendNameCallback, + name : "FriendName", + wrapper : function(handle, friend, buffer, size, userdata) { var name = buffer.slice(0, size).toString(); _this._emit("friendName", new toxEvents.FriendNameEvent(friend, name)); }, @@ -3099,18 +3161,17 @@ Tox.prototype._initFriendNameCb = function () { * Initialize the friendStatusMessage event callback. * @private */ -Tox.prototype._initFriendStatusMessageCb = function () { +Tox.prototype._initFriendStatusMessageCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_friend_status_message.bind(undefined, this.getHandle()), - cb: FriendStatusMessageCallback, - name: "FriendStatusMessage", - wrapper: function (handle, friend, buffer, size, userdata) { + api : this.getLibrary().tox_callback_friend_status_message.bind( + undefined, this.getHandle()), + cb : FriendStatusMessageCallback, + name : "FriendStatusMessage", + wrapper : function(handle, friend, buffer, size, userdata) { var statusMessage = buffer.slice(0, size).toString(); - _this._emit( - "friendStatusMessage", - new toxEvents.FriendStatusMessageEvent(friend, statusMessage) - ); + _this._emit("friendStatusMessage", new toxEvents.FriendStatusMessageEvent( + friend, statusMessage)); }, }); }; @@ -3119,14 +3180,16 @@ Tox.prototype._initFriendStatusMessageCb = function () { * Initialize the friendStatus event callback. * @private */ -Tox.prototype._initFriendStatusCb = function () { +Tox.prototype._initFriendStatusCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_friend_status.bind(undefined, this.getHandle()), - cb: FriendStatusCallback, - name: "FriendStatus", - wrapper: function (handle, friend, status, userdata) { - _this._emit("friendStatus", new toxEvents.FriendStatusEvent(friend, status)); + api : this.getLibrary().tox_callback_friend_status.bind(undefined, + this.getHandle()), + cb : FriendStatusCallback, + name : "FriendStatus", + wrapper : function(handle, friend, status, userdata) { + _this._emit("friendStatus", + new toxEvents.FriendStatusEvent(friend, status)); }, }); }; @@ -3135,17 +3198,17 @@ Tox.prototype._initFriendStatusCb = function () { * Initialize the friendConnectionStatus event callback. * @private */ -Tox.prototype._initFriendConnectionStatusCb = function () { +Tox.prototype._initFriendConnectionStatusCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_friend_connection_status.bind(undefined, this.getHandle()), - cb: FriendConnectionStatusCallback, - name: "FriendConnectionStatus", - wrapper: function (handle, friend, connection, userdata) { + api : this.getLibrary().tox_callback_friend_connection_status.bind( + undefined, this.getHandle()), + cb : FriendConnectionStatusCallback, + name : "FriendConnectionStatus", + wrapper : function(handle, friend, connection, userdata) { _this._emit( - "friendConnectionStatus", - new toxEvents.FriendConnectionStatusEvent(friend, connection) - ); + "friendConnectionStatus", + new toxEvents.FriendConnectionStatusEvent(friend, connection)); }, }); }; @@ -3154,14 +3217,16 @@ Tox.prototype._initFriendConnectionStatusCb = function () { * Initialize the friendTyping event callback. * @private */ -Tox.prototype._initFriendTypingCb = function () { +Tox.prototype._initFriendTypingCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_friend_typing.bind(undefined, this.getHandle()), - cb: FriendTypingCallback, - name: "FriendTypingStatus", - wrapper: function (handle, friend, typing, userdata) { - _this._emit("friendTyping", new toxEvents.FriendTypingEvent(friend, typing)); + api : this.getLibrary().tox_callback_friend_typing.bind(undefined, + this.getHandle()), + cb : FriendTypingCallback, + name : "FriendTypingStatus", + wrapper : function(handle, friend, typing, userdata) { + _this._emit("friendTyping", + new toxEvents.FriendTypingEvent(friend, typing)); }, }); }; @@ -3170,14 +3235,16 @@ Tox.prototype._initFriendTypingCb = function () { * Initialize the friendReadReceipt event callback. * @private */ -Tox.prototype._initFriendReadReceiptCb = function () { +Tox.prototype._initFriendReadReceiptCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_friend_read_receipt.bind(undefined, this.getHandle()), - cb: FriendReadReceiptCallback, - name: "FriendReadReceiptStatus", - wrapper: function (handle, friend, receipt, userdata) { - _this._emit("friendReadReceipt", new toxEvents.FriendReadReceiptEvent(friend, receipt)); + api : this.getLibrary().tox_callback_friend_read_receipt.bind( + undefined, this.getHandle()), + cb : FriendReadReceiptCallback, + name : "FriendReadReceiptStatus", + wrapper : function(handle, friend, receipt, userdata) { + _this._emit("friendReadReceipt", + new toxEvents.FriendReadReceiptEvent(friend, receipt)); }, }); }; @@ -3186,16 +3253,18 @@ Tox.prototype._initFriendReadReceiptCb = function () { * Initialize the friendRequest event callback. * @private */ -Tox.prototype._initFriendRequestCb = function () { +Tox.prototype._initFriendRequestCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_friend_request.bind(undefined, this.getHandle()), - cb: FriendRequestCallback, - name: "FriendRequestStatus", - wrapper: function (handle, publicKey, data, size, userdata) { + api : this.getLibrary().tox_callback_friend_request.bind(undefined, + this.getHandle()), + cb : FriendRequestCallback, + name : "FriendRequestStatus", + wrapper : function(handle, publicKey, data, size, userdata) { publicKey = Buffer.from(publicKey); // Copy into persistent Buffer var message = data.slice(0, size).toString(); - _this._emit("friendRequest", new toxEvents.FriendRequestEvent(publicKey, message)); + _this._emit("friendRequest", + new toxEvents.FriendRequestEvent(publicKey, message)); }, }); }; @@ -3204,15 +3273,17 @@ Tox.prototype._initFriendRequestCb = function () { * Initialize the friendMessage event callback. * @private */ -Tox.prototype._initFriendMessageCb = function () { +Tox.prototype._initFriendMessageCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_friend_message.bind(undefined, this.getHandle()), - cb: FriendMessageCallback, - name: "FriendMessage", - wrapper: function (handle, friend, type, data, size, userdata) { + api : this.getLibrary().tox_callback_friend_message.bind(undefined, + this.getHandle()), + cb : FriendMessageCallback, + name : "FriendMessage", + wrapper : function(handle, friend, type, data, size, userdata) { var message = data.slice(0, size).toString(); - _this._emit("friendMessage", new toxEvents.FriendMessageEvent(friend, type, message)); + _this._emit("friendMessage", + new toxEvents.FriendMessageEvent(friend, type, message)); }, }); }; @@ -3221,14 +3292,16 @@ Tox.prototype._initFriendMessageCb = function () { * Initialize the fileRecvControl event callback. * @private */ -Tox.prototype._initFileRecvControlCb = function () { +Tox.prototype._initFileRecvControlCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_file_recv_control.bind(undefined, this.getHandle()), - cb: FileRecvControlCallback, - name: "FileRecvControlCallback", - wrapper: function (handle, friend, file, control, userdata) { - _this._emit("fileRecvControl", new toxEvents.FileRecvControlEvent(friend, file, control)); + api : this.getLibrary().tox_callback_file_recv_control.bind( + undefined, this.getHandle()), + cb : FileRecvControlCallback, + name : "FileRecvControlCallback", + wrapper : function(handle, friend, file, control, userdata) { + _this._emit("fileRecvControl", + new toxEvents.FileRecvControlEvent(friend, file, control)); }, }); }; @@ -3237,17 +3310,16 @@ Tox.prototype._initFileRecvControlCb = function () { * Initialize the fileChunkRequest event callback. * @private */ -Tox.prototype._initFileChunkRequestCb = function () { +Tox.prototype._initFileChunkRequestCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_file_chunk_request.bind(undefined, this.getHandle()), - cb: FileChunkRequestCallback, - name: "FileChunkRequestCallback", - wrapper: function (handle, friend, file, position, length, userdata) { - _this._emit( - "fileChunkRequest", - new toxEvents.FileChunkRequestEvent(friend, file, position, length) - ); + api : this.getLibrary().tox_callback_file_chunk_request.bind( + undefined, this.getHandle()), + cb : FileChunkRequestCallback, + name : "FileChunkRequestCallback", + wrapper : function(handle, friend, file, position, length, userdata) { + _this._emit("fileChunkRequest", new toxEvents.FileChunkRequestEvent( + friend, file, position, length)); }, }); }; @@ -3256,20 +3328,23 @@ Tox.prototype._initFileChunkRequestCb = function () { * Initialize the fileRecv event callback. * @private */ -Tox.prototype._initFileRecvCb = function () { +Tox.prototype._initFileRecvCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_file_recv.bind(undefined, this.getHandle()), - cb: FileRecvCallback, - name: "FileRecvCallback", - wrapper: function (handle, friend, file, kind, size, filename, length, userdata) { + api : this.getLibrary().tox_callback_file_recv.bind(undefined, + this.getHandle()), + cb : FileRecvCallback, + name : "FileRecvCallback", + wrapper : function(handle, friend, file, kind, size, filename, length, + userdata) { // Filename might be NULL, probably if file kind is AVATAR or non-DATA if (ref.address(filename) !== 0) { filename = ref.reinterpret(filename, length).toString("utf8"); } else { filename = undefined; } - _this._emit("fileRecv", new toxEvents.FileRecvEvent(friend, file, kind, size, filename)); + _this._emit("fileRecv", new toxEvents.FileRecvEvent(friend, file, kind, + size, filename)); }, }); }; @@ -3278,21 +3353,24 @@ Tox.prototype._initFileRecvCb = function () { * Initialize the fileRecvChunk event callback. * @private */ -Tox.prototype._initFileRecvChunkCb = function () { +Tox.prototype._initFileRecvChunkCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_file_recv_chunk.bind(undefined, this.getHandle()), - 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? + api : this.getLibrary().tox_callback_file_recv_chunk.bind(undefined, + this.getHandle()), + 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? if (ref.address(data) !== 0) { - data = Buffer.from(ref.reinterpret(data, size)); // Copy to another Buffer + data = + Buffer.from(ref.reinterpret(data, size)); // Copy to another Buffer } else { data = undefined; } - _this._emit("fileRecvChunk", new toxEvents.FileRecvChunkEvent(friend, file, position, data)); + _this._emit("fileRecvChunk", new toxEvents.FileRecvChunkEvent( + friend, file, position, data)); }, }); }; @@ -3301,16 +3379,18 @@ Tox.prototype._initFileRecvChunkCb = function () { * Initialize the friendLosslessPacket event callback. * @private */ -Tox.prototype._initFriendLosslessPacketCb = function () { +Tox.prototype._initFriendLosslessPacketCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_friend_lossless_packet.bind(undefined, this.getHandle()), - cb: FriendLosslessPacketCallback, - name: "FriendLosslessPacketCallback", - wrapper: function (handle, friend, data, length, userdata) { - //if(ref.address(data) !== 0) { + api : this.getLibrary().tox_callback_friend_lossless_packet.bind( + undefined, this.getHandle()), + cb : FriendLosslessPacketCallback, + name : "FriendLosslessPacketCallback", + wrapper : function(handle, friend, data, length, userdata) { + // 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; //} @@ -3318,7 +3398,8 @@ Tox.prototype._initFriendLosslessPacketCb = function () { throw new Error("NULL data packet"); } data = Buffer.from(ref.reinterpret(data, length)); - _this._emit("friendLosslessPacket", new toxEvents.FriendPacketEvent(friend, data, true)); + _this._emit("friendLosslessPacket", + new toxEvents.FriendPacketEvent(friend, data, true)); }, }); }; @@ -3327,18 +3408,20 @@ Tox.prototype._initFriendLosslessPacketCb = function () { * Initialize the friendLossyPacket event callback. * @private */ -Tox.prototype._initFriendLossyPacketCb = function () { +Tox.prototype._initFriendLossyPacketCb = function() { var _this = this; this._initCallback({ - api: this.getLibrary().tox_callback_friend_lossy_packet.bind(undefined, this.getHandle()), - cb: FriendLossyPacketCallback, - name: "FriendLossyPacketCallback", - wrapper: function (handle, friend, data, length, userdata) { + api : this.getLibrary().tox_callback_friend_lossy_packet.bind( + undefined, this.getHandle()), + cb : FriendLossyPacketCallback, + name : "FriendLossyPacketCallback", + wrapper : function(handle, friend, data, length, userdata) { if (ref.address(data) === 0) { throw new Error("NULL data packet"); } data = Buffer.from(ref.reinterpret(data, length)); - _this._emit("friendLossyPacket", new toxEvents.FriendPacketEvent(friend, data, false)); + _this._emit("friendLossyPacket", + new toxEvents.FriendPacketEvent(friend, data, false)); }, }); }; From d821b15e829929fa205563356e13b5655217947f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 6 Dec 2021 11:59:24 +0000 Subject: [PATCH 2/2] Restyled by prettier --- examples/bin/promises-example.js | 121 +- lib/tox.js | 2184 ++++++++++++++---------------- 2 files changed, 1108 insertions(+), 1197 deletions(-) diff --git a/examples/bin/promises-example.js b/examples/bin/promises-example.js index 940578e..bed0093 100644 --- a/examples/bin/promises-example.js +++ b/examples/bin/promises-example.js @@ -21,14 +21,14 @@ var tox = new toxcore.Tox(); * Bootstrap tox via hardcoded nodes. * For more nodes, see: https://wiki.tox.chat/users/nodes */ -var bootstrap = function(callback) { +var bootstrap = function (callback) { // Define nodes to bootstrap from var nodes = [ { - maintainer : "Anthony Bilinski", - address : "tox.abilinski.com", - port : 33445, - key : "10C00EB250C3233E343E2AEBA07115A5C28920E9C8D29492F6D00B29049EDC7E", + maintainer: "Anthony Bilinski", + address: "tox.abilinski.com", + port: 33445, + key: "10C00EB250C3233E343E2AEBA07115A5C28920E9C8D29492F6D00B29049EDC7E", }, ]; @@ -59,55 +59,49 @@ var bootstrap = function(callback) { }); }; -var initProfile = function(callback) { +var initProfile = function (callback) { var setName = tox.setNameAsync("Promises Bot"), - setStatusMessage = - tox.setStatusMessageAsync("node-toxcore promises bot example"); + setStatusMessage = tox.setStatusMessageAsync("node-toxcore promises bot example"); Promise.join(setName, setStatusMessage, callback); }; -var initCallbacks = function(callback) { - tox.on( - "selfConnectionStatus", - function( - e) { console.log(e.isConnected() ? "Connected" : "Disconnected"); }); +var initCallbacks = function (callback) { + tox.on("selfConnectionStatus", function (e) { + console.log(e.isConnected() ? "Connected" : "Disconnected"); + }); - tox.on("friendName", function(e) { + tox.on("friendName", function (e) { console.log("Friend[" + e.friend() + "] changed their name: " + e.name()); }); - tox.on("friendStatusMessage", function(e) { - console.log("Friend[" + e.friend() + - "] changed their status message: " + e.statusMessage()); + tox.on("friendStatusMessage", function (e) { + console.log("Friend[" + e.friend() + "] changed their status message: " + e.statusMessage()); }); - tox.on("friendStatus", function(e) { - console.log("Friend[" + e.friend() + - "] changed their status: " + e.status()); + tox.on("friendStatus", function (e) { + console.log("Friend[" + e.friend() + "] changed their status: " + e.status()); }); - tox.on("friendConnectionStatus", function(e) { - console.log("Friend[" + e.friend() + "] is now " + - (e.isConnected() ? "online" : "offline")); + tox.on("friendConnectionStatus", function (e) { + console.log("Friend[" + e.friend() + "] is now " + (e.isConnected() ? "online" : "offline")); }); - tox.on("friendTyping", function(e) { - console.log("Friend[" + e.friend() + "] is " + - (e.isTyping() ? "typing" : "not typing")); + tox.on("friendTyping", function (e) { + console.log("Friend[" + e.friend() + "] is " + (e.isTyping() ? "typing" : "not typing")); }); - tox.on("friendReadReceipt", function(e) { + tox.on("friendReadReceipt", function (e) { console.log("Friend[" + e.friend() + "] receipt: " + e.receipt()); }); - tox.on("friendRequest", function(e) { - tox.addFriendNoRequest(e.publicKey(), function(err, friend) { + tox.on("friendRequest", function (e) { + tox.addFriendNoRequest(e.publicKey(), function (err, friend) { console.log("Received friend request: " + e.message()); console.log("Accepted friend request from " + e.publicKeyHex()); }); }); - tox.on("friendMessage", function(e) { + tox.on("friendMessage", function (e) { if (e.isAction()) { console.log("** Friend[" + e.friend() + "] " + e.message() + " **"); } else { @@ -117,46 +111,48 @@ var initCallbacks = function(callback) { tox.sendFriendMessageSync(e.friend(), e.message(), e.messageType()); if (e.message() === "typing on") { - tox.setTyping(e.friend(), true, function(err) { + tox.setTyping(e.friend(), true, function (err) { console.log("Started typing to friend[" + e.friend() + "]"); }); } else if (e.message() === "typing off") { - tox.setTyping(e.friend(), false, function(err) { + tox.setTyping(e.friend(), false, function (err) { console.log("Stopped typing to friend[" + e.friend() + "]"); }); } if (e.message() === "profile") { var getName = tox.getFriendNameAsync(e.friend()), - getStatusMessage = tox.getFriendStatusMessageAsync(e.friend()), - 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); - }); + getStatusMessage = tox.getFriendStatusMessageAsync(e.friend()), + 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); + }); } if (e.message() === "lastonline") { - tox.getFriendLastOnlineAsync(e.friend).then(function(lastOnline) { + tox.getFriendLastOnlineAsync(e.friend).then(function (lastOnline) { console.log("Last online: " + lastOnline.toString()); }); } if (e.message() === "namelen") { var getNameSize = tox.getFriendNameSizeAsync(e.friend()), - getStatusMessageSize = - tox.getFriendStatusMessageSizeAsync(e.friend()); - Promise.join(getNameSize, getStatusMessageSize, - function(nameSize, statusMessageSize) { - console.log("Name length: " + nameSize); - console.log("Status message length: " + statusMessageSize); - }); + getStatusMessageSize = tox.getFriendStatusMessageSizeAsync(e.friend()); + Promise.join(getNameSize, getStatusMessageSize, function (nameSize, statusMessageSize) { + console.log("Name length: " + nameSize); + console.log("Status message length: " + statusMessageSize); + }); } }); @@ -166,14 +162,15 @@ var initCallbacks = function(callback) { // Initialize everything + bootstrap from nodes, then when everything // is ready, start async.parallel( - [ - bootstrap, // Bootstrap - initProfile, // Name, status message - initCallbacks, // Initialize callbacks - ], - function() { - tox.getAddressHex(function(err, address) { - console.log("Address: " + address); - tox.start(); // Start - }); + [ + bootstrap, // Bootstrap + initProfile, // Name, status message + initCallbacks, // Initialize callbacks + ], + function () { + tox.getAddressHex(function (err, address) { + console.log("Address: " + address); + tox.start(); // Start }); + } +); diff --git a/lib/tox.js b/lib/tox.js index 86bb3c7..9d1af30 100644 --- a/lib/tox.js +++ b/lib/tox.js @@ -74,15 +74,13 @@ var TOX_ERR_SET_TYPING = CEnum; // Buffer sizes for callbacks var KeyBuffer = RefArray("uint8", consts.TOX_KEY_SIZE); var KeyBufferPtr = ref.refType(KeyBuffer); -var RequestMessageBuffer = - RefArray("uint8", consts.TOX_MAX_FRIEND_REQUEST_LENGTH); +var RequestMessageBuffer = RefArray("uint8", consts.TOX_MAX_FRIEND_REQUEST_LENGTH); var RequestMessageBufferPtr = ref.refType(RequestMessageBuffer); var MessageBuffer = RefArray("uint8", consts.TOX_MAX_MESSAGE_LENGTH); var MessageBufferPtr = ref.refType(MessageBuffer); var NameBuffer = RefArray("uint8", consts.TOX_MAX_NAME_LENGTH); var NameBufferPtr = ref.refType(NameBuffer); -var StatusMessageBuffer = - RefArray("uint8", consts.TOX_MAX_STATUS_MESSAGE_LENGTH); +var StatusMessageBuffer = RefArray("uint8", consts.TOX_MAX_STATUS_MESSAGE_LENGTH); var StatusMessageBufferPtr = ref.refType(StatusMessageBuffer); var FilenameBuffer = RefArray("uint8", consts.TOX_MAX_FILENAME_LENGTH); var FilenameBufferPtr = ref.refType(FilenameBuffer); @@ -92,8 +90,7 @@ var UnknownSizeBuffer = RefArray("uint8", 1); var UnknownSizeBufferPtr = ref.refType(UnknownSizeBuffer); // Tox callback types -var SelfConnectionStatusCallback = - ffi.Function("void", [ ToxPtr, TOX_CONNECTION, UserData ]); +var SelfConnectionStatusCallback = ffi.Function("void", [ToxPtr, TOX_CONNECTION, UserData]); var FriendNameCallback = ffi.Function("void", [ ToxPtr, "uint32", @@ -108,18 +105,15 @@ var FriendStatusMessageCallback = ffi.Function("void", [ "size_t", UserData, ]); -var FriendStatusCallback = - ffi.Function("void", [ ToxPtr, "uint32", TOX_USER_STATUS, UserData ]); +var FriendStatusCallback = ffi.Function("void", [ToxPtr, "uint32", TOX_USER_STATUS, UserData]); var FriendConnectionStatusCallback = ffi.Function("void", [ ToxPtr, "uint32", TOX_CONNECTION, UserData, ]); -var FriendTypingCallback = - ffi.Function("void", [ ToxPtr, "uint32", "bool", UserData ]); -var FriendReadReceiptCallback = - ffi.Function("void", [ ToxPtr, "uint32", "uint32", UserData ]); +var FriendTypingCallback = ffi.Function("void", [ToxPtr, "uint32", "bool", UserData]); +var FriendReadReceiptCallback = ffi.Function("void", [ToxPtr, "uint32", "uint32", UserData]); var FriendRequestCallback = ffi.Function("void", [ ToxPtr, KeyBufferPtr, @@ -189,9 +183,8 @@ var FriendLossyPacketCallback = ffi.Function("void", [ * @class * @param {Object} [opts] Options */ -var Tox = function(opts) { - if (!opts) - opts = {}; +var Tox = function (opts) { + if (!opts) opts = {}; var libpath = opts["path"]; this._emitter = new events.EventEmitter(); @@ -206,9 +199,9 @@ var Tox = function(opts) { * Return a string representation of the Tox instance using util.inspect. * @return {String} string representation */ -Tox.prototype.inspect = function() { +Tox.prototype.inspect = function () { var obj = {}; - Object.keys(this).forEach(function(k) { + Object.keys(this).forEach(function (k) { obj[k] = this[k]; // Hacky fix for StringSlice assert error: // void node::Buffer::StringSlice(const @@ -229,7 +222,7 @@ Tox.prototype.inspect = function() { * @param {Tox~toxCallback} [callback] * @todo Implement with async tox_new? */ -Tox.load = function(opts, callback) { +Tox.load = function (opts, callback) { // Handle Tox.load(callback) if (arguments.length === 1 && _.isFunction(opts)) { callback = opts; @@ -238,7 +231,7 @@ Tox.load = function(opts, callback) { var data = opts["data"]; if (_.isString(data)) { - fs.readFile(data, function(err, data) { + fs.readFile(data, function (err, data) { if (!err) { opts["data"] = data; // Overwrite data (path) with data (Buffer) var tox = new Tox(opts); @@ -263,64 +256,42 @@ Tox.load = function(opts, callback) { * @param {String} [libpath="libtoxcore"] - Path to libtoxcore * @return {ffi.Library} */ -Tox.prototype.createLibrary = function(libpath) { +Tox.prototype.createLibrary = function (libpath) { libpath = libpath || "libtoxcore"; return ffi.Library(libpath, { - tox_add_tcp_relay : [ - "bool", - [ ToxPtr, Int8Ptr, "uint16", UInt8Ptr, ref.refType(TOX_ERR_BOOTSTRAP) ], - ], - tox_bootstrap : [ + tox_add_tcp_relay: [ "bool", - [ ToxPtr, Int8Ptr, "uint16", UInt8Ptr, ref.refType(TOX_ERR_BOOTSTRAP) ] + [ToxPtr, Int8Ptr, "uint16", UInt8Ptr, ref.refType(TOX_ERR_BOOTSTRAP)], ], - tox_callback_file_chunk_request : - [ "void", [ ToxPtr, FileChunkRequestCallback, UserData ] ], - tox_callback_file_recv : [ "void", [ ToxPtr, FileRecvCallback, UserData ] ], - tox_callback_file_recv_chunk : - [ "void", [ ToxPtr, FileRecvChunkCallback, UserData ] ], - tox_callback_file_recv_control : - [ "void", [ ToxPtr, FileRecvControlCallback, UserData ] ], - tox_callback_friend_connection_status : [ + tox_bootstrap: ["bool", [ToxPtr, Int8Ptr, "uint16", UInt8Ptr, ref.refType(TOX_ERR_BOOTSTRAP)]], + tox_callback_file_chunk_request: ["void", [ToxPtr, FileChunkRequestCallback, UserData]], + tox_callback_file_recv: ["void", [ToxPtr, FileRecvCallback, UserData]], + tox_callback_file_recv_chunk: ["void", [ToxPtr, FileRecvChunkCallback, UserData]], + tox_callback_file_recv_control: ["void", [ToxPtr, FileRecvControlCallback, UserData]], + tox_callback_friend_connection_status: [ "void", - [ ToxPtr, FriendConnectionStatusCallback, UserData ], + [ToxPtr, FriendConnectionStatusCallback, UserData], ], - tox_callback_friend_message : - [ "void", [ ToxPtr, FriendMessageCallback, UserData ] ], - tox_callback_friend_name : - [ "void", [ ToxPtr, FriendNameCallback, UserData ] ], - tox_callback_friend_read_receipt : - [ "void", [ ToxPtr, FriendReadReceiptCallback, UserData ] ], - tox_callback_friend_request : - [ "void", [ ToxPtr, FriendRequestCallback, UserData ] ], - tox_callback_friend_status : - [ "void", [ ToxPtr, FriendStatusCallback, UserData ] ], - tox_callback_friend_status_message : - [ "void", [ ToxPtr, FriendStatusMessageCallback, UserData ] ], - tox_callback_friend_typing : - [ "void", [ ToxPtr, FriendTypingCallback, UserData ] ], - tox_callback_self_connection_status : - [ "void", [ ToxPtr, SelfConnectionStatusCallback, UserData ] ], - tox_callback_friend_lossless_packet : - [ "void", [ ToxPtr, FriendLosslessPacketCallback, UserData ] ], - tox_callback_friend_lossy_packet : - [ "void", [ ToxPtr, FriendLossyPacketCallback, UserData ] ], - tox_file_control : [ + tox_callback_friend_message: ["void", [ToxPtr, FriendMessageCallback, UserData]], + tox_callback_friend_name: ["void", [ToxPtr, FriendNameCallback, UserData]], + tox_callback_friend_read_receipt: ["void", [ToxPtr, FriendReadReceiptCallback, UserData]], + tox_callback_friend_request: ["void", [ToxPtr, FriendRequestCallback, UserData]], + tox_callback_friend_status: ["void", [ToxPtr, FriendStatusCallback, UserData]], + tox_callback_friend_status_message: ["void", [ToxPtr, FriendStatusMessageCallback, UserData]], + tox_callback_friend_typing: ["void", [ToxPtr, FriendTypingCallback, UserData]], + tox_callback_self_connection_status: ["void", [ToxPtr, SelfConnectionStatusCallback, UserData]], + tox_callback_friend_lossless_packet: ["void", [ToxPtr, FriendLosslessPacketCallback, UserData]], + tox_callback_friend_lossy_packet: ["void", [ToxPtr, FriendLossyPacketCallback, UserData]], + tox_file_control: [ "bool", - [ - ToxPtr, "uint32", "uint32", TOX_FILE_CONTROL, - ref.refType(TOX_ERR_FILE_CONTROL) - ], + [ToxPtr, "uint32", "uint32", TOX_FILE_CONTROL, ref.refType(TOX_ERR_FILE_CONTROL)], ], - tox_file_get_file_id : [ + tox_file_get_file_id: [ "bool", - [ ToxPtr, "uint32", "uint32", UInt8Ptr, ref.refType(TOX_ERR_FILE_GET) ], + [ToxPtr, "uint32", "uint32", UInt8Ptr, ref.refType(TOX_ERR_FILE_GET)], ], - tox_file_seek : [ - "bool", - [ ToxPtr, "uint32", "uint32", "uint64", ref.refType(TOX_ERR_FILE_SEEK) ] - ], - tox_file_send : [ + tox_file_seek: ["bool", [ToxPtr, "uint32", "uint32", "uint64", ref.refType(TOX_ERR_FILE_SEEK)]], + tox_file_send: [ "uint32", [ ToxPtr, @@ -333,7 +304,7 @@ Tox.prototype.createLibrary = function(libpath) { ref.refType(TOX_ERR_FILE_SEND), ], ], - tox_file_send_chunk : [ + tox_file_send_chunk: [ "bool", [ ToxPtr, @@ -345,64 +316,49 @@ Tox.prototype.createLibrary = function(libpath) { ref.refType(TOX_ERR_FILE_SEND_CHUNK), ], ], - tox_friend_add : [ + tox_friend_add: [ "uint32", - [ ToxPtr, UInt8Ptr, UInt8Ptr, "size_t", ref.refType(TOX_ERR_FRIEND_ADD) ], + [ToxPtr, UInt8Ptr, UInt8Ptr, "size_t", ref.refType(TOX_ERR_FRIEND_ADD)], ], - tox_friend_add_norequest : - [ "uint32", [ ToxPtr, UInt8Ptr, ref.refType(TOX_ERR_FRIEND_ADD) ] ], - tox_friend_by_public_key : [ + tox_friend_add_norequest: ["uint32", [ToxPtr, UInt8Ptr, ref.refType(TOX_ERR_FRIEND_ADD)]], + tox_friend_by_public_key: [ "uint32", - [ ToxPtr, UInt8Ptr, ref.refType(TOX_ERR_FRIEND_BY_PUBLIC_KEY) ], + [ToxPtr, UInt8Ptr, ref.refType(TOX_ERR_FRIEND_BY_PUBLIC_KEY)], ], - tox_friend_delete : - [ "bool", [ ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_DELETE) ] ], - tox_friend_exists : [ "bool", [ ToxPtr, "uint32" ] ], - tox_friend_get_connection_status : [ + tox_friend_delete: ["bool", [ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_DELETE)]], + tox_friend_exists: ["bool", [ToxPtr, "uint32"]], + tox_friend_get_connection_status: [ TOX_CONNECTION, - [ ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY) ], + [ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY)], ], - tox_friend_get_last_online : [ + tox_friend_get_last_online: [ "uint64", - [ ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_GET_LAST_ONLINE) ], - ], - tox_friend_get_name : [ - "bool", [ ToxPtr, "uint32", UInt8Ptr, ref.refType(TOX_ERR_FRIEND_QUERY) ] + [ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_GET_LAST_ONLINE)], ], - tox_friend_get_name_size : - [ "size_t", [ ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY) ] ], - tox_friend_get_public_key : [ + tox_friend_get_name: ["bool", [ToxPtr, "uint32", UInt8Ptr, ref.refType(TOX_ERR_FRIEND_QUERY)]], + tox_friend_get_name_size: ["size_t", [ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY)]], + tox_friend_get_public_key: [ "uint32", - [ - ToxPtr, "uint32", UInt8Ptr, ref.refType(TOX_ERR_FRIEND_GET_PUBLIC_KEY) - ], - ], - tox_friend_get_status : [ - TOX_USER_STATUS, [ ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY) ] + [ToxPtr, "uint32", UInt8Ptr, ref.refType(TOX_ERR_FRIEND_GET_PUBLIC_KEY)], ], - tox_friend_get_status_message : [ + tox_friend_get_status: [TOX_USER_STATUS, [ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY)]], + tox_friend_get_status_message: [ "bool", - [ ToxPtr, "uint32", UInt8Ptr, ref.refType(TOX_ERR_FRIEND_QUERY) ], + [ToxPtr, "uint32", UInt8Ptr, ref.refType(TOX_ERR_FRIEND_QUERY)], ], - tox_friend_get_status_message_size : [ + tox_friend_get_status_message_size: [ "size_t", - [ ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY) ], + [ToxPtr, "uint32", ref.refType(TOX_ERR_FRIEND_QUERY)], ], - tox_friend_send_lossless_packet : [ + tox_friend_send_lossless_packet: [ "bool", - [ - ToxPtr, "uint32", UInt8Ptr, "size_t", - ref.refType(TOX_ERR_FRIEND_CUSTOM_PACKET) - ], + [ToxPtr, "uint32", UInt8Ptr, "size_t", ref.refType(TOX_ERR_FRIEND_CUSTOM_PACKET)], ], - tox_friend_send_lossy_packet : [ + tox_friend_send_lossy_packet: [ "bool", - [ - ToxPtr, "uint32", UInt8Ptr, "size_t", - ref.refType(TOX_ERR_FRIEND_CUSTOM_PACKET) - ], + [ToxPtr, "uint32", UInt8Ptr, "size_t", ref.refType(TOX_ERR_FRIEND_CUSTOM_PACKET)], ], - tox_friend_send_message : [ + tox_friend_send_message: [ "uint32", [ ToxPtr, @@ -413,47 +369,41 @@ Tox.prototype.createLibrary = function(libpath) { ref.refType(TOX_ERR_FRIEND_SEND_MESSAGE), ], ], - tox_hash : [ "bool", [ UInt8Ptr, UInt8Ptr, "size_t" ] ], - tox_iteration_interval : [ "uint32", [ ToxPtr ] ], - tox_iterate : [ "void", [ ToxPtr ] ], - tox_kill : [ "void", [ ToxPtr ] ], - tox_new : [ ToxPtr, [ ToxOptionsPtr, ref.refType(TOX_ERR_NEW) ] ], - tox_get_savedata : [ "void", [ ToxPtr, UInt8Ptr ] ], - tox_get_savedata_size : [ "size_t", [ ToxPtr ] ], - tox_options_default : [ "void", [ ToxOptionsPtr ] ], - tox_options_free : [ "void", [ ToxOptionsPtr ] ], - tox_options_new : [ ToxOptionsPtr, [ ref.refType(TOX_ERR_OPTIONS_NEW) ] ], - tox_self_get_address : [ "void", [ ToxPtr, UInt8Ptr ] ], - tox_self_get_connection_status : [ TOX_CONNECTION, [ ToxPtr ] ], - tox_self_get_friend_list : [ "void", [ ToxPtr, UInt32Ptr ] ], - tox_self_get_friend_list_size : [ "size_t", [ ToxPtr ] ], - tox_self_get_name : [ "void", [ ToxPtr, UInt8Ptr ] ], - tox_self_get_name_size : [ "size_t", [ ToxPtr ] ], - tox_self_get_nospam : [ "uint32", [ ToxPtr ] ], - tox_self_get_public_key : [ "void", [ ToxPtr, UInt8Ptr ] ], - tox_self_get_secret_key : [ "void", [ ToxPtr, UInt8Ptr ] ], - tox_self_get_status : [ TOX_USER_STATUS, [ ToxPtr ] ], - tox_self_get_status_message : [ "void", [ ToxPtr, UInt8Ptr ] ], - tox_self_get_status_message_size : [ "size_t", [ ToxPtr ] ], - tox_self_get_tcp_port : - [ "uint16", [ ToxPtr, ref.refType(TOX_ERR_GET_PORT) ] ], - tox_self_get_udp_port : - [ "uint16", [ ToxPtr, ref.refType(TOX_ERR_GET_PORT) ] ], - tox_self_set_name : [ - "bool", [ ToxPtr, UInt8Ptr, "size_t", ref.refType(TOX_ERR_SET_INFO) ] - ], - tox_self_set_nospam : [ "void", [ ToxPtr, "uint32" ] ], - tox_self_set_status : [ "void", [ ToxPtr, TOX_USER_STATUS ] ], - tox_self_set_status_message : [ + tox_hash: ["bool", [UInt8Ptr, UInt8Ptr, "size_t"]], + tox_iteration_interval: ["uint32", [ToxPtr]], + tox_iterate: ["void", [ToxPtr]], + tox_kill: ["void", [ToxPtr]], + tox_new: [ToxPtr, [ToxOptionsPtr, ref.refType(TOX_ERR_NEW)]], + tox_get_savedata: ["void", [ToxPtr, UInt8Ptr]], + tox_get_savedata_size: ["size_t", [ToxPtr]], + tox_options_default: ["void", [ToxOptionsPtr]], + tox_options_free: ["void", [ToxOptionsPtr]], + tox_options_new: [ToxOptionsPtr, [ref.refType(TOX_ERR_OPTIONS_NEW)]], + tox_self_get_address: ["void", [ToxPtr, UInt8Ptr]], + tox_self_get_connection_status: [TOX_CONNECTION, [ToxPtr]], + tox_self_get_friend_list: ["void", [ToxPtr, UInt32Ptr]], + tox_self_get_friend_list_size: ["size_t", [ToxPtr]], + tox_self_get_name: ["void", [ToxPtr, UInt8Ptr]], + tox_self_get_name_size: ["size_t", [ToxPtr]], + tox_self_get_nospam: ["uint32", [ToxPtr]], + tox_self_get_public_key: ["void", [ToxPtr, UInt8Ptr]], + tox_self_get_secret_key: ["void", [ToxPtr, UInt8Ptr]], + tox_self_get_status: [TOX_USER_STATUS, [ToxPtr]], + tox_self_get_status_message: ["void", [ToxPtr, UInt8Ptr]], + tox_self_get_status_message_size: ["size_t", [ToxPtr]], + tox_self_get_tcp_port: ["uint16", [ToxPtr, ref.refType(TOX_ERR_GET_PORT)]], + tox_self_get_udp_port: ["uint16", [ToxPtr, ref.refType(TOX_ERR_GET_PORT)]], + tox_self_set_name: ["bool", [ToxPtr, UInt8Ptr, "size_t", ref.refType(TOX_ERR_SET_INFO)]], + tox_self_set_nospam: ["void", [ToxPtr, "uint32"]], + tox_self_set_status: ["void", [ToxPtr, TOX_USER_STATUS]], + tox_self_set_status_message: [ "bool", - [ ToxPtr, UInt8Ptr, "size_t", ref.refType(TOX_ERR_SET_INFO) ], + [ToxPtr, UInt8Ptr, "size_t", ref.refType(TOX_ERR_SET_INFO)], ], - tox_self_set_typing : [ - "bool", [ ToxPtr, "uint32", "bool", ref.refType(TOX_ERR_SET_TYPING) ] - ], - tox_version_major : [ "uint32", [] ], - tox_version_minor : [ "uint32", [] ], - tox_version_patch : [ "uint32", [] ], + tox_self_set_typing: ["bool", [ToxPtr, "uint32", "bool", ref.refType(TOX_ERR_SET_TYPING)]], + tox_version_major: ["uint32", []], + tox_version_minor: ["uint32", []], + tox_version_patch: ["uint32", []], }); }; @@ -465,11 +415,11 @@ Tox.prototype.createLibrary = function(libpath) { * Asynchronous tox_version_major(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.versionMajor = function(callback) { +Tox.prototype.versionMajor = function (callback) { this._performVersion({ - api : this.getLibrary().tox_version_major.async, - async : true, - callback : callback, + api: this.getLibrary().tox_version_major.async, + async: true, + callback: callback, }); }; @@ -477,9 +427,9 @@ Tox.prototype.versionMajor = function(callback) { * Synchronous tox_version_major(3). * @return {Number} major version number */ -Tox.prototype.versionMajorSync = function(callback) { +Tox.prototype.versionMajorSync = function (callback) { return this._performVersion({ - api : this.getLibrary().tox_version_major, + api: this.getLibrary().tox_version_major, }); }; @@ -487,11 +437,11 @@ Tox.prototype.versionMajorSync = function(callback) { * Asynchronous tox_version_minor(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.versionMinor = function(callback) { +Tox.prototype.versionMinor = function (callback) { this._performVersion({ - api : this.getLibrary().tox_version_minor.async, - async : true, - callback : callback, + api: this.getLibrary().tox_version_minor.async, + async: true, + callback: callback, }); }; @@ -499,9 +449,9 @@ Tox.prototype.versionMinor = function(callback) { * Synchronous tox_version_minor(3). * @return {Number} minor version number */ -Tox.prototype.versionMinorSync = function(callback) { +Tox.prototype.versionMinorSync = function (callback) { return this._performVersion({ - api : this.getLibrary().tox_version_minor, + api: this.getLibrary().tox_version_minor, }); }; @@ -509,11 +459,11 @@ Tox.prototype.versionMinorSync = function(callback) { * Asynchronous tox_version_patch(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.versionPatch = function(callback) { +Tox.prototype.versionPatch = function (callback) { this._performVersion({ - api : this.getLibrary().tox_version_patch.async, - async : true, - callback : callback, + api: this.getLibrary().tox_version_patch.async, + async: true, + callback: callback, }); }; @@ -521,9 +471,9 @@ Tox.prototype.versionPatch = function(callback) { * Synchronous tox_version_patch(3). * @return {Number} patch version number */ -Tox.prototype.versionPatchSync = function(callback) { +Tox.prototype.versionPatchSync = function (callback) { return this._performVersion({ - api : this.getLibrary().tox_version_patch, + api: this.getLibrary().tox_version_patch, }); }; @@ -532,7 +482,7 @@ Tox.prototype.versionPatchSync = function(callback) { * @param {ToxOptions} opts * @param {Tox~errorCallback} [callback] */ -Tox.prototype.freeOptions = function(opts, callback) { +Tox.prototype.freeOptions = function (opts, callback) { this.getLibrary().tox_options_free.async(opts.ref(), callback); }; @@ -540,8 +490,9 @@ Tox.prototype.freeOptions = function(opts, callback) { * Synchronous tox_options_free(3). * @param {ToxOptions} opts */ -Tox.prototype.freeOptionsSync = function( - opts) { this.getLibrary().tox_options_free(opts.ref()); }; +Tox.prototype.freeOptionsSync = function (opts) { + this.getLibrary().tox_options_free(opts.ref()); +}; /** * Asynchronous tox_options_new(3). @@ -550,11 +501,10 @@ Tox.prototype.freeOptionsSync = function( * @return {ToxOptions} Options * @todo Error handling */ -Tox.prototype.newOptions = function(callback) { - this.getLibrary().tox_options_new.async(ref.NULL, function(err, options) { +Tox.prototype.newOptions = function (callback) { + this.getLibrary().tox_options_new.async(ref.NULL, function (err, options) { var opts; - if (!err) - opts = options.deref(); + if (!err) opts = options.deref(); if (callback) { callback(err, opts); } @@ -567,7 +517,7 @@ Tox.prototype.newOptions = function(callback) { * @return {ToxOptions} Options * @todo Error handling */ -Tox.prototype.newOptionsSync = function() { +Tox.prototype.newOptionsSync = function () { var options = this.getLibrary().tox_options_new(ref.NULL); return options.deref(); }; @@ -579,13 +529,12 @@ Tox.prototype.newOptionsSync = function() { * @param {(Buffer|String)} publicKey * @param {Tox~errorCallback} [callback] */ -Tox.prototype.bootstrap = function(address, port, publicKey, callback) { +Tox.prototype.bootstrap = function (address, port, publicKey, callback) { this._performBootstrap({ - api : - this.getLibrary().tox_bootstrap.async.bind(undefined, this.getHandle()), - args : [ address, port, publicKey ], - async : true, - callback : callback, + api: this.getLibrary().tox_bootstrap.async.bind(undefined, this.getHandle()), + args: [address, port, publicKey], + async: true, + callback: callback, }); }; @@ -596,11 +545,11 @@ Tox.prototype.bootstrap = function(address, port, publicKey, callback) { * @param {(Buffer|String)} publicKey * @throws Error if tox_bootstrap errors or returns false */ -Tox.prototype.bootstrapSync = function(address, port, publicKey) { +Tox.prototype.bootstrapSync = function (address, port, publicKey) { this._performBootstrap({ - api : this.getLibrary().tox_bootstrap.bind(undefined, this.getHandle()), - args : [ address, port, publicKey ], - async : false, + api: this.getLibrary().tox_bootstrap.bind(undefined, this.getHandle()), + args: [address, port, publicKey], + async: false, }); }; @@ -611,13 +560,12 @@ Tox.prototype.bootstrapSync = function(address, port, publicKey) { * @param {(Buffer|String)} publicKey * @param {Tox~errorCallback} [callback] */ -Tox.prototype.addTCPRelay = function(address, port, publicKey, callback) { +Tox.prototype.addTCPRelay = function (address, port, publicKey, callback) { this._performBootstrap({ - api : this.getLibrary().tox_add_tcp_relay.async.bind(undefined, - this.getHandle()), - args : [ address, port, publicKey ], - async : true, - callback : callback, + api: this.getLibrary().tox_add_tcp_relay.async.bind(undefined, this.getHandle()), + args: [address, port, publicKey], + async: true, + callback: callback, }); }; @@ -628,11 +576,11 @@ Tox.prototype.addTCPRelay = function(address, port, publicKey, callback) { * @param {(Buffer|String)} publicKey * @throws Error if tox_add_tcp_relay errors or returns false */ -Tox.prototype.addTCPRelaySync = function(address, port, publicKey) { +Tox.prototype.addTCPRelaySync = function (address, port, publicKey) { this._performBootstrap({ - api : this.getLibrary().tox_add_tcp_relay.bind(undefined, this.getHandle()), - args : [ address, port, publicKey ], - async : false, + api: this.getLibrary().tox_add_tcp_relay.bind(undefined, this.getHandle()), + args: [address, port, publicKey], + async: false, }); }; @@ -640,7 +588,7 @@ Tox.prototype.addTCPRelaySync = function(address, port, publicKey) { * Asynchronous tox_iteration_interval(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.iterationInterval = function(callback) { +Tox.prototype.iterationInterval = function (callback) { if (!this._checkHandle(callback)) { return; } @@ -652,7 +600,7 @@ Tox.prototype.iterationInterval = function(callback) { * Synchronous tox_iteration_interval(3). * @return {Number} milliseconds until the next tox_iterate should occur */ -Tox.prototype.iterationIntervalSync = function() { +Tox.prototype.iterationIntervalSync = function () { this._checkHandleSync(); return this.getLibrary().tox_iteration_interval(this.getHandle()); }; @@ -661,7 +609,7 @@ Tox.prototype.iterationIntervalSync = function() { * Asynchronous tox_iterate(3). * @param {Tox~errorCallback} [callback] */ -Tox.prototype.iterate = function(callback) { +Tox.prototype.iterate = function (callback) { if (!this._checkHandle(callback)) { return; } @@ -672,7 +620,7 @@ Tox.prototype.iterate = function(callback) { /** * Synchronous tox_iterate(3). */ -Tox.prototype.iterateSync = function() { +Tox.prototype.iterateSync = function () { this._checkHandleSync(); this.getLibrary().tox_iterate(this.getHandle()); }; @@ -681,14 +629,13 @@ Tox.prototype.iterateSync = function() { * Asynchronous tox_self_get_address(3). * @param {Tox~dataCallback} [callback] */ -Tox.prototype.getAddress = function(callback) { +Tox.prototype.getAddress = function (callback) { this._performGetter({ - api : this.getLibrary().tox_self_get_address.async.bind(undefined, - this.getHandle()), - format : "raw", - size : consts.TOX_FRIEND_ADDRESS_SIZE, - async : true, - callback : callback, + api: this.getLibrary().tox_self_get_address.async.bind(undefined, this.getHandle()), + format: "raw", + size: consts.TOX_FRIEND_ADDRESS_SIZE, + async: true, + callback: callback, }); }; @@ -696,12 +643,11 @@ Tox.prototype.getAddress = function(callback) { * Synchronous tox_self_get_address(3). * @return {Buffer} address */ -Tox.prototype.getAddressSync = function() { +Tox.prototype.getAddressSync = function () { return this._performGetter({ - api : this.getLibrary().tox_self_get_address.bind(undefined, - this.getHandle()), - format : "raw", - size : consts.TOX_FRIEND_ADDRESS_SIZE, + api: this.getLibrary().tox_self_get_address.bind(undefined, this.getHandle()), + format: "raw", + size: consts.TOX_FRIEND_ADDRESS_SIZE, }); }; @@ -709,12 +655,11 @@ Tox.prototype.getAddressSync = function() { * Asynchronous tox_self_get_connection_status(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getConnectionStatus = function(callback) { +Tox.prototype.getConnectionStatus = function (callback) { this._performNumberGetter({ - api : this.getLibrary().tox_self_get_connection_status.async.bind( - undefined, this.getHandle()), - async : true, - callback : callback, + api: this.getLibrary().tox_self_get_connection_status.async.bind(undefined, this.getHandle()), + async: true, + callback: callback, }); }; @@ -722,10 +667,9 @@ Tox.prototype.getConnectionStatus = function(callback) { * Synchronous tox_self_get_connection_status(3). * @return {Number} connection status */ -Tox.prototype.getConnectionStatusSync = function() { +Tox.prototype.getConnectionStatusSync = function () { return this._performNumberGetter({ - api : this.getLibrary().tox_self_get_connection_status.bind( - undefined, this.getHandle()), + api: this.getLibrary().tox_self_get_connection_status.bind(undefined, this.getHandle()), }); }; @@ -734,22 +678,20 @@ Tox.prototype.getConnectionStatusSync = function() { * @param {Number} nospam * @param {Tox~errorCallback} [callback] */ -Tox.prototype.setNospam = function(nospam, callback) { - if (!this._checkHandle(callback)) - return; - this.getLibrary().tox_self_set_nospam.async(this.getHandle(), nospam, - function(err) { - if (callback) { - callback(err); - } - }); +Tox.prototype.setNospam = function (nospam, callback) { + if (!this._checkHandle(callback)) return; + this.getLibrary().tox_self_set_nospam.async(this.getHandle(), nospam, function (err) { + if (callback) { + callback(err); + } + }); }; /** * Synchronous tox_self_set_nospam(3). * @param {Number} nospam */ -Tox.prototype.setNospamSync = function(nospam) { +Tox.prototype.setNospamSync = function (nospam) { this._checkHandleSync(); this.getLibrary().tox_self_set_nospam(this.getHandle(), nospam); }; @@ -758,22 +700,20 @@ Tox.prototype.setNospamSync = function(nospam) { * Asynchronous tox_self_get_nospam(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getNospam = function(callback) { - if (!this._checkHandle(callback)) - return; - this.getLibrary().tox_self_get_nospam.async(this.getHandle(), - function(err, nospam) { - if (callback) { - callback(err, nospam); - } - }); +Tox.prototype.getNospam = function (callback) { + if (!this._checkHandle(callback)) return; + this.getLibrary().tox_self_get_nospam.async(this.getHandle(), function (err, nospam) { + if (callback) { + callback(err, nospam); + } + }); }; /** * Synchronous tox_self_get_nospam(3). * @return {Number} nospam */ -Tox.prototype.getNospamSync = function() { +Tox.prototype.getNospamSync = function () { this._checkHandleSync(); return this.getLibrary().tox_self_get_nospam(this.getHandle()); }; @@ -782,14 +722,13 @@ Tox.prototype.getNospamSync = function() { * Asynchronous tox_self_get_public_key(3). * @param {Tox~dataCallback} [callback] */ -Tox.prototype.getPublicKey = function(callback) { +Tox.prototype.getPublicKey = function (callback) { this._performGetter({ - api : this.getLibrary().tox_self_get_public_key.async.bind( - undefined, this.getHandle()), - format : "raw", - size : consts.TOX_PUBLIC_KEY_SIZE, - async : true, - callback : callback, + api: this.getLibrary().tox_self_get_public_key.async.bind(undefined, this.getHandle()), + format: "raw", + size: consts.TOX_PUBLIC_KEY_SIZE, + async: true, + callback: callback, }); }; @@ -797,12 +736,11 @@ Tox.prototype.getPublicKey = function(callback) { * Synchronous tox_self_get_public_key(3). * @return {Buffer} public key */ -Tox.prototype.getPublicKeySync = function() { +Tox.prototype.getPublicKeySync = function () { return this._performGetter({ - api : this.getLibrary().tox_self_get_public_key.bind(undefined, - this.getHandle()), - format : "raw", - size : consts.TOX_PUBLIC_KEY_SIZE, + api: this.getLibrary().tox_self_get_public_key.bind(undefined, this.getHandle()), + format: "raw", + size: consts.TOX_PUBLIC_KEY_SIZE, }); }; @@ -810,14 +748,13 @@ Tox.prototype.getPublicKeySync = function() { * Asynchronous tox_self_get_secret_key(3). * @param {Tox~dataCallback} [callback] */ -Tox.prototype.getSecretKey = function(callback) { +Tox.prototype.getSecretKey = function (callback) { this._performGetter({ - api : this.getLibrary().tox_self_get_secret_key.async.bind( - undefined, this.getHandle()), - format : "raw", - size : consts.TOX_PUBLIC_KEY_SIZE, - async : true, - callback : callback, + api: this.getLibrary().tox_self_get_secret_key.async.bind(undefined, this.getHandle()), + format: "raw", + size: consts.TOX_PUBLIC_KEY_SIZE, + async: true, + callback: callback, }); }; @@ -825,12 +762,11 @@ Tox.prototype.getSecretKey = function(callback) { * Synchronous tox_self_get_secret_key(3). * @return {Buffer} secret key */ -Tox.prototype.getSecretKeySync = function() { +Tox.prototype.getSecretKeySync = function () { return this._performGetter({ - api : this.getLibrary().tox_self_get_secret_key.bind(undefined, - this.getHandle()), - format : "raw", - size : consts.TOX_SECRET_KEY_SIZE, + api: this.getLibrary().tox_self_get_secret_key.bind(undefined, this.getHandle()), + format: "raw", + size: consts.TOX_SECRET_KEY_SIZE, }); }; @@ -839,14 +775,13 @@ Tox.prototype.getSecretKeySync = function() { * @param {String} name * @param {Tox~errorCallback} [callback] */ -Tox.prototype.setName = function(name, callback) { +Tox.prototype.setName = function (name, callback) { this._performSetter({ - api : this.getLibrary().tox_self_set_name.async.bind(undefined, - this.getHandle()), - data : name, - error : errors.setInfo, - async : true, - callback : callback, + api: this.getLibrary().tox_self_set_name.async.bind(undefined, this.getHandle()), + data: name, + error: errors.setInfo, + async: true, + callback: callback, }); }; @@ -854,11 +789,11 @@ Tox.prototype.setName = function(name, callback) { * Synchronous tox_self_set_name(3). * @param {String} name */ -Tox.prototype.setNameSync = function(name) { +Tox.prototype.setNameSync = function (name) { this._performSetter({ - api : this.getLibrary().tox_self_set_name.bind(undefined, this.getHandle()), - error : errors.setInfo, - data : name, + api: this.getLibrary().tox_self_set_name.bind(undefined, this.getHandle()), + error: errors.setInfo, + data: name, }); }; @@ -866,12 +801,11 @@ Tox.prototype.setNameSync = function(name) { * Asynchronous tox_self_get_name_size(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getNameSize = function(callback) { +Tox.prototype.getNameSize = function (callback) { this._performSizeGetter({ - api : this.getLibrary().tox_self_get_name_size.async.bind(undefined, - this.getHandle()), - async : true, - callback : callback, + api: this.getLibrary().tox_self_get_name_size.async.bind(undefined, this.getHandle()), + async: true, + callback: callback, }); }; @@ -879,10 +813,9 @@ Tox.prototype.getNameSize = function(callback) { * Synchronous tox_self_get_name_size(3). * @return {Number} name size */ -Tox.prototype.getNameSizeSync = function() { +Tox.prototype.getNameSizeSync = function () { return this._performSizeGetter({ - api : this.getLibrary().tox_self_get_name_size.bind(undefined, - this.getHandle()), + api: this.getLibrary().tox_self_get_name_size.bind(undefined, this.getHandle()), }); }; @@ -890,14 +823,13 @@ Tox.prototype.getNameSizeSync = function() { * Asynchronous tox_self_get_name(3). * @param {Tox~stringCallback} [callback] */ -Tox.prototype.getName = function(callback) { +Tox.prototype.getName = function (callback) { this._performGetter({ - api : this.getLibrary().tox_self_get_name.async.bind(undefined, - this.getHandle()), - format : "string", - size : Tox.prototype.getNameSize.bind(this), - async : true, - callback : callback, + api: this.getLibrary().tox_self_get_name.async.bind(undefined, this.getHandle()), + format: "string", + size: Tox.prototype.getNameSize.bind(this), + async: true, + callback: callback, }); }; @@ -905,11 +837,11 @@ Tox.prototype.getName = function(callback) { * Synchronous tox_self_get_name(3). * @return {String} name */ -Tox.prototype.getNameSync = function() { +Tox.prototype.getNameSync = function () { return this._performGetter({ - api : this.getLibrary().tox_self_get_name.bind(undefined, this.getHandle()), - format : "string", - size : Tox.prototype.getNameSizeSync.bind(this), + api: this.getLibrary().tox_self_get_name.bind(undefined, this.getHandle()), + format: "string", + size: Tox.prototype.getNameSizeSync.bind(this), }); }; @@ -918,14 +850,13 @@ Tox.prototype.getNameSync = function() { * @param {String} status_message * @param {Tox~errorCallback} [callback] */ -Tox.prototype.setStatusMessage = function(statusMessage, callback) { +Tox.prototype.setStatusMessage = function (statusMessage, callback) { this._performSetter({ - api : this.getLibrary().tox_self_set_status_message.async.bind( - undefined, this.getHandle()), - data : statusMessage, - error : errors.setInfo, - async : true, - callback : callback, + api: this.getLibrary().tox_self_set_status_message.async.bind(undefined, this.getHandle()), + data: statusMessage, + error: errors.setInfo, + async: true, + callback: callback, }); }; @@ -933,12 +864,11 @@ Tox.prototype.setStatusMessage = function(statusMessage, callback) { * Synchronous tox_self_set_status_message(3). * @param {String} status_message */ -Tox.prototype.setStatusMessageSync = function(statusMessage) { +Tox.prototype.setStatusMessageSync = function (statusMessage) { this._performSetter({ - api : this.getLibrary().tox_self_set_status_message.bind(undefined, - this.getHandle()), - error : errors.setInfo, - data : statusMessage, + api: this.getLibrary().tox_self_set_status_message.bind(undefined, this.getHandle()), + error: errors.setInfo, + data: statusMessage, }); }; @@ -946,12 +876,11 @@ Tox.prototype.setStatusMessageSync = function(statusMessage) { * Asynchronous tox_self_get_status_message_size(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getStatusMessageSize = function(callback) { +Tox.prototype.getStatusMessageSize = function (callback) { this._performSizeGetter({ - api : this.getLibrary().tox_self_get_status_message_size.async.bind( - undefined, this.getHandle()), - async : true, - callback : callback, + api: this.getLibrary().tox_self_get_status_message_size.async.bind(undefined, this.getHandle()), + async: true, + callback: callback, }); }; @@ -959,10 +888,9 @@ Tox.prototype.getStatusMessageSize = function(callback) { * Synchronous tox_self_get_status_message_size(3). * @return {Number} status_message size */ -Tox.prototype.getStatusMessageSizeSync = function() { +Tox.prototype.getStatusMessageSizeSync = function () { return this._performSizeGetter({ - api : this.getLibrary().tox_self_get_status_message_size.bind( - undefined, this.getHandle()), + api: this.getLibrary().tox_self_get_status_message_size.bind(undefined, this.getHandle()), }); }; @@ -970,14 +898,13 @@ Tox.prototype.getStatusMessageSizeSync = function() { * Asynchronous tox_self_get_status_message(3). * @param {Tox~stringCallback} [callback] */ -Tox.prototype.getStatusMessage = function(callback) { +Tox.prototype.getStatusMessage = function (callback) { this._performGetter({ - api : this.getLibrary().tox_self_get_status_message.async.bind( - undefined, this.getHandle()), - format : "string", - size : Tox.prototype.getStatusMessageSize.bind(this), - async : true, - callback : callback, + api: this.getLibrary().tox_self_get_status_message.async.bind(undefined, this.getHandle()), + format: "string", + size: Tox.prototype.getStatusMessageSize.bind(this), + async: true, + callback: callback, }); }; @@ -985,12 +912,11 @@ Tox.prototype.getStatusMessage = function(callback) { * Synchronous tox_self_get_status_message(3). * @return {String} status message */ -Tox.prototype.getStatusMessageSync = function() { +Tox.prototype.getStatusMessageSync = function () { return this._performGetter({ - api : this.getLibrary().tox_self_get_status_message.bind(undefined, - this.getHandle()), - format : "string", - size : Tox.prototype.getStatusMessageSizeSync.bind(this), + api: this.getLibrary().tox_self_get_status_message.bind(undefined, this.getHandle()), + format: "string", + size: Tox.prototype.getStatusMessageSizeSync.bind(this), }); }; @@ -999,13 +925,12 @@ Tox.prototype.getStatusMessageSync = function() { * @param {Number} status * @param {Tox~errorCallback} [callback] */ -Tox.prototype.setStatus = function(status, callback) { +Tox.prototype.setStatus = function (status, callback) { this._performNumberSetter({ - api : this.getLibrary().tox_self_set_status.async.bind(undefined, - this.getHandle()), - value : status, - async : true, - callback : callback, + api: this.getLibrary().tox_self_set_status.async.bind(undefined, this.getHandle()), + value: status, + async: true, + callback: callback, }); }; @@ -1013,11 +938,10 @@ Tox.prototype.setStatus = function(status, callback) { * Synchronous tox_self_set_status(3). * @param {Number} status */ -Tox.prototype.setStatusSync = function(status) { +Tox.prototype.setStatusSync = function (status) { this._performNumberSetter({ - api : - this.getLibrary().tox_self_set_status.bind(undefined, this.getHandle()), - value : status, + api: this.getLibrary().tox_self_set_status.bind(undefined, this.getHandle()), + value: status, }); }; @@ -1025,12 +949,11 @@ Tox.prototype.setStatusSync = function(status) { * Asynchronous tox_self_get_status(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getStatus = function(callback) { +Tox.prototype.getStatus = function (callback) { this._performNumberGetter({ - api : this.getLibrary().tox_self_get_status.async.bind(undefined, - this.getHandle()), - async : true, - callback : callback, + api: this.getLibrary().tox_self_get_status.async.bind(undefined, this.getHandle()), + async: true, + callback: callback, }); }; @@ -1038,10 +961,9 @@ Tox.prototype.getStatus = function(callback) { * Synchronous tox_self_get_status(3). * @return {Number} status */ -Tox.prototype.getStatusSync = function() { +Tox.prototype.getStatusSync = function () { return this._performNumberGetter({ - api : - this.getLibrary().tox_self_get_status.bind(undefined, this.getHandle()), + api: this.getLibrary().tox_self_get_status.bind(undefined, this.getHandle()), }); }; @@ -1051,9 +973,8 @@ Tox.prototype.getStatusSync = function() { * @param {(Buffer|String)} message * @param {Tox~numberCallback} [callback] */ -Tox.prototype.addFriend = function(address, message, callback) { - if (!this._checkHandle(callback)) - return; +Tox.prototype.addFriend = function (address, message, callback) { + if (!this._checkHandle(callback)) return; address = fromHex(address); if (_.isString(message)) { @@ -1062,15 +983,19 @@ Tox.prototype.addFriend = function(address, message, callback) { var eptr = ref.alloc(TOX_ERR_FRIEND_ADD); this.getLibrary().tox_friend_add.async( - this.getHandle(), address, message, size_t(message.length), eptr, - function(err, friend) { - var terr = errors.friendAdd(eptr.deref()); - if (!err && terr) - err = terr; - if (callback) { - callback(err, friend); - } - }); + this.getHandle(), + address, + message, + size_t(message.length), + eptr, + function (err, friend) { + var terr = errors.friendAdd(eptr.deref()); + if (!err && terr) err = terr; + if (callback) { + callback(err, friend); + } + } + ); }; /** @@ -1079,7 +1004,7 @@ Tox.prototype.addFriend = function(address, message, callback) { * @param {(Buffer|String)} message * @return {Number} friend number */ -Tox.prototype.addFriendSync = function(address, message) { +Tox.prototype.addFriendSync = function (address, message) { this._checkHandleSync(); address = fromHex(address); @@ -1088,11 +1013,15 @@ Tox.prototype.addFriendSync = function(address, message) { } var eptr = ref.alloc(TOX_ERR_FRIEND_ADD), - friend = this.getLibrary().tox_friend_add( - this.getHandle(), address, message, size_t(message.length), eptr), - err = errors.friendAdd(eptr.deref()); - if (err) - throw err; + friend = this.getLibrary().tox_friend_add( + this.getHandle(), + address, + message, + size_t(message.length), + eptr + ), + err = errors.friendAdd(eptr.deref()); + if (err) throw err; return friend; }; @@ -1101,20 +1030,20 @@ Tox.prototype.addFriendSync = function(address, message) { * @param {(Buffer|String)} publicKey * @param {Tox~numberCallback} [callback] */ -Tox.prototype.addFriendNoRequest = function(publicKey, callback) { - if (!this._checkHandle(callback)) - return; +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); + } + }); }; /** @@ -1122,15 +1051,13 @@ Tox.prototype.addFriendNoRequest = function(publicKey, callback) { * @param {(Buffer|String)} publicKey * @return {Number} friend number */ -Tox.prototype.addFriendNoRequestSync = function(publicKey) { +Tox.prototype.addFriendNoRequestSync = function (publicKey) { this._checkHandleSync(); publicKey = fromHex(publicKey); var eptr = ref.alloc(TOX_ERR_FRIEND_ADD), - friend = this.getLibrary().tox_friend_add_norequest(this.getHandle(), - publicKey, eptr), - err = errors.friendAdd(eptr.deref()); - if (err) - throw err; + friend = this.getLibrary().tox_friend_add_norequest(this.getHandle(), publicKey, eptr), + err = errors.friendAdd(eptr.deref()); + if (err) throw err; return friend; }; @@ -1139,37 +1066,33 @@ Tox.prototype.addFriendNoRequestSync = function(publicKey) { * @param {Number} friend * @param {Tox~errorCallback} [callback] */ -Tox.prototype.deleteFriend = function(friend, callback) { - if (!this._checkHandle(callback)) - return; +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); + } + }); }; /** * Synchronous tox_friend_delete(3). * @param {Number} friend */ -Tox.prototype.deleteFriendSync = function(friend) { +Tox.prototype.deleteFriendSync = function (friend) { this._checkHandle(); var eptr = ref.alloc(TOX_ERR_FRIEND_DELETE), - success = - this.getLibrary().tox_friend_delete(this.getHandle(), friend, eptr); + success = this.getLibrary().tox_friend_delete(this.getHandle(), friend, eptr); var err = errors.friendDelete(eptr.deref()); - if (err) - throw err; - if (!success) - throw errors.unsuccessful(); + if (err) throw err; + if (!success) throw errors.unsuccessful(); }; /** @@ -1177,20 +1100,20 @@ Tox.prototype.deleteFriendSync = function(friend) { * @param {(Buffer|String)} publicKey * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getFriendByPublicKey = function(publicKey, callback) { - if (!this._checkHandle(callback)) - return; +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); + } + }); }; /** @@ -1198,15 +1121,13 @@ Tox.prototype.getFriendByPublicKey = function(publicKey, callback) { * @param {(Buffer|String)} publicKey * @return {Number} friend number */ -Tox.prototype.getFriendByPublicKeySync = function(publicKey) { +Tox.prototype.getFriendByPublicKeySync = function (publicKey) { this._checkHandle(); publicKey = fromHex(publicKey); var eptr = ref.alloc(TOX_ERR_FRIEND_BY_PUBLIC_KEY), - friend = this.getLibrary().tox_friend_by_public_key(this.getHandle(), - publicKey, eptr); + friend = this.getLibrary().tox_friend_by_public_key(this.getHandle(), publicKey, eptr); var err = errors.friendByPublicKey(eptr.deref()); - if (err) - throw err; + if (err) throw err; return friend; }; @@ -1215,20 +1136,23 @@ Tox.prototype.getFriendByPublicKeySync = function(publicKey) { * @param {Number} friend * @param {Tox~dataCallback} [callback] */ -Tox.prototype.getFriendPublicKey = function(friend, callback) { - if (!this._checkHandle(callback)) - return; +Tox.prototype.getFriendPublicKey = function (friend, callback) { + if (!this._checkHandle(callback)) return; var eptr = ref.alloc(TOX_ERR_FRIEND_GET_PUBLIC_KEY), - buffer = Buffer.alloc(consts.TOX_PUBLIC_KEY_SIZE); + buffer = Buffer.alloc(consts.TOX_PUBLIC_KEY_SIZE); this.getLibrary().tox_friend_get_public_key.async( - this.getHandle(), friend, buffer, eptr, function(err, friend) { - var terr = errors.friendGetPublicKey(eptr.deref()); - if (!err && terr) - err = terr; - if (callback) { - callback(err, buffer); - } - }); + this.getHandle(), + friend, + buffer, + eptr, + function (err, friend) { + var terr = errors.friendGetPublicKey(eptr.deref()); + if (!err && terr) err = terr; + if (callback) { + callback(err, buffer); + } + } + ); }; /** @@ -1236,17 +1160,14 @@ Tox.prototype.getFriendPublicKey = function(friend, callback) { * @param {Number} friend * @return {Buffer} public key */ -Tox.prototype.getFriendPublicKeySync = function(friend) { +Tox.prototype.getFriendPublicKeySync = function (friend) { this._checkHandle(); var eptr = ref.alloc(TOX_ERR_FRIEND_GET_PUBLIC_KEY), - buffer = Buffer.alloc(consts.TOX_PUBLIC_KEY_SIZE), - success = this.getLibrary().tox_friend_get_public_key( - this.getHandle(), friend, buffer, eptr); + buffer = Buffer.alloc(consts.TOX_PUBLIC_KEY_SIZE), + success = this.getLibrary().tox_friend_get_public_key(this.getHandle(), friend, buffer, eptr); var err = errors.friendGetPublicKey(eptr.deref()); - if (err) - throw err; - if (!success) - throw errors.unsuccessful(); + if (err) throw err; + if (!success) throw errors.unsuccessful(); return buffer; }; @@ -1255,15 +1176,13 @@ Tox.prototype.getFriendPublicKeySync = function(friend) { * @param {Number} friend * @param {Tox~booleanCallback} [callback] */ -Tox.prototype.hasFriend = function(friend, callback) { - if (!this._checkHandle(callback)) - return; - this.getLibrary().tox_friend_exists.async(this.getHandle(), friend, - function(err, exists) { - if (callback) { - callback(err, exists); - } - }); +Tox.prototype.hasFriend = function (friend, callback) { + if (!this._checkHandle(callback)) return; + this.getLibrary().tox_friend_exists.async(this.getHandle(), friend, function (err, exists) { + if (callback) { + callback(err, exists); + } + }); }; /** @@ -1271,7 +1190,7 @@ Tox.prototype.hasFriend = function(friend, callback) { * @param {Number} friend * @return {Boolean} true if has friend, false if not */ -Tox.prototype.hasFriendSync = function(friend) { +Tox.prototype.hasFriendSync = function (friend) { this._checkHandleSync(); return this.getLibrary().tox_friend_exists(this.getHandle(), friend); }; @@ -1285,24 +1204,23 @@ Tox.prototype.hasFriendSync = function(friend) { * doubles and "considered accurate up to 15 digits" * www.w3schools.com/js/js_numbers.asp */ -Tox.prototype.getFriendLastOnline = function(friend, callback) { - if (!this._checkHandle(callback)) - return; +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); + } + }); }; /** @@ -1311,14 +1229,12 @@ Tox.prototype.getFriendLastOnline = function(friend, callback) { * @return {Date} last online date, may be backed by NaN * @note See note for Tox#getFriendLastOnline() */ -Tox.prototype.getFriendLastOnlineSync = function(friend) { +Tox.prototype.getFriendLastOnlineSync = function (friend) { this._checkHandle(); var eptr = ref.alloc(TOX_ERR_FRIEND_GET_LAST_ONLINE), - timeval = this.getLibrary().tox_friend_get_last_online(this.getHandle(), - friend, eptr); + timeval = this.getLibrary().tox_friend_get_last_online(this.getHandle(), friend, eptr); var err = errors.friendGetLastOnline(eptr.deref()); - if (err) - throw err; + if (err) throw err; return getDateFromUInt64(timeval); }; @@ -1326,12 +1242,11 @@ Tox.prototype.getFriendLastOnlineSync = function(friend) { * Asynchronous tox_self_get_friend_list_size(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getFriendListSize = function(callback) { +Tox.prototype.getFriendListSize = function (callback) { this._performSizeGetter({ - api : this.getLibrary().tox_self_get_friend_list_size.async.bind( - undefined, this.getHandle()), - async : true, - callback : callback, + api: this.getLibrary().tox_self_get_friend_list_size.async.bind(undefined, this.getHandle()), + async: true, + callback: callback, }); }; @@ -1339,10 +1254,9 @@ Tox.prototype.getFriendListSize = function(callback) { * Synchronous tox_self_get_friend_list_size(3). * @return {Number} friend count */ -Tox.prototype.getFriendListSizeSync = function() { +Tox.prototype.getFriendListSizeSync = function () { return this._performSizeGetter({ - api : this.getLibrary().tox_self_get_friend_list_size.bind( - undefined, this.getHandle()), + api: this.getLibrary().tox_self_get_friend_list_size.bind(undefined, this.getHandle()), }); }; @@ -1352,27 +1266,26 @@ Tox.prototype.getFriendListSizeSync = function() { * @note Between getting the size and calling tox_self_get_friend_list, * we may have another friend leading to an overflow. */ -Tox.prototype.getFriendList = function(callback) { - if (!this._checkHandle(callback)) - return; +Tox.prototype.getFriendList = function (callback) { + if (!this._checkHandle(callback)) return; var _this = this; - this.getFriendListSize(function(err, size) { + this.getFriendListSize(function (err, size) { if (!err) { var arr = new RefArray("uint32")(size); - _this.getLibrary().tox_self_get_friend_list.async( - _this.getHandle(), arr.buffer, function(err) { - // RefArray -> Javascript Array - // @todo Make this RefArrayToArray()? - var nums = []; - if (!err) { - for (var i = 0; i < arr.length; i++) - nums.push(arr[i]); - } - - if (callback) { - callback(err, nums); - } - }); + _this + .getLibrary() + .tox_self_get_friend_list.async(_this.getHandle(), arr.buffer, function (err) { + // RefArray -> Javascript Array + // @todo Make this RefArrayToArray()? + var nums = []; + if (!err) { + for (var i = 0; i < arr.length; i++) nums.push(arr[i]); + } + + if (callback) { + callback(err, nums); + } + }); } else if (callback) { callback(err); } @@ -1384,15 +1297,15 @@ Tox.prototype.getFriendList = function(callback) { * @return {Number[]} array of friend numbers * @note See overflow note for Tox#getFriendList() */ -Tox.prototype.getFriendListSync = function() { +Tox.prototype.getFriendListSync = function () { this._checkHandleSync(); - var size = this.getFriendListSizeSync(), arr = new RefArray("uint32")(size); + var size = this.getFriendListSizeSync(), + arr = new RefArray("uint32")(size); this.getLibrary().tox_self_get_friend_list(this.getHandle(), arr.buffer); // RefArray -> Javascript Array var nums = []; - for (var i = 0; i < arr.length; i++) - nums.push(arr[i]); + for (var i = 0; i < arr.length; i++) nums.push(arr[i]); return nums; }; @@ -1402,13 +1315,12 @@ Tox.prototype.getFriendListSync = function() { * @param {Number} friend * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getFriendNameSize = function(friend, callback) { +Tox.prototype.getFriendNameSize = function (friend, callback) { this._performFriendNumberGetter({ - api : this.getLibrary().tox_friend_get_name_size.async.bind( - undefined, this.getHandle()), - friend : friend, - async : true, - callback : callback, + api: this.getLibrary().tox_friend_get_name_size.async.bind(undefined, this.getHandle()), + friend: friend, + async: true, + callback: callback, }); }; @@ -1417,11 +1329,10 @@ Tox.prototype.getFriendNameSize = function(friend, callback) { * @param {Number} friend * @return {Number} name size */ -Tox.prototype.getFriendNameSizeSync = function(friend) { +Tox.prototype.getFriendNameSizeSync = function (friend) { return this._performFriendNumberGetter({ - api : this.getLibrary().tox_friend_get_name_size.bind(undefined, - this.getHandle()), - friend : friend, + api: this.getLibrary().tox_friend_get_name_size.bind(undefined, this.getHandle()), + friend: friend, }); }; @@ -1430,15 +1341,14 @@ Tox.prototype.getFriendNameSizeSync = function(friend) { * @param {Number} friend * @param {Tox~stringCallback} [callback] */ -Tox.prototype.getFriendName = function(friend, callback) { +Tox.prototype.getFriendName = function (friend, callback) { this._performFriendGetter({ - api : this.getLibrary().tox_friend_get_name.async.bind(undefined, - this.getHandle()), - format : "string", - friend : friend, - size : consts.TOX_MAX_NAME_LENGTH, - async : true, - callback : callback, + api: this.getLibrary().tox_friend_get_name.async.bind(undefined, this.getHandle()), + format: "string", + friend: friend, + size: consts.TOX_MAX_NAME_LENGTH, + async: true, + callback: callback, }); }; @@ -1447,13 +1357,12 @@ Tox.prototype.getFriendName = function(friend, callback) { * @param {Number} friend * @return {String} friend name */ -Tox.prototype.getFriendNameSync = function(friend) { +Tox.prototype.getFriendNameSync = function (friend) { return this._performFriendGetter({ - api : - this.getLibrary().tox_friend_get_name.bind(undefined, this.getHandle()), - format : "string", - friend : friend, - size : consts.TOX_MAX_NAME_LENGTH, + api: this.getLibrary().tox_friend_get_name.bind(undefined, this.getHandle()), + format: "string", + friend: friend, + size: consts.TOX_MAX_NAME_LENGTH, }); }; @@ -1462,13 +1371,15 @@ Tox.prototype.getFriendNameSync = function(friend) { * @param {Number} friend * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getFriendStatusMessageSize = function(friend, callback) { +Tox.prototype.getFriendStatusMessageSize = function (friend, callback) { this._performFriendNumberGetter({ - api : this.getLibrary().tox_friend_get_status_message_size.async.bind( - undefined, this.getHandle()), - friend : friend, - async : true, - callback : callback, + api: this.getLibrary().tox_friend_get_status_message_size.async.bind( + undefined, + this.getHandle() + ), + friend: friend, + async: true, + callback: callback, }); }; @@ -1477,11 +1388,10 @@ Tox.prototype.getFriendStatusMessageSize = function(friend, callback) { * @param {Number} friend * @return {Number} status message size */ -Tox.prototype.getFriendStatusMessageSizeSync = function(friend) { +Tox.prototype.getFriendStatusMessageSizeSync = function (friend) { return this._performFriendNumberGetter({ - api : this.getLibrary().tox_friend_get_status_message_size.bind( - undefined, this.getHandle()), - friend : friend, + api: this.getLibrary().tox_friend_get_status_message_size.bind(undefined, this.getHandle()), + friend: friend, }); }; @@ -1490,15 +1400,14 @@ Tox.prototype.getFriendStatusMessageSizeSync = function(friend) { * @param {Number} friend * @param {Tox~stringCallback} [callback] */ -Tox.prototype.getFriendStatusMessage = function(friend, callback) { +Tox.prototype.getFriendStatusMessage = function (friend, callback) { this._performFriendGetter({ - api : this.getLibrary().tox_friend_get_status_message.async.bind( - undefined, this.getHandle()), - format : "string", - friend : friend, - size : consts.TOX_MAX_STATUS_MESSAGE_LENGTH, - async : true, - callback : callback, + api: this.getLibrary().tox_friend_get_status_message.async.bind(undefined, this.getHandle()), + format: "string", + friend: friend, + size: consts.TOX_MAX_STATUS_MESSAGE_LENGTH, + async: true, + callback: callback, }); }; @@ -1507,13 +1416,12 @@ Tox.prototype.getFriendStatusMessage = function(friend, callback) { * @param {Number} friend * @return {String} friend status message */ -Tox.prototype.getFriendStatusMessageSync = function(friend) { +Tox.prototype.getFriendStatusMessageSync = function (friend) { return this._performFriendGetter({ - api : this.getLibrary().tox_friend_get_status_message.bind( - undefined, this.getHandle()), - format : "string", - friend : friend, - size : consts.TOX_MAX_STATUS_MESSAGE_LENGTH, + api: this.getLibrary().tox_friend_get_status_message.bind(undefined, this.getHandle()), + format: "string", + friend: friend, + size: consts.TOX_MAX_STATUS_MESSAGE_LENGTH, }); }; @@ -1522,13 +1430,12 @@ Tox.prototype.getFriendStatusMessageSync = function(friend) { * @param {Number} friend * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getFriendStatus = function(friend, callback) { +Tox.prototype.getFriendStatus = function (friend, callback) { this._performFriendNumberGetter({ - api : this.getLibrary().tox_friend_get_status.async.bind(undefined, - this.getHandle()), - friend : friend, - async : true, - callback : callback, + api: this.getLibrary().tox_friend_get_status.async.bind(undefined, this.getHandle()), + friend: friend, + async: true, + callback: callback, }); }; @@ -1537,11 +1444,10 @@ Tox.prototype.getFriendStatus = function(friend, callback) { * @param {Number} friend * @return {Number} friend status */ -Tox.prototype.getFriendStatusSync = function(friend) { +Tox.prototype.getFriendStatusSync = function (friend) { return this._performFriendNumberGetter({ - api : this.getLibrary().tox_friend_get_status.bind(undefined, - this.getHandle()), - friend : friend, + api: this.getLibrary().tox_friend_get_status.bind(undefined, this.getHandle()), + friend: friend, }); }; @@ -1550,13 +1456,12 @@ Tox.prototype.getFriendStatusSync = function(friend) { * @param {Number} friend * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getFriendConnectionStatus = function(friend, callback) { +Tox.prototype.getFriendConnectionStatus = function (friend, callback) { this._performFriendNumberGetter({ - api : this.getLibrary().tox_friend_get_connection_status.async.bind( - undefined, this.getHandle()), - friend : friend, - async : true, - callback : callback, + api: this.getLibrary().tox_friend_get_connection_status.async.bind(undefined, this.getHandle()), + friend: friend, + async: true, + callback: callback, }); }; @@ -1565,11 +1470,10 @@ Tox.prototype.getFriendConnectionStatus = function(friend, callback) { * @param {Number} friend * @return {Number} friend status */ -Tox.prototype.getFriendConnectionStatusSync = function(friend) { +Tox.prototype.getFriendConnectionStatusSync = function (friend) { return this._performFriendNumberGetter({ - api : this.getLibrary().tox_friend_get_connection_status.bind( - undefined, this.getHandle()), - friend : friend, + api: this.getLibrary().tox_friend_get_connection_status.bind(undefined, this.getHandle()), + friend: friend, }); }; @@ -1577,12 +1481,11 @@ Tox.prototype.getFriendConnectionStatusSync = function(friend) { * Asynchronous tox_self_get_udp_port(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getUdpPort = function(callback) { +Tox.prototype.getUdpPort = function (callback) { this._performGetPort({ - api : this.getLibrary().tox_self_get_udp_port.async.bind(undefined, - this.getHandle()), - async : true, - callback : callback, + api: this.getLibrary().tox_self_get_udp_port.async.bind(undefined, this.getHandle()), + async: true, + callback: callback, }); }; @@ -1591,10 +1494,9 @@ Tox.prototype.getUdpPort = function(callback) { * @returns {Number} Port * @throws Error if TOX_ERR_GET_PORT set. */ -Tox.prototype.getUdpPortSync = function() { +Tox.prototype.getUdpPortSync = function () { return this._performGetPort({ - api : this.getLibrary().tox_self_get_udp_port.bind(undefined, - this.getHandle()), + api: this.getLibrary().tox_self_get_udp_port.bind(undefined, this.getHandle()), }); }; @@ -1602,12 +1504,11 @@ Tox.prototype.getUdpPortSync = function() { * Asynchronous tox_self_get_tcp_port(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getTcpPort = function(callback) { +Tox.prototype.getTcpPort = function (callback) { this._performGetPort({ - api : this.getLibrary().tox_self_get_tcp_port.async.bind(undefined, - this.getHandle()), - async : true, - callback : callback, + api: this.getLibrary().tox_self_get_tcp_port.async.bind(undefined, this.getHandle()), + async: true, + callback: callback, }); }; @@ -1616,10 +1517,9 @@ Tox.prototype.getTcpPort = function(callback) { * @returns {Number} Port * @throws Error if TOX_ERR_GET_PORT set. */ -Tox.prototype.getTcpPortSync = function() { +Tox.prototype.getTcpPortSync = function () { return this._performGetPort({ - api : this.getLibrary().tox_self_get_tcp_port.bind(undefined, - this.getHandle()), + api: this.getLibrary().tox_self_get_tcp_port.bind(undefined, this.getHandle()), }); }; @@ -1629,21 +1529,20 @@ Tox.prototype.getTcpPortSync = function() { * @param {Boolean} typing * @param {Tox~errorCallback} [callback] */ -Tox.prototype.setTyping = function(friend, typing, callback) { - if (!this._checkHandle(callback)) - return; +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); + } + }); }; /** @@ -1651,17 +1550,14 @@ Tox.prototype.setTyping = function(friend, typing, callback) { * @param {Number} friend * @param {Boolean} typing */ -Tox.prototype.setTypingSync = function(friend, typing) { +Tox.prototype.setTypingSync = function (friend, typing) { this._checkHandleSync(); var eptr = ref.alloc(TOX_ERR_SET_TYPING), - success = this.getLibrary().tox_self_set_typing(this.getHandle(), friend, - typing, eptr); + success = this.getLibrary().tox_self_set_typing(this.getHandle(), friend, typing, eptr); var err = errors.setTyping(eptr.deref()); - if (err) - throw err; - if (!success) - throw errors.unsuccessful(); + if (err) throw err; + if (!success) throw errors.unsuccessful(); }; /** @@ -1671,9 +1567,8 @@ Tox.prototype.setTypingSync = function(friend, typing) { * @param {(Boolean|Number|String)} [type] - If boolean, assumed isAction * @param {Tox~numberCallback} [callback] */ -Tox.prototype.sendFriendMessage = function(friend, message, type, callback) { - if (!this._checkHandle(callback)) - return; +Tox.prototype.sendFriendMessage = function (friend, message, type, callback) { + if (!this._checkHandle(callback)) return; // If #sendFriendMessage(friend, message, callback), use default type if (arguments.length === 3 && _.isFunction(type)) { @@ -1681,20 +1576,27 @@ Tox.prototype.sendFriendMessage = function(friend, message, type, callback) { type = undefined; } - var args = this._fixSendMessageArgs(friend, message, type), friend = args[0], - message = args[1], type = args[2], - eptr = ref.alloc(TOX_ERR_FRIEND_SEND_MESSAGE); + var args = this._fixSendMessageArgs(friend, message, type), + friend = args[0], + message = args[1], + type = args[2], + eptr = ref.alloc(TOX_ERR_FRIEND_SEND_MESSAGE); this.getLibrary().tox_friend_send_message.async( - this.getHandle(), friend, type, message, message.length, eptr, - function(err, mid) { - var terr = errors.friendSendMessage(eptr.deref()); - if (!err && terr) - err = terr; - if (callback) { - callback(err, mid); - } - }); + this.getHandle(), + friend, + type, + message, + message.length, + eptr, + function (err, mid) { + var terr = errors.friendSendMessage(eptr.deref()); + if (!err && terr) err = terr; + if (callback) { + callback(err, mid); + } + } + ); }; /** @@ -1704,18 +1606,25 @@ Tox.prototype.sendFriendMessage = function(friend, message, type, callback) { * @param {(Boolean|Number|String)} [type] - If boolean, assumed isAction * @return {Number} message id */ -Tox.prototype.sendFriendMessageSync = function(friend, message, type) { +Tox.prototype.sendFriendMessageSync = function (friend, message, type) { this._checkHandleSync(); - var args = this._fixSendMessageArgs(friend, message, type), friend = args[0], - message = args[1], type = args[2], - eptr = ref.alloc(TOX_ERR_FRIEND_SEND_MESSAGE); + var args = this._fixSendMessageArgs(friend, message, type), + friend = args[0], + message = args[1], + type = args[2], + eptr = ref.alloc(TOX_ERR_FRIEND_SEND_MESSAGE); var mid = this.getLibrary().tox_friend_send_message( - this.getHandle(), friend, type, message, message.length, eptr); + this.getHandle(), + friend, + type, + message, + message.length, + eptr + ); var err = errors.friendSendMessage(eptr.deref()); - if (err) - throw err; + if (err) throw err; return mid; }; @@ -1724,18 +1633,15 @@ Tox.prototype.sendFriendMessageSync = function(friend, message, type) { * @param {(Buffer|String)} data * @param {Tox~dataCallback} [callback] */ -Tox.prototype.hash = function(data, callback) { - if (_.isString(data)) - data = Buffer.from(data); +Tox.prototype.hash = function (data, callback) { + if (_.isString(data)) data = Buffer.from(data); var hash = Buffer.alloc(consts.TOX_HASH_LENGTH); - this.getLibrary().tox_hash.async(hash, data, data.length, - function(err, success) { - if (!err && !success) - err = errors.unsuccessful(); - if (callback) { - callback(err, hash); - } - }); + this.getLibrary().tox_hash.async(hash, data, data.length, function (err, success) { + if (!err && !success) err = errors.unsuccessful(); + if (callback) { + callback(err, hash); + } + }); }; /** @@ -1743,13 +1649,11 @@ Tox.prototype.hash = function(data, callback) { * @param {(Buffer|String)} data * @return {Buffer} hash */ -Tox.prototype.hashSync = function(data) { - if (_.isString(data)) - data = Buffer.from(data); +Tox.prototype.hashSync = function (data) { + if (_.isString(data)) data = Buffer.from(data); var hash = Buffer.alloc(consts.TOX_HASH_LENGTH), - success = this.getLibrary().tox_hash(hash, data, data.length); - if (!success) - throw errors.unsuccessful(); + success = this.getLibrary().tox_hash(hash, data, data.length); + if (!success) throw errors.unsuccessful(); return hash; }; @@ -1760,23 +1664,25 @@ Tox.prototype.hashSync = function(data) { * @param {Number} control * @param {Tox~errorCallback} [callback] */ -Tox.prototype.controlFile = function(friendnum, filenum, control, callback) { - if (!this._checkHandle(callback)) - return; +Tox.prototype.controlFile = function (friendnum, filenum, control, callback) { + if (!this._checkHandle(callback)) return; control = this._fixFileControl(control); var eptr = ref.alloc(TOX_ERR_FILE_CONTROL); this.getLibrary().tox_file_control.async( - this.getHandle(), friendnum, filenum, control, eptr, - function(err, success) { - var terr = errors.fileControl(eptr.deref()); - if (!err && terr) - err = terr; - if (!err && !success) - err = errors.unsuccessful(); - if (callback) { - callback(err); - } - }); + this.getHandle(), + friendnum, + filenum, + control, + eptr, + function (err, success) { + var terr = errors.fileControl(eptr.deref()); + if (!err && terr) err = terr; + if (!err && !success) err = errors.unsuccessful(); + if (callback) { + callback(err); + } + } + ); }; /** @@ -1785,17 +1691,20 @@ Tox.prototype.controlFile = function(friendnum, filenum, control, callback) { * @param {Number} filenum * @param {Number} control */ -Tox.prototype.controlFileSync = function(friendnum, filenum, control) { +Tox.prototype.controlFileSync = function (friendnum, filenum, control) { this._checkHandleSync(); control = this._fixFileControl(control); var eptr = ref.alloc(TOX_ERR_FILE_CONTROL), - success = this.getLibrary().tox_file_control(this.getHandle(), friendnum, - filenum, control, eptr); + success = this.getLibrary().tox_file_control( + this.getHandle(), + friendnum, + filenum, + control, + eptr + ); var err = errors.fileControl(eptr.deref()); - if (err) - throw err; - if (!success) - throw errors.unsuccessful(); + if (err) throw err; + if (!success) throw errors.unsuccessful(); }; /** @@ -1805,22 +1714,24 @@ Tox.prototype.controlFileSync = function(friendnum, filenum, control) { * @param {Number} position * @param {Tox~errorCallback} [callback] */ -Tox.prototype.seekFile = function(friendnum, filenum, position, callback) { - if (!this._checkHandle(callback)) - return; +Tox.prototype.seekFile = function (friendnum, filenum, position, callback) { + if (!this._checkHandle(callback)) return; var eptr = ref.alloc(TOX_ERR_FILE_SEEK); - this.getLibrary().tox_file_seek.async(this.getHandle(), friendnum, filenum, - position, eptr, function(err, success) { - var terr = - errors.fileSeek(eptr.deref()); - if (!err && terr) - err = terr; - if (!err && !success) - err = errors.unsuccessful(); - if (callback) { - callback(err); - } - }); + this.getLibrary().tox_file_seek.async( + this.getHandle(), + friendnum, + filenum, + position, + eptr, + function (err, success) { + var terr = errors.fileSeek(eptr.deref()); + if (!err && terr) err = terr; + if (!err && !success) err = errors.unsuccessful(); + if (callback) { + callback(err); + } + } + ); }; /** @@ -1829,16 +1740,13 @@ Tox.prototype.seekFile = function(friendnum, filenum, position, callback) { * @param {Number} filenum * @param {Number} position */ -Tox.prototype.seekFileSync = function(friendnum, filenum, position) { +Tox.prototype.seekFileSync = function (friendnum, filenum, position) { this._checkHandleSync(); var eptr = ref.alloc(TOX_ERR_FILE_SEEK), - success = this.getLibrary().tox_file_seek(this.getHandle(), friendnum, - filenum, position, eptr); + success = this.getLibrary().tox_file_seek(this.getHandle(), friendnum, filenum, position, eptr); var err = errors.fileSeek(eptr.deref()); - if (err) - throw err; - if (!success) - throw errors.unsuccessful(); + if (err) throw err; + if (!success) throw errors.unsuccessful(); }; /** @@ -1847,23 +1755,25 @@ Tox.prototype.seekFileSync = function(friendnum, filenum, position) { * @param {Number} filenum * @param {Tox~dataCallback} [callback] */ -Tox.prototype.getFileId = function(friendnum, filenum, callback) { - if (!this._checkHandle(callback)) - return; +Tox.prototype.getFileId = function (friendnum, filenum, callback) { + if (!this._checkHandle(callback)) return; var eptr = ref.alloc(TOX_ERR_FILE_GET), - fileid = Buffer.alloc(consts.TOX_FILE_ID_LENGTH); + fileid = Buffer.alloc(consts.TOX_FILE_ID_LENGTH); this.getLibrary().tox_file_get_file_id.async( - this.getHandle(), friendnum, filenum, fileid, eptr, - function(err, success) { - var terr = errors.fileGet(eptr.deref()); - if (!err && terr) - err = terr; - if (!err && !success) - err = errors.unsuccessful(); - if (callback) { - callback(err, fileid); - } - }); + this.getHandle(), + friendnum, + filenum, + fileid, + eptr, + function (err, success) { + var terr = errors.fileGet(eptr.deref()); + if (!err && terr) err = terr; + if (!err && !success) err = errors.unsuccessful(); + if (callback) { + callback(err, fileid); + } + } + ); }; /** @@ -1872,17 +1782,20 @@ Tox.prototype.getFileId = function(friendnum, filenum, callback) { * @param {Number} filenum * @return {Buffer} file id */ -Tox.prototype.getFileIdSync = function(friendnum, filenum) { +Tox.prototype.getFileIdSync = function (friendnum, filenum) { this._checkHandleSync(); var eptr = ref.alloc(TOX_ERR_FILE_GET), - fileid = Buffer.alloc(consts.TOX_FILE_ID_LENGTH), - success = this.getLibrary().tox_file_get_file_id( - this.getHandle(), friendnum, filenum, fileid, eptr); + fileid = Buffer.alloc(consts.TOX_FILE_ID_LENGTH), + success = this.getLibrary().tox_file_get_file_id( + this.getHandle(), + friendnum, + filenum, + fileid, + eptr + ); var err = errors.fileGet(eptr.deref()); - if (err) - throw err; - if (!success) - throw errors.unsuccessful(); + if (err) throw err; + if (!success) throw errors.unsuccessful(); return fileid; }; @@ -1895,30 +1808,34 @@ Tox.prototype.getFileIdSync = function(friendnum, filenum) { * @param {Buffer} [fileid] * @param {Tox~numberCallback} [callback] */ -Tox.prototype.sendFile = function(friendnum, kind, filename, size, fileid, - callback) { - if (!this._checkHandle(callback)) - return; +Tox.prototype.sendFile = function (friendnum, kind, filename, size, fileid, callback) { + if (!this._checkHandle(callback)) return; if (arguments.length === 5 && _.isFunction(fileid)) { callback = fileid; fileid = undefined; } - if (!fileid) - fileid = ref.NULL; + if (!fileid) fileid = ref.NULL; if (_.isString(filename)) { filename = Buffer.from(filename); } var eptr = ref.alloc(TOX_ERR_FILE_SEND); this.getLibrary().tox_file_send.async( - this.getHandle(), friendnum, kind, size, fileid, filename, - filename.length, eptr, function(err, filenum) { - var terr = errors.fileSend(eptr.deref()); - if (!err && terr) - err = terr; - if (callback) { - callback(err, filenum); - } - }); + this.getHandle(), + friendnum, + kind, + size, + fileid, + filename, + filename.length, + eptr, + function (err, filenum) { + var terr = errors.fileSend(eptr.deref()); + if (!err && terr) err = terr; + if (callback) { + callback(err, filenum); + } + } + ); }; /** @@ -1930,20 +1847,25 @@ Tox.prototype.sendFile = function(friendnum, kind, filename, size, fileid, * @param {Buffer} [fileid] * @return {Number} file number */ -Tox.prototype.sendFileSync = function(friendnum, kind, filename, size, fileid) { +Tox.prototype.sendFileSync = function (friendnum, kind, filename, size, fileid) { this._checkHandleSync(); - if (!fileid) - fileid = ref.NULL; + if (!fileid) fileid = ref.NULL; if (_.isString(filename)) { filename = Buffer.from(filename); } var eptr = ref.alloc(TOX_ERR_FILE_SEND), - filenum = this.getLibrary().tox_file_send(this.getHandle(), friendnum, - kind, size, fileid, filename, - filename.length, eptr); + filenum = this.getLibrary().tox_file_send( + this.getHandle(), + friendnum, + kind, + size, + fileid, + filename, + filename.length, + eptr + ); var err = errors.fileSend(eptr.deref()); - if (err) - throw err; + if (err) throw err; return filenum; }; @@ -1955,23 +1877,26 @@ Tox.prototype.sendFileSync = function(friendnum, kind, filename, size, fileid) { * @param {Buffer} data * @param {Tox~errorCallback} [callback] */ -Tox.prototype.sendFileChunk = function(friendnum, filenum, position, data, - callback) { - if (!this._checkHandle(callback)) - return; +Tox.prototype.sendFileChunk = function (friendnum, filenum, position, data, callback) { + if (!this._checkHandle(callback)) return; var eptr = ref.alloc(TOX_ERR_FILE_SEND_CHUNK); this.getLibrary().tox_file_send_chunk.async( - this.getHandle(), friendnum, filenum, position, data, data.length, eptr, - function(err, success) { - var terr = errors.fileSendChunk(eptr.deref()); - if (!err && terr) - err = terr; - if (!err && !success) - err = errors.unsuccessful(); - if (callback) { - callback(err); - } - }); + this.getHandle(), + friendnum, + filenum, + position, + data, + data.length, + eptr, + function (err, success) { + var terr = errors.fileSendChunk(eptr.deref()); + if (!err && terr) err = terr; + if (!err && !success) err = errors.unsuccessful(); + if (callback) { + callback(err); + } + } + ); }; /** @@ -1981,17 +1906,21 @@ Tox.prototype.sendFileChunk = function(friendnum, filenum, position, data, * @param {Number} position * @param {Buffer} data */ -Tox.prototype.sendFileChunkSync = function(friendnum, filenum, position, data) { +Tox.prototype.sendFileChunkSync = function (friendnum, filenum, position, data) { this._checkHandleSync(); var eptr = ref.alloc(TOX_ERR_FILE_SEND_CHUNK), - success = this.getLibrary().tox_file_send_chunk( - this.getHandle(), friendnum, filenum, position, data, data.length, - eptr); + success = this.getLibrary().tox_file_send_chunk( + this.getHandle(), + friendnum, + filenum, + position, + data, + data.length, + eptr + ); var err = errors.fileSendChunk(eptr.deref()); - if (err) - throw err; - if (!success) - throw errors.unsuccessful(); + if (err) throw err; + if (!success) throw errors.unsuccessful(); }; /** @@ -2001,7 +1930,7 @@ Tox.prototype.sendFileChunkSync = function(friendnum, filenum, position, data) { * @param {Buffer} data * @param {Tox~errorCallback} [callback] */ -Tox.prototype.sendLosslessPacket = function(friendnum, id, data, callback) { +Tox.prototype.sendLosslessPacket = function (friendnum, id, data, callback) { if (_.isNumber(id)) { data = this._fixPacketBuffer(id, data); } else { @@ -2010,12 +1939,11 @@ Tox.prototype.sendLosslessPacket = function(friendnum, id, data, callback) { } this._performSendPacket({ - api : this.getLibrary().tox_friend_send_lossless_packet.async.bind( - undefined, this.getHandle()), - data : data, - friend : friendnum, - async : true, - callback : callback, + api: this.getLibrary().tox_friend_send_lossless_packet.async.bind(undefined, this.getHandle()), + data: data, + friend: friendnum, + async: true, + callback: callback, }); }; @@ -2027,7 +1955,7 @@ Tox.prototype.sendLosslessPacket = function(friendnum, id, data, callback) { * @throws Error if TOX_ERR_FRIEND_CUSTOM_PACKET set * @throws Error if tox_friend_send_lossless_packet returns false */ -Tox.prototype.sendLosslessPacketSync = function(friendnum, id, data) { +Tox.prototype.sendLosslessPacketSync = function (friendnum, id, data) { if (_.isNumber(id)) { data = this._fixPacketBuffer(id, data); } else { @@ -2035,10 +1963,9 @@ Tox.prototype.sendLosslessPacketSync = function(friendnum, id, data) { } this._performSendPacket({ - api : this.getLibrary().tox_friend_send_lossless_packet.bind( - undefined, this.getHandle()), - data : data, - friend : friendnum, + api: this.getLibrary().tox_friend_send_lossless_packet.bind(undefined, this.getHandle()), + data: data, + friend: friendnum, }); }; @@ -2050,7 +1977,7 @@ Tox.prototype.sendLosslessPacketSync = function(friendnum, id, data) { * @param {Buffer} data * @param {Tox~errorCallback} [callback] */ -Tox.prototype.sendLossyPacket = function(friendnum, data, callback) { +Tox.prototype.sendLossyPacket = function (friendnum, data, callback) { if (_.isNumber(id)) { data = this._fixPacketBuffer(id, data); } else { @@ -2059,12 +1986,11 @@ Tox.prototype.sendLossyPacket = function(friendnum, data, callback) { } this._performSendPacket({ - api : this.getLibrary().tox_friend_send_lossy_packet.async.bind( - undefined, this.getHandle()), - data : data, - friend : friendnum, - async : true, - callback : callback, + api: this.getLibrary().tox_friend_send_lossy_packet.async.bind(undefined, this.getHandle()), + data: data, + friend: friendnum, + async: true, + callback: callback, }); }; @@ -2077,7 +2003,7 @@ Tox.prototype.sendLossyPacket = function(friendnum, data, callback) { * @throws Error if TOX_ERR_FRIEND_CUSTOM_PACKET set * @throws Error if tox_friend_send_lossy_packet returns false */ -Tox.prototype.sendLossyPacketSync = function(friendnum, id, data) { +Tox.prototype.sendLossyPacketSync = function (friendnum, id, data) { if (_.isNumber(id)) { data = this._fixPacketBuffer(id, data); } else { @@ -2085,10 +2011,9 @@ Tox.prototype.sendLossyPacketSync = function(friendnum, id, data) { } this._performSendPacket({ - api : this.getLibrary().tox_friend_send_lossy_packet.bind(undefined, - this.getHandle()), - data : data, - friend : friendnum, + api: this.getLibrary().tox_friend_send_lossy_packet.bind(undefined, this.getHandle()), + data: data, + friend: friendnum, }); }; @@ -2096,13 +2021,13 @@ Tox.prototype.sendLossyPacketSync = function(friendnum, id, data) { * Asynchronous tox_kill(3). Will also set handle to undefined. * @param {Tox~errorCallback} [callback] */ -Tox.prototype.kill = function(callback) { +Tox.prototype.kill = function (callback) { if (!this._checkHandle(callback)) { return; } var _this = this; - this.getLibrary().tox_kill.async(this.getHandle(), function(err) { + this.getLibrary().tox_kill.async(this.getHandle(), function (err) { if (!err) { _this._handle = undefined; } @@ -2116,7 +2041,7 @@ Tox.prototype.kill = function(callback) { /** * Synchronous tox_kill(3). Will also set handle to undefined. */ -Tox.prototype.killSync = function() { +Tox.prototype.killSync = function () { this._checkHandleSync(); this.getLibrary().tox_kill(this.getHandle()); this._handle = undefined; @@ -2126,12 +2051,11 @@ Tox.prototype.killSync = function() { * Asynchronous tox_get_savedata_size(3). * @param {Tox~numberCallback} [callback] */ -Tox.prototype.getSavedataSize = function(callback) { +Tox.prototype.getSavedataSize = function (callback) { this._performSizeGetter({ - api : this.getLibrary().tox_get_savedata_size.async.bind(undefined, - this.getHandle()), - async : true, - callback : callback, + api: this.getLibrary().tox_get_savedata_size.async.bind(undefined, this.getHandle()), + async: true, + callback: callback, }); }; @@ -2139,10 +2063,9 @@ Tox.prototype.getSavedataSize = function(callback) { * Synchronous tox_get_savedata_size(3). * @return {Number} savedata size */ -Tox.prototype.getSavedataSizeSync = function(callback) { +Tox.prototype.getSavedataSizeSync = function (callback) { return this._performSizeGetter({ - api : this.getLibrary().tox_get_savedata_size.bind(undefined, - this.getHandle()), + api: this.getLibrary().tox_get_savedata_size.bind(undefined, this.getHandle()), }); }; @@ -2150,14 +2073,13 @@ Tox.prototype.getSavedataSizeSync = function(callback) { * Asynchronous tox_get_savedata(3). * @param {Tox~dataCallback} [callback] */ -Tox.prototype.getSavedata = function(callback) { +Tox.prototype.getSavedata = function (callback) { this._performGetter({ - api : this.getLibrary().tox_get_savedata.async.bind(undefined, - this.getHandle()), - format : "raw", - size : Tox.prototype.getSavedataSize.bind(this), - async : true, - callback : callback, + api: this.getLibrary().tox_get_savedata.async.bind(undefined, this.getHandle()), + format: "raw", + size: Tox.prototype.getSavedataSize.bind(this), + async: true, + callback: callback, }); }; @@ -2165,11 +2087,11 @@ Tox.prototype.getSavedata = function(callback) { * Synchronous tox_get_savedata(3). * @return {Buffer} savedata */ -Tox.prototype.getSavedataSync = function() { +Tox.prototype.getSavedataSync = function () { return this._performGetter({ - api : this.getLibrary().tox_get_savedata.bind(undefined, this.getHandle()), - format : "raw", - size : Tox.prototype.getSavedataSizeSync.bind(this), + api: this.getLibrary().tox_get_savedata.bind(undefined, this.getHandle()), + format: "raw", + size: Tox.prototype.getSavedataSizeSync.bind(this), }); }; @@ -2182,37 +2104,46 @@ Tox.prototype.getSavedataSync = function() { * if any. * @return {ToxEncryptSave} Crypto handler */ -Tox.prototype.crypto = function() { return this._crypto; }; +Tox.prototype.crypto = function () { + return this._crypto; +}; /** * Get the handle object. * @return {Object} */ -Tox.prototype.getHandle = function() { return this._handle; }; +Tox.prototype.getHandle = function () { + return this._handle; +}; /** * Whether or not this Tox instance has a crypto handler. * @return {Boolean} true if it has a crypto handler, false if not */ -Tox.prototype.hasCrypto = - function() { return this._crypto instanceof ToxEncryptSave; }; +Tox.prototype.hasCrypto = function () { + return this._crypto instanceof ToxEncryptSave; +}; /** * Whether or not this Tox instance has a handle. * @return {Boolean} true if handle, false if none */ -Tox.prototype.hasHandle = function() { return !!this.getHandle(); }; +Tox.prototype.hasHandle = function () { + return !!this.getHandle(); +}; /** * Get the internal Library instance. * @return {ffi.Library} */ -Tox.prototype.getLibrary = function() { return this._library; }; +Tox.prototype.getLibrary = function () { + return this._library; +}; /** * Frees the ToxOptions and calls tox_kill synchronously. */ -Tox.prototype.free = function() { +Tox.prototype.free = function () { this.freeOptionsSync(this._options); this._options = undefined; this.killSync(); @@ -2222,33 +2153,33 @@ Tox.prototype.free = function() { * Get the event emitter. * @return {EventEmitter} emitter */ -Tox.prototype.getEmitter = function() { return this._emitter; }; +Tox.prototype.getEmitter = function () { + return this._emitter; +}; /** * Get the ToxOptions as an object. * @return {Object} object */ -Tox.prototype.getOptions = function() { +Tox.prototype.getOptions = function () { var options = this._options; var proxyAddress = undefined; if (ref.address(options.proxy_address) !== 0) { - proxyAddress = - ref.reinterpretUntilZeros(options.proxy_address, ref.types.char.size) - .toString(); + proxyAddress = ref.reinterpretUntilZeros(options.proxy_address, ref.types.char.size).toString(); } return { - ipv6_enabled : options.ipv6_enabled, - udp_enabled : options.udp_enabled, - proxy_type : options.proxy_type, - proxy_address : proxyAddress, - proxy_port : options.proxy_port, - start_port : options.start_port, - end_port : options.end_port, - savedata_type : options.savedata_type, - savedata_data : ref.address(options.savedata_data), - savedata_length : options.savedata_length, + ipv6_enabled: options.ipv6_enabled, + udp_enabled: options.udp_enabled, + proxy_type: options.proxy_type, + proxy_address: proxyAddress, + proxy_port: options.proxy_port, + start_port: options.start_port, + end_port: options.end_port, + savedata_type: options.savedata_type, + savedata_data: ref.address(options.savedata_data), + savedata_length: options.savedata_length, }; }; @@ -2256,13 +2187,15 @@ Tox.prototype.getOptions = function() { * Check whether or not an iterateSync loop is running. * @return {Boolean} true if loop running, false if not */ -Tox.prototype.isStarted = function() { return !!this._interval; }; +Tox.prototype.isStarted = function () { + return !!this._interval; +}; /** * Checks if listening on a tcp port. * @return {Boolean} true if tcp, false if not */ -Tox.prototype.isTcp = function() { +Tox.prototype.isTcp = function () { try { this.getTcpPortSync(); return true; @@ -2275,7 +2208,7 @@ Tox.prototype.isTcp = function() { * Checks if listening on a udp port. * @return {Boolean} true if udp, false if not */ -Tox.prototype.isUdp = function() { +Tox.prototype.isUdp = function () { try { this.getUdpPortSync(); return true; @@ -2287,26 +2220,27 @@ Tox.prototype.isUdp = function() { /** * Wrapper method for _emitter.removeListener. */ -Tox.prototype.off = function() { +Tox.prototype.off = function () { this._emitter.removeListener.apply(this._emitter, arguments); }; /** * Wrapper method for _emitter.on. */ -Tox.prototype.on = - function() { this._emitter.on.apply(this._emitter, arguments); }; +Tox.prototype.on = function () { + this._emitter.on.apply(this._emitter, arguments); +}; /** * Asynchronously save state to a tox file. * @param {String} filepath * @param {Tox~errorCallback} [callback] */ -Tox.prototype.saveToFile = function(filepath, callback) { - this.getSavedata(function(err, buffer) { +Tox.prototype.saveToFile = function (filepath, callback) { + this.getSavedata(function (err, buffer) { if (!err) { // Using hex number because "grunt jsdoc" doesn't understand octal. - fs.writeFile(filepath, buffer, {mode : 0x180 /* 0600 */}, callback); + fs.writeFile(filepath, buffer, { mode: 0x180 /* 0600 */ }, callback); } else if (callback) { callback(err); } @@ -2317,10 +2251,10 @@ Tox.prototype.saveToFile = function(filepath, callback) { * Synchronously save state to a tox file. * @param {String} filepath */ -Tox.prototype.saveToFileSync = function(filepath) { +Tox.prototype.saveToFileSync = function (filepath) { // Using hex number because "grunt jsdoc" doesn't understand octal. fs.writeFileSync(filepath, this.getSavedataSync(), { - mode : 0x180 /* 0600 */, + mode: 0x180 /* 0600 */, }); }; @@ -2330,10 +2264,9 @@ Tox.prototype.saveToFileSync = function(filepath) { * @todo Maybe do one iterateSync(), then iterationIntervalSync(), and use that * value as "wait"? */ -Tox.prototype.start = function(wait) { +Tox.prototype.start = function (wait) { if (!this.isStarted()) { - if (isNaN(wait) || wait <= 0) - wait = 40; // Default milliseconds to wait + if (isNaN(wait) || wait <= 0) wait = 40; // Default milliseconds to wait this._interval = setInterval(Tox.prototype.iterateSync.bind(this), wait); } }; @@ -2341,7 +2274,7 @@ Tox.prototype.start = function(wait) { /** * Stop the iterateSync loop if there is one running. */ -Tox.prototype.stop = function() { +Tox.prototype.stop = function () { if (this._interval) { clearInterval(this._interval); this._interval = undefined; @@ -2351,20 +2284,22 @@ Tox.prototype.stop = function() { /** * Asynchronously get the address as a hex string. */ -Tox.prototype.getAddressHex = function( - callback) { util.hexify(this.getAddress.bind(this), callback); }; +Tox.prototype.getAddressHex = function (callback) { + util.hexify(this.getAddress.bind(this), callback); +}; /** * Synchronously get the address as a hex string. * @return {String} Address hex string */ -Tox.prototype.getAddressHexSync = - function() { return util.hexifySync(this.getAddressSync.bind(this)); }; +Tox.prototype.getAddressHexSync = function () { + return util.hexifySync(this.getAddressSync.bind(this)); +}; /** * Asynchronously get the public key of a friend as a hex string. */ -Tox.prototype.getFriendPublicKeyHex = function(friend, callback) { +Tox.prototype.getFriendPublicKeyHex = function (friend, callback) { util.hexify(this.getFriendPublicKey.bind(this, friend), callback); }; @@ -2372,35 +2307,39 @@ Tox.prototype.getFriendPublicKeyHex = function(friend, callback) { * Synchronously get the public key of a friend as a hex string. * @return {String} Friend public key hex string */ -Tox.prototype.getFriendPublicKeyHexSync = function(friend) { +Tox.prototype.getFriendPublicKeyHexSync = function (friend) { return util.hexifySync(this.getFriendPublicKeySync.bind(this, friend)); }; /** * Asynchronously get the public key as a hex string. */ -Tox.prototype.getPublicKeyHex = function( - callback) { util.hexify(this.getPublicKey.bind(this), callback); }; +Tox.prototype.getPublicKeyHex = function (callback) { + util.hexify(this.getPublicKey.bind(this), callback); +}; /** * Synchronously get the public key as a hex string. * @return {String} Public key hex string */ -Tox.prototype.getPublicKeyHexSync = - function() { return util.hexifySync(this.getPublicKeySync.bind(this)); }; +Tox.prototype.getPublicKeyHexSync = function () { + return util.hexifySync(this.getPublicKeySync.bind(this)); +}; /** * Asynchronously get the secret key as a hex string. */ -Tox.prototype.getSecretKeyHex = function( - callback) { util.hexify(this.getSecretKey.bind(this), callback); }; +Tox.prototype.getSecretKeyHex = function (callback) { + util.hexify(this.getSecretKey.bind(this), callback); +}; /** * Synchronously get the secret key as a hex string. * @return {String} Secret key hex string */ -Tox.prototype.getSecretKeyHexSync = - function() { return util.hexifySync(this.getSecretKeySync.bind(this)); }; +Tox.prototype.getSecretKeyHexSync = function () { + return util.hexifySync(this.getSecretKeySync.bind(this)); +}; ////////////////////////// //> Private helper methods @@ -2413,7 +2352,7 @@ Tox.prototype.getSecretKeyHexSync = * handle * @return {Boolean} true if has handle (no error), false if no handle (error) */ -Tox.prototype._checkHandle = function(callback) { +Tox.prototype._checkHandle = function (callback) { if (!this.hasHandle()) { var err = new Error("No toxcore handle"); err.code = "NO_HANDLE"; @@ -2434,7 +2373,7 @@ Tox.prototype._checkHandle = function(callback) { * @private * @throws Error if no handle */ -Tox.prototype._checkHandleSync = function() { +Tox.prototype._checkHandleSync = function () { if (!this.hasHandle()) { var err = new Error("No toxcore handle"); err.code = "NO_HANDLE"; @@ -2451,16 +2390,22 @@ Tox.prototype._checkHandleSync = function() { * @param {Object} opts * @return {ToxOptions} Options */ -Tox.prototype._createToxOptions = function(opts) { - var toxopts = this.newOptionsSync(), ipv6 = opts["ipv6"], udp = opts["udp"], - startPort = opts["startPort"], endPort = opts["endPort"], - data = opts["data"], pass = opts["pass"]; +Tox.prototype._createToxOptions = function (opts) { + var toxopts = this.newOptionsSync(), + ipv6 = opts["ipv6"], + udp = opts["udp"], + startPort = opts["startPort"], + endPort = opts["endPort"], + data = opts["data"], + pass = opts["pass"]; // If pass is a string or Buffer, have pass be a function that returns // the string or Buffer if (_.isString(pass) || Buffer.isBuffer(pass)) { var passData = pass; - pass = function() { return passData; }; + pass = function () { + return passData; + }; } // If "data" is a string, assume filepath to read data from @@ -2469,8 +2414,7 @@ Tox.prototype._createToxOptions = function(opts) { } if (data) { - if (this.hasCrypto() && _.isFunction(pass) && - this.crypto().isDataEncryptedSync(data)) { + if (this.hasCrypto() && _.isFunction(pass) && this.crypto().isDataEncryptedSync(data)) { var passphrase = pass(); data = this.crypto().decryptSync(data, passphrase); } @@ -2516,43 +2460,42 @@ Tox.prototype._createToxOptions = function(opts) { * Wrapper method for _emitter.emit. * @private */ -Tox.prototype._emit = - function() { this._emitter.emit.apply(this._emitter, arguments); }; +Tox.prototype._emit = function () { + this._emitter.emit.apply(this._emitter, arguments); +}; /** * Fix arguments passed to bootstrap functions. * @private */ -Tox.prototype._fixBootstrapArgs = function(address, port, publicKey) { +Tox.prototype._fixBootstrapArgs = function (address, port, publicKey) { address = Buffer.from(address + "\0"); if (_.isString(publicKey)) { publicKey = Buffer.from(publicKey, "hex"); } - return [ address, port, publicKey ]; + return [address, port, publicKey]; }; /** * Fix arguments passed to send-message functions. * @private */ -Tox.prototype._fixSendMessageArgs = function(to, message, type) { +Tox.prototype._fixSendMessageArgs = function (to, message, type) { if (_.isString(message)) { message = Buffer.from(message); } if (_.isBoolean(type)) { - type = - type ? consts.TOX_MESSAGE_TYPE_ACTION : consts.TOX_MESSAGE_TYPE_NORMAL; + type = type ? consts.TOX_MESSAGE_TYPE_ACTION : consts.TOX_MESSAGE_TYPE_NORMAL; } else if (_.isString(type)) { - type = /^action$/i.test(type) ? consts.TOX_MESSAGE_TYPE_ACTION - : consts.TOX_MESSAGE_TYPE_NORMAL; + type = /^action$/i.test(type) ? consts.TOX_MESSAGE_TYPE_ACTION : consts.TOX_MESSAGE_TYPE_NORMAL; } else if (!_.isNumber(type)) { type = consts.TOX_MESSAGE_TYPE_NORMAL; } - return [ to, message, type ]; + return [to, message, type]; }; /** @@ -2562,7 +2505,7 @@ Tox.prototype._fixSendMessageArgs = function(to, message, type) { * @param {(Number|String)} control * @return {Number} control value */ -Tox.prototype._fixFileControl = function(control) { +Tox.prototype._fixFileControl = function (control) { if (_.isString(control)) { if (/^resume$/i.test(control)) { return consts.TOX_FILE_CONTROL_RESUME; @@ -2582,9 +2525,9 @@ Tox.prototype._fixFileControl = function(control) { * @param {Buffer} data * @return {Buffer} new data */ -Tox.prototype._fixSendLosslessPacket = function(data) { +Tox.prototype._fixSendLosslessPacket = function (data) { // 160: magic byte - return Buffer.concat([ Buffer.from([ 160 ]), data ]); + return Buffer.concat([Buffer.from([160]), data]); }; /** @@ -2596,8 +2539,8 @@ Tox.prototype._fixSendLosslessPacket = function(data) { * @param {Buffer} data - Data buffer to prepend to * @return {Buffer} new data */ -Tox.prototype._fixPacketBuffer = function(id, data) { - return Buffer.concat([ Buffer.from([ id ]), data ]); +Tox.prototype._fixPacketBuffer = function (id, data) { + return Buffer.concat([Buffer.from([id]), data]); }; /** @@ -2605,7 +2548,7 @@ Tox.prototype._fixPacketBuffer = function(id, data) { * @param {Object} opts - Tox constructor options object * @private */ -Tox.prototype._initCrypto = function(opts) { +Tox.prototype._initCrypto = function (opts) { var crypto = opts["crypto"]; if (crypto === undefined || crypto === true) { // If not given, use a default instance @@ -2632,7 +2575,7 @@ Tox.prototype._initCrypto = function(opts) { * @param {(Buffer|String)} [data] * @todo Take one param (opts map) */ -Tox.prototype._initNew = function(options, data) { +Tox.prototype._initNew = function (options, data) { var eptr = ref.alloc(TOX_ERR_NEW); if (options) { @@ -2654,7 +2597,7 @@ Tox.prototype._initNew = function(options, data) { * @param {ToxOptions} options * @todo Update for char* proxy_host, instead of char[256] proxy_host */ -Tox.prototype._setProxyToToxOptions = function(opts, options) { +Tox.prototype._setProxyToToxOptions = function (opts, options) { var proxy = opts["proxy"]; if (_.isString(proxy)) { @@ -2664,10 +2607,8 @@ Tox.prototype._setProxyToToxOptions = function(opts, options) { if (_.isObject(proxy)) { if (_.isString(proxy.type)) { - if (/^http$/i.test(proxy.type)) - options.proxy_type = consts.TOX_PROXY_TYPE_HTTP; - else if (/^socks5?$/i.test(proxy.type)) - options.proxy_type = consts.TOX_PROXY_TYPE_SOCKS5; + if (/^http$/i.test(proxy.type)) options.proxy_type = consts.TOX_PROXY_TYPE_HTTP; + else if (/^socks5?$/i.test(proxy.type)) options.proxy_type = consts.TOX_PROXY_TYPE_SOCKS5; } if (options.proxy_type !== consts.TOX_PROXY_TYPE_NONE) { @@ -2694,14 +2635,11 @@ Tox.prototype._setProxyToToxOptions = function(opts, options) { * @param {Object} key - Key * @param {ffi.Callback} callback - Callback */ -Tox.prototype._storeFFICallback = function(key, callback) { - if (!this._ffiCallbacks) - this._ffiCallbacks = {}; +Tox.prototype._storeFFICallback = function (key, callback) { + if (!this._ffiCallbacks) this._ffiCallbacks = {}; - if (this._ffiCallbacks[key] === undefined) - this._ffiCallbacks[key] = [ callback ]; - else - this._ffiCallbacks[key].push(callback); + if (this._ffiCallbacks[key] === undefined) this._ffiCallbacks[key] = [callback]; + else this._ffiCallbacks[key].push(callback); }; /** @@ -2711,7 +2649,7 @@ Tox.prototype._storeFFICallback = function(key, callback) { * @param {Function} callback - Callback function * @return {ffi.Callback} ffi callback */ -Tox.prototype._toFFICallback = function(ffiFunc, callback) { +Tox.prototype._toFFICallback = function (ffiFunc, callback) { return ffi.Callback(ffiFunc.retType, ffiFunc.argTypes, callback); }; @@ -2724,10 +2662,14 @@ Tox.prototype._toFFICallback = function(ffiFunc, callback) { * Tox#addTCPRelaySync(). * @private */ -Tox.prototype._performBootstrap = function(opts) { - var api = opts["api"], args = opts["args"], async = opts["async"], - callback = opts["callback"], address = args[0], port = args[1], - publicKey = args[2]; +Tox.prototype._performBootstrap = function (opts) { + var api = opts["api"], + args = opts["args"], + async = opts["async"], + callback = opts["callback"], + address = args[0], + port = args[1], + publicKey = args[2]; // Fix address and public key address = Buffer.from(address + "\0"); @@ -2738,14 +2680,11 @@ Tox.prototype._performBootstrap = function(opts) { var eptr = ref.alloc(TOX_ERR_BOOTSTRAP); if (async) { - if (!this._checkHandle(callback)) - return; - api(address, port, publicKey, eptr, function(err, success) { + if (!this._checkHandle(callback)) return; + api(address, port, publicKey, eptr, function (err, success) { var terr = errors.bootstrap(eptr.deref()); - if (!err && terr) - err = terr; - if (!err && !success) - err = errors.unsuccessful(); + if (!err && terr) err = terr; + if (!err && !success) err = errors.unsuccessful(); if (callback) { callback(err); } @@ -2754,10 +2693,8 @@ Tox.prototype._performBootstrap = function(opts) { this._checkHandleSync(); var success = api(address, port, publicKey, eptr); var err = errors.bootstrap(eptr.deref()); - if (err) - throw err; - if (!success) - throw errors.unsuccessful(); + if (err) throw err; + if (!success) throw errors.unsuccessful(); } }; @@ -2767,37 +2704,39 @@ Tox.prototype._performBootstrap = function(opts) { * @todo Custom error type/function, ex. TOX_ERR_FRIEND_GET_PUBLIC_KEY * @private */ -Tox.prototype._performFriendGetter = function(opts) { - var api = opts["api"], friend = opts["friend"], - raw = opts["format"] === "raw", _size = opts["size"], - async = opts["async"], callback = opts["callback"]; +Tox.prototype._performFriendGetter = function (opts) { + var api = opts["api"], + friend = opts["friend"], + raw = opts["format"] === "raw", + _size = opts["size"], + async = opts["async"], + callback = opts["callback"]; if (_.isNumber(_size)) { var size; if (async) - size = function(cb) { cb(undefined, _size); }; + size = function (cb) { + cb(undefined, _size); + }; else - size = function() { return _size; }; - } else - size = _size; // Assumes size is a Function + size = function () { + return _size; + }; + } else size = _size; // Assumes size is a Function var eptr = ref.alloc(TOX_ERR_FRIEND_QUERY); if (async) { - if (!this._checkHandle(callback)) - return; - size(function(err, size) { + if (!this._checkHandle(callback)) return; + size(function (err, size) { if (!err) { var buffer = Buffer.alloc(size); buffer.fill(0); - api(friend, buffer, eptr, function(err, success) { + api(friend, buffer, eptr, function (err, success) { var terr = errors.friendQuery(eptr.deref()); - if (!err && terr) - err = terr; - if (!err && !success) - err = errors.unsuccessful(); - if (!err && !raw) - buffer = buffer.toString("utf8"); + if (!err && terr) err = terr; + if (!err && !success) err = errors.unsuccessful(); + if (!err && !raw) buffer = buffer.toString("utf8"); if (callback) { callback(err, buffer); } @@ -2813,12 +2752,9 @@ Tox.prototype._performFriendGetter = function(opts) { buffer.fill(0); var success = api(friend, buffer, eptr); var err = errors.friendQuery(eptr.deref()); - if (err) - throw err; - if (!success) - throw errors.unsuccessful(); - if (!raw) - buffer = buffer.toString("utf8"); + if (err) throw err; + if (!success) throw errors.unsuccessful(); + if (!raw) buffer = buffer.toString("utf8"); return buffer; } }; @@ -2828,21 +2764,20 @@ Tox.prototype._performFriendGetter = function(opts) { * a Number. * @private */ -Tox.prototype._performFriendNumberGetter = function(opts) { - var api = opts["api"], friend = opts["friend"], async = opts["async"], - callback = opts["callback"]; +Tox.prototype._performFriendNumberGetter = function (opts) { + var api = opts["api"], + friend = opts["friend"], + async = opts["async"], + callback = opts["callback"]; var eptr = ref.alloc(TOX_ERR_FRIEND_QUERY); if (async) { - if (!this._checkHandle(callback)) - return; - api(friend, eptr, function(err, size) { + if (!this._checkHandle(callback)) return; + api(friend, eptr, function (err, size) { var terr = errors.friendQuery(eptr.deref()); - if (!err && terr) - err = terr; - if (!err) - size = Number(size); + if (!err && terr) err = terr; + if (!err) size = Number(size); if (callback) { callback(err, size); } @@ -2851,8 +2786,7 @@ Tox.prototype._performFriendNumberGetter = function(opts) { this._checkHandleSync(); var size = api(friend, eptr); var err = errors.friendQuery(eptr.deref()); - if (err) - throw err; + if (err) throw err; return Number(size); } }; @@ -2865,28 +2799,32 @@ Tox.prototype._performFriendNumberGetter = function(opts) { * a Buffer of that size) and trying to move data to that Buffer. * @private */ -Tox.prototype._performGetter = function(opts) { - var api = opts["api"], raw = opts["format"] === "raw", _size = opts["size"], - async = opts["async"], callback = opts["callback"]; +Tox.prototype._performGetter = function (opts) { + var api = opts["api"], + raw = opts["format"] === "raw", + _size = opts["size"], + async = opts["async"], + callback = opts["callback"]; if (_.isNumber(_size)) { var size; if (async) - size = function(cb) { cb(undefined, _size); }; + size = function (cb) { + cb(undefined, _size); + }; else - size = function() { return _size; }; - } else - size = _size; // Assumes size is a Function + size = function () { + return _size; + }; + } else size = _size; // Assumes size is a Function if (async) { - if (!this._checkHandle(callback)) - return; - size(function(err, size) { + if (!this._checkHandle(callback)) return; + size(function (err, size) { if (!err) { var buffer = Buffer.alloc(size); - api(buffer, function(err) { - if (!err && !raw) - buffer = buffer.toString("utf8"); + api(buffer, function (err) { + if (!err && !raw) buffer = buffer.toString("utf8"); if (callback) { callback(err, buffer); } @@ -2900,8 +2838,7 @@ Tox.prototype._performGetter = function(opts) { size = size(); var buffer = Buffer.alloc(size); api(buffer); - if (!raw) - buffer = buffer.toString("utf8"); + if (!raw) buffer = buffer.toString("utf8"); return buffer; } }; @@ -2910,15 +2847,15 @@ Tox.prototype._performGetter = function(opts) { * Helper wrapper function for api functions that return a Number. * @private */ -Tox.prototype._performNumberGetter = function(opts) { - var api = opts["api"], async = opts["async"], callback = opts["callback"]; +Tox.prototype._performNumberGetter = function (opts) { + var api = opts["api"], + async = opts["async"], + callback = opts["callback"]; if (async) { - if (!this._checkHandle(callback)) - return; - api(function(err, size) { - if (!err) - size = Number(size); + if (!this._checkHandle(callback)) return; + api(function (err, size) { + if (!err) size = Number(size); if (callback) { callback(err, size); } @@ -2933,14 +2870,15 @@ Tox.prototype._performNumberGetter = function(opts) { /** * @private */ -Tox.prototype._performNumberSetter = function(opts) { - var api = opts["api"], value = opts["value"], async = opts["async"], - callback = opts["callback"]; +Tox.prototype._performNumberSetter = function (opts) { + var api = opts["api"], + value = opts["value"], + async = opts["async"], + callback = opts["callback"]; if (async) { - if (!this._checkHandle(callback)) - return; - api(value, function(err) { + if (!this._checkHandle(callback)) return; + api(value, function (err) { if (callback) { callback(err); } @@ -2955,17 +2893,21 @@ Tox.prototype._performNumberSetter = function(opts) { * Helper wrapper function for api functions that get a size_t. * @private */ -Tox.prototype._performSizeGetter = function( - opts) { return this._performNumberGetter(opts); }; +Tox.prototype._performSizeGetter = function (opts) { + return this._performNumberGetter(opts); +}; /** * Helper wrapper function for api functions that take a buffer * (char*, uint8_t*) or a string of some size and use it to set data. * @private */ -Tox.prototype._performSetter = function(opts) { - var api = opts["api"], data = opts["data"], errorCheck = opts["error"], - async = opts["async"], callback = opts["callback"]; +Tox.prototype._performSetter = function (opts) { + var api = opts["api"], + data = opts["data"], + errorCheck = opts["error"], + async = opts["async"], + callback = opts["callback"]; if (_.isString(data)) { data = Buffer.from(data); @@ -2974,14 +2916,11 @@ Tox.prototype._performSetter = function(opts) { var eptr = ref.alloc(CEnum); // @todo: Make this more specific? if (async) { - if (!this._checkHandle(callback)) - return; - api(data, size_t(data.length), eptr, function(err, success) { + if (!this._checkHandle(callback)) return; + api(data, size_t(data.length), eptr, function (err, success) { var terr = errorCheck(eptr.deref()); - if (!err && terr) - err = terr; - if (!err && !success) - err = errors.unsuccessful(); + if (!err && terr) err = terr; + if (!err && !success) err = errors.unsuccessful(); if (callback) { callback(err); } @@ -2989,11 +2928,9 @@ Tox.prototype._performSetter = function(opts) { } else { this._checkHandleSync(); var success = api(data, size_t(data.length), eptr), - err = errorCheck(eptr.deref()); - if (err) - throw err; - if (!success) - throw errors.unsuccessful(); + err = errorCheck(eptr.deref()); + if (err) throw err; + if (!success) throw errors.unsuccessful(); } }; @@ -3002,21 +2939,21 @@ Tox.prototype._performSetter = function(opts) { * Buffer to send a packet. * @private */ -Tox.prototype._performSendPacket = function(opts) { - var api = opts["api"], data = opts["data"], friendnum = opts["friend"], - async = opts["async"], callback = opts["callback"]; +Tox.prototype._performSendPacket = function (opts) { + var api = opts["api"], + data = opts["data"], + friendnum = opts["friend"], + async = opts["async"], + callback = opts["callback"]; var eptr = ref.alloc(TOX_ERR_FRIEND_CUSTOM_PACKET); if (async) { - if (!this._checkHandle(callback)) - return; - api(friendnum, data, size_t(data.length), eptr, function(err, res) { + if (!this._checkHandle(callback)) return; + api(friendnum, data, size_t(data.length), eptr, function (err, res) { var terr = errors.friendCustomPacket(eptr.deref()); - if (!err && terr) - err = terr; - if (!err && !res) - err = errors.unsuccessful(); + if (!err && terr) err = terr; + if (!err && !res) err = errors.unsuccessful(); if (callback) { callback(err); } @@ -3024,11 +2961,9 @@ Tox.prototype._performSendPacket = function(opts) { } else { this._checkHandleSync(); var success = api(friendnum, data, size_t(data.length), eptr), - err = errors.friendCustomPacket(eptr.deref()); - if (err) - throw err; - if (!success) - throw errors.unsuccessful(); + err = errors.friendCustomPacket(eptr.deref()); + if (err) throw err; + if (!success) throw errors.unsuccessful(); } }; @@ -3036,18 +2971,18 @@ Tox.prototype._performSendPacket = function(opts) { * Helper wrapper function for api functions that get a port. * @private */ -Tox.prototype._performGetPort = function(opts) { - var api = opts["api"], async = opts["async"], callback = opts["callback"]; +Tox.prototype._performGetPort = function (opts) { + var api = opts["api"], + async = opts["async"], + callback = opts["callback"]; var eptr = ref.alloc(TOX_ERR_GET_PORT); if (async) { - if (!this._checkHandle(callback)) - return; - api(eptr, function(err, port) { + if (!this._checkHandle(callback)) return; + api(eptr, function (err, port) { var terr = errors.getPort(eptr.deref()); - if (!err && terr) - err = terr; + if (!err && terr) err = terr; if (callback) { callback(err, port); } @@ -3056,8 +2991,7 @@ Tox.prototype._performGetPort = function(opts) { this._checkHandleSync(); var port = api(eptr); var err = errors.getPort(eptr.deref()); - if (err) - throw err; + if (err) throw err; return port; } }; @@ -3066,10 +3000,12 @@ Tox.prototype._performGetPort = function(opts) { * Helper wrapper function for version api functions. * @private */ -Tox.prototype._performVersion = function(opts) { - var api = opts["api"], async = opts["async"], callback = opts["callback"]; +Tox.prototype._performVersion = function (opts) { + var api = opts["api"], + async = opts["async"], + callback = opts["callback"]; if (async) { - api(function(err, version) { + api(function (err, version) { if (callback) { callback(err, version); } @@ -3087,7 +3023,7 @@ Tox.prototype._performVersion = function(opts) { * Initialize all callbacks. * @private */ -Tox.prototype._initCallbacks = function() { +Tox.prototype._initCallbacks = function () { this._initSelfConnectionStatusCb(); this._initFriendNameCb(); this._initFriendStatusMessageCb(); @@ -3109,12 +3045,13 @@ Tox.prototype._initCallbacks = function() { * Helper function for initializing tox callbacks. * @private */ -Tox.prototype._initCallback = function(opts) { +Tox.prototype._initCallback = function (opts) { this._checkHandleSync(); var api = opts["api"], - cb = opts["cb"], // Callback type - name = opts["name"], wrapper = opts["wrapper"]; + cb = opts["cb"], // Callback type + name = opts["name"], + wrapper = opts["wrapper"]; var x = this._toFFICallback(cb, wrapper); this._storeFFICallback(name, x); // Store for GC issues @@ -3125,16 +3062,14 @@ Tox.prototype._initCallback = function(opts) { * Initialize the selfConnectionStatus event callback. * @private */ -Tox.prototype._initSelfConnectionStatusCb = function() { +Tox.prototype._initSelfConnectionStatusCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_self_connection_status.bind( - undefined, this.getHandle()), - cb : SelfConnectionStatusCallback, - name : "SelfConnectionStatus", - wrapper : function(handle, connection, userdata) { - _this._emit("selfConnectionStatus", - new toxEvents.SelfConnectionStatusEvent(connection)); + api: this.getLibrary().tox_callback_self_connection_status.bind(undefined, this.getHandle()), + cb: SelfConnectionStatusCallback, + name: "SelfConnectionStatus", + wrapper: function (handle, connection, userdata) { + _this._emit("selfConnectionStatus", new toxEvents.SelfConnectionStatusEvent(connection)); }, }); }; @@ -3143,14 +3078,13 @@ Tox.prototype._initSelfConnectionStatusCb = function() { * Initialize the friendName event callback. * @private */ -Tox.prototype._initFriendNameCb = function() { +Tox.prototype._initFriendNameCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_friend_name.bind(undefined, - this.getHandle()), - cb : FriendNameCallback, - name : "FriendName", - wrapper : function(handle, friend, buffer, size, userdata) { + api: this.getLibrary().tox_callback_friend_name.bind(undefined, this.getHandle()), + cb: FriendNameCallback, + name: "FriendName", + wrapper: function (handle, friend, buffer, size, userdata) { var name = buffer.slice(0, size).toString(); _this._emit("friendName", new toxEvents.FriendNameEvent(friend, name)); }, @@ -3161,17 +3095,18 @@ Tox.prototype._initFriendNameCb = function() { * Initialize the friendStatusMessage event callback. * @private */ -Tox.prototype._initFriendStatusMessageCb = function() { +Tox.prototype._initFriendStatusMessageCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_friend_status_message.bind( - undefined, this.getHandle()), - cb : FriendStatusMessageCallback, - name : "FriendStatusMessage", - wrapper : function(handle, friend, buffer, size, userdata) { + api: this.getLibrary().tox_callback_friend_status_message.bind(undefined, this.getHandle()), + cb: FriendStatusMessageCallback, + name: "FriendStatusMessage", + wrapper: function (handle, friend, buffer, size, userdata) { var statusMessage = buffer.slice(0, size).toString(); - _this._emit("friendStatusMessage", new toxEvents.FriendStatusMessageEvent( - friend, statusMessage)); + _this._emit( + "friendStatusMessage", + new toxEvents.FriendStatusMessageEvent(friend, statusMessage) + ); }, }); }; @@ -3180,16 +3115,14 @@ Tox.prototype._initFriendStatusMessageCb = function() { * Initialize the friendStatus event callback. * @private */ -Tox.prototype._initFriendStatusCb = function() { +Tox.prototype._initFriendStatusCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_friend_status.bind(undefined, - this.getHandle()), - cb : FriendStatusCallback, - name : "FriendStatus", - wrapper : function(handle, friend, status, userdata) { - _this._emit("friendStatus", - new toxEvents.FriendStatusEvent(friend, status)); + api: this.getLibrary().tox_callback_friend_status.bind(undefined, this.getHandle()), + cb: FriendStatusCallback, + name: "FriendStatus", + wrapper: function (handle, friend, status, userdata) { + _this._emit("friendStatus", new toxEvents.FriendStatusEvent(friend, status)); }, }); }; @@ -3198,17 +3131,17 @@ Tox.prototype._initFriendStatusCb = function() { * Initialize the friendConnectionStatus event callback. * @private */ -Tox.prototype._initFriendConnectionStatusCb = function() { +Tox.prototype._initFriendConnectionStatusCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_friend_connection_status.bind( - undefined, this.getHandle()), - cb : FriendConnectionStatusCallback, - name : "FriendConnectionStatus", - wrapper : function(handle, friend, connection, userdata) { + api: this.getLibrary().tox_callback_friend_connection_status.bind(undefined, this.getHandle()), + cb: FriendConnectionStatusCallback, + name: "FriendConnectionStatus", + wrapper: function (handle, friend, connection, userdata) { _this._emit( - "friendConnectionStatus", - new toxEvents.FriendConnectionStatusEvent(friend, connection)); + "friendConnectionStatus", + new toxEvents.FriendConnectionStatusEvent(friend, connection) + ); }, }); }; @@ -3217,16 +3150,14 @@ Tox.prototype._initFriendConnectionStatusCb = function() { * Initialize the friendTyping event callback. * @private */ -Tox.prototype._initFriendTypingCb = function() { +Tox.prototype._initFriendTypingCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_friend_typing.bind(undefined, - this.getHandle()), - cb : FriendTypingCallback, - name : "FriendTypingStatus", - wrapper : function(handle, friend, typing, userdata) { - _this._emit("friendTyping", - new toxEvents.FriendTypingEvent(friend, typing)); + api: this.getLibrary().tox_callback_friend_typing.bind(undefined, this.getHandle()), + cb: FriendTypingCallback, + name: "FriendTypingStatus", + wrapper: function (handle, friend, typing, userdata) { + _this._emit("friendTyping", new toxEvents.FriendTypingEvent(friend, typing)); }, }); }; @@ -3235,16 +3166,14 @@ Tox.prototype._initFriendTypingCb = function() { * Initialize the friendReadReceipt event callback. * @private */ -Tox.prototype._initFriendReadReceiptCb = function() { +Tox.prototype._initFriendReadReceiptCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_friend_read_receipt.bind( - undefined, this.getHandle()), - cb : FriendReadReceiptCallback, - name : "FriendReadReceiptStatus", - wrapper : function(handle, friend, receipt, userdata) { - _this._emit("friendReadReceipt", - new toxEvents.FriendReadReceiptEvent(friend, receipt)); + api: this.getLibrary().tox_callback_friend_read_receipt.bind(undefined, this.getHandle()), + cb: FriendReadReceiptCallback, + name: "FriendReadReceiptStatus", + wrapper: function (handle, friend, receipt, userdata) { + _this._emit("friendReadReceipt", new toxEvents.FriendReadReceiptEvent(friend, receipt)); }, }); }; @@ -3253,18 +3182,16 @@ Tox.prototype._initFriendReadReceiptCb = function() { * Initialize the friendRequest event callback. * @private */ -Tox.prototype._initFriendRequestCb = function() { +Tox.prototype._initFriendRequestCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_friend_request.bind(undefined, - this.getHandle()), - cb : FriendRequestCallback, - name : "FriendRequestStatus", - wrapper : function(handle, publicKey, data, size, userdata) { + api: this.getLibrary().tox_callback_friend_request.bind(undefined, this.getHandle()), + cb: FriendRequestCallback, + name: "FriendRequestStatus", + wrapper: function (handle, publicKey, data, size, userdata) { publicKey = Buffer.from(publicKey); // Copy into persistent Buffer var message = data.slice(0, size).toString(); - _this._emit("friendRequest", - new toxEvents.FriendRequestEvent(publicKey, message)); + _this._emit("friendRequest", new toxEvents.FriendRequestEvent(publicKey, message)); }, }); }; @@ -3273,17 +3200,15 @@ Tox.prototype._initFriendRequestCb = function() { * Initialize the friendMessage event callback. * @private */ -Tox.prototype._initFriendMessageCb = function() { +Tox.prototype._initFriendMessageCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_friend_message.bind(undefined, - this.getHandle()), - cb : FriendMessageCallback, - name : "FriendMessage", - wrapper : function(handle, friend, type, data, size, userdata) { + api: this.getLibrary().tox_callback_friend_message.bind(undefined, this.getHandle()), + cb: FriendMessageCallback, + name: "FriendMessage", + wrapper: function (handle, friend, type, data, size, userdata) { var message = data.slice(0, size).toString(); - _this._emit("friendMessage", - new toxEvents.FriendMessageEvent(friend, type, message)); + _this._emit("friendMessage", new toxEvents.FriendMessageEvent(friend, type, message)); }, }); }; @@ -3292,16 +3217,14 @@ Tox.prototype._initFriendMessageCb = function() { * Initialize the fileRecvControl event callback. * @private */ -Tox.prototype._initFileRecvControlCb = function() { +Tox.prototype._initFileRecvControlCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_file_recv_control.bind( - undefined, this.getHandle()), - cb : FileRecvControlCallback, - name : "FileRecvControlCallback", - wrapper : function(handle, friend, file, control, userdata) { - _this._emit("fileRecvControl", - new toxEvents.FileRecvControlEvent(friend, file, control)); + api: this.getLibrary().tox_callback_file_recv_control.bind(undefined, this.getHandle()), + cb: FileRecvControlCallback, + name: "FileRecvControlCallback", + wrapper: function (handle, friend, file, control, userdata) { + _this._emit("fileRecvControl", new toxEvents.FileRecvControlEvent(friend, file, control)); }, }); }; @@ -3310,16 +3233,17 @@ Tox.prototype._initFileRecvControlCb = function() { * Initialize the fileChunkRequest event callback. * @private */ -Tox.prototype._initFileChunkRequestCb = function() { +Tox.prototype._initFileChunkRequestCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_file_chunk_request.bind( - undefined, this.getHandle()), - cb : FileChunkRequestCallback, - name : "FileChunkRequestCallback", - wrapper : function(handle, friend, file, position, length, userdata) { - _this._emit("fileChunkRequest", new toxEvents.FileChunkRequestEvent( - friend, file, position, length)); + api: this.getLibrary().tox_callback_file_chunk_request.bind(undefined, this.getHandle()), + cb: FileChunkRequestCallback, + name: "FileChunkRequestCallback", + wrapper: function (handle, friend, file, position, length, userdata) { + _this._emit( + "fileChunkRequest", + new toxEvents.FileChunkRequestEvent(friend, file, position, length) + ); }, }); }; @@ -3328,23 +3252,20 @@ Tox.prototype._initFileChunkRequestCb = function() { * Initialize the fileRecv event callback. * @private */ -Tox.prototype._initFileRecvCb = function() { +Tox.prototype._initFileRecvCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_file_recv.bind(undefined, - this.getHandle()), - cb : FileRecvCallback, - name : "FileRecvCallback", - wrapper : function(handle, friend, file, kind, size, filename, length, - userdata) { + api: this.getLibrary().tox_callback_file_recv.bind(undefined, this.getHandle()), + cb: FileRecvCallback, + name: "FileRecvCallback", + wrapper: function (handle, friend, file, kind, size, filename, length, userdata) { // Filename might be NULL, probably if file kind is AVATAR or non-DATA if (ref.address(filename) !== 0) { filename = ref.reinterpret(filename, length).toString("utf8"); } else { filename = undefined; } - _this._emit("fileRecv", new toxEvents.FileRecvEvent(friend, file, kind, - size, filename)); + _this._emit("fileRecv", new toxEvents.FileRecvEvent(friend, file, kind, size, filename)); }, }); }; @@ -3353,24 +3274,21 @@ Tox.prototype._initFileRecvCb = function() { * Initialize the fileRecvChunk event callback. * @private */ -Tox.prototype._initFileRecvChunkCb = function() { +Tox.prototype._initFileRecvChunkCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_file_recv_chunk.bind(undefined, - this.getHandle()), - cb : FileRecvChunkCallback, - name : "FileRecvChunkCallback", - wrapper : function(handle, friend, file, position, data, size, userdata) { + api: this.getLibrary().tox_callback_file_recv_chunk.bind(undefined, this.getHandle()), + 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? if (ref.address(data) !== 0) { - data = - Buffer.from(ref.reinterpret(data, size)); // Copy to another Buffer + data = Buffer.from(ref.reinterpret(data, size)); // Copy to another Buffer } else { data = undefined; } - _this._emit("fileRecvChunk", new toxEvents.FileRecvChunkEvent( - friend, file, position, data)); + _this._emit("fileRecvChunk", new toxEvents.FileRecvChunkEvent(friend, file, position, data)); }, }); }; @@ -3379,14 +3297,13 @@ Tox.prototype._initFileRecvChunkCb = function() { * Initialize the friendLosslessPacket event callback. * @private */ -Tox.prototype._initFriendLosslessPacketCb = function() { +Tox.prototype._initFriendLosslessPacketCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_friend_lossless_packet.bind( - undefined, this.getHandle()), - cb : FriendLosslessPacketCallback, - name : "FriendLosslessPacketCallback", - wrapper : function(handle, friend, data, length, userdata) { + api: this.getLibrary().tox_callback_friend_lossless_packet.bind(undefined, this.getHandle()), + cb: FriendLosslessPacketCallback, + name: "FriendLosslessPacketCallback", + wrapper: function (handle, friend, data, length, userdata) { // 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 @@ -3398,8 +3315,7 @@ Tox.prototype._initFriendLosslessPacketCb = function() { throw new Error("NULL data packet"); } data = Buffer.from(ref.reinterpret(data, length)); - _this._emit("friendLosslessPacket", - new toxEvents.FriendPacketEvent(friend, data, true)); + _this._emit("friendLosslessPacket", new toxEvents.FriendPacketEvent(friend, data, true)); }, }); }; @@ -3408,20 +3324,18 @@ Tox.prototype._initFriendLosslessPacketCb = function() { * Initialize the friendLossyPacket event callback. * @private */ -Tox.prototype._initFriendLossyPacketCb = function() { +Tox.prototype._initFriendLossyPacketCb = function () { var _this = this; this._initCallback({ - api : this.getLibrary().tox_callback_friend_lossy_packet.bind( - undefined, this.getHandle()), - cb : FriendLossyPacketCallback, - name : "FriendLossyPacketCallback", - wrapper : function(handle, friend, data, length, userdata) { + api: this.getLibrary().tox_callback_friend_lossy_packet.bind(undefined, this.getHandle()), + cb: FriendLossyPacketCallback, + name: "FriendLossyPacketCallback", + wrapper: function (handle, friend, data, length, userdata) { if (ref.address(data) === 0) { throw new Error("NULL data packet"); } data = Buffer.from(ref.reinterpret(data, length)); - _this._emit("friendLossyPacket", - new toxEvents.FriendPacketEvent(friend, data, false)); + _this._emit("friendLossyPacket", new toxEvents.FriendPacketEvent(friend, data, false)); }, }); };