NativeScript & SocketIO: Can't find variable: SocketManager - socket.io

I'm trying to integrate Backendless JS-SDK into the NativeScript application.
The JS-SDK is dependent on socket.io.client module which is not supported in the NS environment.
So, the first problem with the socket.io.client module I've solved by adding an alias in the custom webpack.json
const webpackConfig = require("./webpack.config");
module.exports = (env) => {
env = env || {};
env.alias = Object.assign({}, env.alias, {
'socket.io-client': 'nativescript-socketio'
});
return webpackConfig(env);
}
but after that, I started receiving another error: Object is not a function (near '...io...')
and I tried to change initializing SocketIO instance as it described here nativescript-socket.io
and now I get another error: Can't find variable: SocketManager, after some investigation I found the code line where the error comes from, ``:
socketio.ios.js#130
Has anybody got this error?
Thanks in advance for any help!

Related

Solana Hello World Example in Documentation Uses Deprecated Functions

I am working through the hello world example and am getting an error when I compile with node. The issue is
let airdropSignature = await connection.requestAirdrop(
SyntaxError: await is only valid in async functions and the top level bodies of modules
It appears here that the connection.confirmTransaction is deprecated. In my VS code, I see a cross through the "confirmTransaction" portion of my code indicating an error there. How can I correct the code so that I avoid this error? Should the hello_world example in the documentation be updated to reflect this?
Your code is running into two problems:
the confirmTransaction method is not fully deprecated
your code is incorrectly using JavaScript async/await
1. confirmTransaction method is not fully deprecated
The #solana/web3.js method you (and the example code from the Solana docs) are using is not a fully deprecated method. But rather, the desired parameter format changed.
NOTE: You can see the source code of the confirmTransaction method here which may help you see the difference.
So in a sense, the confirmTransaction(string_of_tx_sig) format was deprecated. The new desired parameter format should pass an object as the first parameter, with the signature field defined. Like this:
await connection.confirmTransaction({ signature: airdropSignature });
Updating your code to using this updated parameter format will get rid of the "deprecated method line through". But either way, this should not cause your code to fail like it is.
2. Incorrect usage of async/await
The specific error message you are getting is due to the improper use of JavaScript's async/await functions.
Since you did not include much of your source code, I am guessing that you are attempting to call the await connection.requestAirdrop() function out side of an async function.
Perhaps just in the normal flow of a single JavaScript function like this:
const web3 = require("#solana/web3.js");
let airdropSignature = await connection.requestAirdrop(
payer.publicKey,
web3.LAMPORTS_PER_SOL
);
// using the deprecated parameter
await connection.confirmTransaction(airdropSignature);
Attempting to run this code above will result in the specific error message you gave since the requestAirdrop is not being run inside of a async function.
You can fix code in a few different ways, either:
creating a new "named" function with the async keyword before it, adding all the code above to within that function, then running that function. or,
creating an "arrow" fucntion that does effectively the same thing as the option above
For example:
Using a "named" function:
const web3 = require("#solana/web3.js");
async function main(){
let airdropSignature = await connection.requestAirdrop(
payer.publicKey,
web3.LAMPORTS_PER_SOL
);
// using the non-deprecated parameter
await connection.confirmTransaction({ signature: airdropSignature });
}
// now run the "named" function
main()
Using an "arrow" function:
const web3 = require("#solana/web3.js");
// create an run an inline "arrow" function
const runs_automatically = async () => {
let airdropSignature = await connection.requestAirdrop(
payer.publicKey,
web3.LAMPORTS_PER_SOL
);
// using the non-deprecated parameter
await connection.confirmTransaction({ signature: airdropSignature });
}
NOTE: We do not need to call our "arrow" function for it to execute the function's internal logic, unlike the "named" function
You can read more about arrow functions here on the Moz JavaScript docs.

Accessing webpack variables from Nativescript 6.1 Core typescript file

I have a NS 6.1 Core application. In webpack I want to add a variable which I want to access later in a typescript file. Here is my code:
// Define useful constants like TNS_WEBPACK
new webpack.DefinePlugin({
"global.TNS_WEBPACK": "true",
"process": "global.process",
"myGlobal.environment": JSON.stringify(env.mode|| 'not defined'),
}),
TS:
declare let myGlobal: any;
export function onLoaded(e) {
page = <Page>e.object;
console.log('myGlobal.environment: ' + myGlobal.environment);
}
The problem I am facing is that myGlobal is not defined when I run the code.
I tried deleting the platforms folder and rebuilding, but I get the same error.
Any ideas on what I might be doing wrong?
The thing is that the env constant is not having a mode property but a boolean called production. Here is what env looks like
const {
// The 'appPath' and 'appResourcesPath' values are fetched from
// the nsconfig.json configuration file.
appPath = "app",
appResourcesPath = "app/App_Resources",
// You can provide the following flags when running 'tns run android|ios'
snapshot, // --env.snapshot
production, // --env.production
uglify, // --env.uglify
report, // --env.report
sourceMap, // --env.sourceMap
hiddenSourceMap, // --env.hiddenSourceMap
hmr, // --env.hmr,
unitTesting, // --env.unitTesting,
verbose, // --env.verbose
snapshotInDocker, // --env.snapshotInDocker
skipSnapshotTools, // --env.skipSnapshotTools
compileSnapshot // --env.compileSnapshot
} = env;
As in JavaScript undefined equals false (for booleans), that means that if a release flag is not passed explicitly, the production will always be undefined (false). So you could do the following:
"myGlobal.environment": JSON.stringify(env.production || "development")
Or on second thought more like
"myGlobal.environment": JSON.stringify(env.production ? "production" : "development")

Nightwatch using expect in url callback, result.value is undefined

I'm messing around with Nightwatch and I have a test setup like the following:
module.exports = {
'Load index page with default category' : function(browser)
{
browser
.url(browser.launch_url)
.waitForElementPresent('body', 1000)
.url((result)=>
{
console.log(result.value) // http://example.com/something/
browser.expect.result.value.to.contain("something");
// TypeError: Cannot read property 'to' of undefined
})
.end();
}
}
I'm confused how I'm supposed to use result.value with expect.
result.value logs as expected, but I can't verify it.
I can use browser.assert.urlContains("something"), but I was trying to use expect instead.
You can use chai library directly but PASS will not be in report while FAIL will be shown.
https://github.com/nightwatchjs/nightwatch/issues/601

usage of JS plugins with webpack

I am trying to reconfigure my Symfony 3 project to use webpack encore instead of normal asstets. I am a little stuck with this.
For one part of the application I developed some JS plugins which inherits from Kube (a CSS and JS Framework I am unsing). Here is an exmaple:
(function (Kube) {
Kube.Assignment = function (element, options) {
this.namespace = 'assignment';
this.defaults = {
//...
};
Kube.apply(this, arguments);
this.start();
};
Kube.Assignment.prototype = {
start: function () {
//...
}
};
Kube.Assignment.inherits(Kube.Distribution);
Kube.Plugin.create('Assignment');
Kube.Plugin.autoload('Assignment');
}(Kube));
Unfortunatly Kube is not recognized.
The module 'imperavi-kube' is installed via yarn and is imported via
let Kube = require('imperavi-kube');
I am getting the following error: TypeError: Kube.Assignment.inherits is not a function
Propably this is not a issue of the Kube Framework but somthing about handeling JS plugins with webpack.
Inside the Kube module there is a class 'Kube' defined with a prototype. The Prototype ends with window.Kube = Kube;
Try to import Kube like this:
import * as Kube from <your path> or <alias> or <module name>
I may be wrong, but as far as I remember sometimes it works a bit differently.

Cannot convert value of type (CMAccelerometerData!,NSError!)->() to CMAccelerometerHandler(aka(Optional<CMAccelerometerData>,Optional<NSError>)-<())

I recently upgraded my xcode from version 6.3.1 to xcode 7.1 beta. I am using CMMotionManger and the following code shows error in new version. I tried resolving it but could not find the solution. Thanks in Advance.
Code:
let motionManager=CMMotionManager()
motionManager.accelerometerUpdateInterval = 0.2
if(motionManager.accelerometerAvailable)
{
motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue.currentQueue()!, withHandler: { in
(accelerometerData: CMAccelerometerData!, error: NSError!) in
let acceleration = accelerometerData.acceleration
self.accelerationX = CGFloat(acceleration.x)
})
}
error Encountered:
Cannot convert value of type '(CMAccelerometerData!,NSError!)->()'to expected argument type 'CMAccelerometerHandler'(aka'(Optional,Optional)-<()')
Got the answer. Tried many things and the following worked.
Declare the accelerometerData,error as below and use directly the variables inside the handler block.
let _:CMAccelerometerData!
let _:NSError!
let _:CMAccelerometerData!
let _:NSError!
if(motionManager.accelerometerAvailable)
{
motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue.currentQueue()!, withHandler: {
accelerometerData,error in
let acceleration = accelerometerData!.acceleration
self.accelerationX = CGFloat(acceleration.x)
})
and it works.:)

Resources