Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

nodejs-mobile-cordova - IONIC 3/4 support #129

Closed
andreddosantos opened this issue Oct 1, 2018 · 7 comments
Closed

nodejs-mobile-cordova - IONIC 3/4 support #129

andreddosantos opened this issue Oct 1, 2018 · 7 comments

Comments

@andreddosantos
Copy link

Hello guys,

I cant seem to find any working tutorial where the "nodejs-mobile-cordova" is integrated with IONIC framework. Do you know of any code sample that could be used as an example for the integration?

Thanks

@jaimecbernardo
Copy link
Member

Hi @andreddosantos,

This has been answered in the project's gitter, so I'll also quote the answer here:

There isn't any ionic sample available, since it's not one of the supported frameworks. Some issues seem to indicate that other users have been able to use it with ionic. Search the issues for ionic for older issues where it was being used.

@jaimecbernardo
Copy link
Member

If you've been able to make it run in Ionic since then, this issue would be a good place to share how you've been able to do it.
Opening a PR with an Ionic sample in https://github.com/janeasystems/nodejs-mobile-samples would be a welcome contribution, as well.

@andreddosantos
Copy link
Author

Hi @jaimecbernardo,

I've manage with some simple steps use this plugin in Ionic 4 with angular 6.

  1. Install the plugin
  2. Create new directory called "root/nodejs-project" (you can pace it almost anywhere you want ;))
  3. add it to angular.json in the assets array

{ "glob": "**/*", "input": "./nodejs-project", "output": "./nodejs-project" }
4. In typings.d.ts declare a new variable nodejs
declare var nodejs; //The typings.d.ts file isn't present on the initial app structure create by the Ionic CLI, but it can just be added in src/typings.d.ts
5. start the server in app.component.ts
if (this.platform.is('cordova')) { this.startNodeProject(); }

Regards
André

@jaimecbernardo
Copy link
Member

Thank you, @andreddosantos .
This will be useful to point other Ionic users to :)

@mjp0
Copy link

mjp0 commented Oct 5, 2018

Thanks @andreddosantos! I wonder if you can help me to get over the last issue I'm having with this. For some reason I can't get nodejs to start. I've tried few various ways to get startNodeProject() to run but nothing has worked so far. I added if (this.platform.is('cordova')) { this.startNodeProject(); } in initializeApp() in app.component.ts and modified stardard nodejs-mobile's ios js files to export startNodeProject():

export default startNodeProject = () => {
  nodejs.channel.setListener(channelListener);
  nodejs.start('main.js', startupCallback);
};

I then import this into app.component.ts and try to call it but I don't see Node.js mobile... in XCode's console but I do see following lines indicating that plugin is loading correctly:

2018-10-05 13:54:34.849426+0200 myApp[56630:27910759] [CDVTimer][nodejs] 0.669956ms
2018-10-05 13:54:34.850028+0200 myApp[56630:27910759] [CDVTimer][TotalPluginStartup] 40.035009ms
2018-10-05 13:54:35.210634+0200 myApp[56630:27910759] -[CDVNodeJS onReset]
2018-10-05 13:54:37.031720+0200 myApp[56630:27910759] -[CDVNodeJS setAllChannelsListener:]

@jaimecbernardo
Copy link
Member

Hi @0fork ,
@andreddosantos contributed a sample, as well, which is under review int this PR, in case it helps: JaneaSystems/nodejs-mobile-samples#10

@altinselimi
Copy link

altinselimi commented Nov 23, 2018

@andreddosantos Hey that's great. I'm using ionic 4.11 and angular 5, which doesn't have the angular.json (angular-cli) incorporated. What would be the best way to complete Step 3 without angular-cli. Should I make some changes on the webpack config or is there a way to install ng-cli in an existing project ?

EDIT: Also, typescript is throwing errors because nodejs is undefined. Got any ideas how can I fix this ?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants