• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

heroku/mobile-template1

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

heroku/mobile-template1

开源软件地址(OpenSource Url):

https://github.com/heroku/mobile-template1

开源编程语言(OpenSource Language):

JavaScript 79.9%

开源软件介绍(OpenSource Introduction):

Heroku template mobile app Quiz Live

This sample application implements a simple "live quiz" mobile game. The mobile app itself is a hybrid AngularJS app composed of HTML, CSS and Javascript. The server side is implemented as an Express Node.js application running on top of a Postgres database.

This application should serve as a good base for creating mobile apps to deploy on Heroku.

Deploy

How to play

A set of players opens the app on their phones and registers to play. The app maintains this list of users plus a set of quiz questions. During the game, questions are presented to each user running the app, and points are awarded for correct answers to questions. As players earn points a realtime leaderboard is displayed to each player.

Notification of new questions and answer results are broadcast via Websocket to the mobile app using the SocketIO library.

Game screenshot

Admin screenshot

Architecture

The app has two major pieces: An AngularJS based client app which comprises the front-end which runs on the phone, and a Node.js backend which provides an API to the client app for user registration, data storage, and event broadcast.

/---mobile app-----\
| Ionic framework  |
| Angular JS       |
\------------------/
       |
       | http / websocket
       |
/-------Node.js app-\
|                   |
| express           |
|   bookshelf       |
|      node-pg      |
\-------------------/
       |
   [Postgres DB]

Deployment

The app can be deployed to Heroku, and distributed to the mobile device either through the mobile web browser, or by compiling the AngularJS application into a native app using an Apache Cordova container.

Installation and setup

Clone this repo to your local machine and install the requirements:

npm install

Now create a database on your local server called quizlive:

createdb quizlive

Now create the database schema and initial data:

./bootstrap.sh

And now run the server app:

node server.js

and open the client app:

http://localhost:5000

From the home screen click "Register". Enter your name and email and click Register. The first user is automatically marked as the administrator. Click the Open Admin Page link on the quiz page.

On the admin page, use the following controls

Next Question - queue up the next quiz question Restart Quiz - erase all current scores and start over

As you click Next Question a new question will appear automatically for anyone running the app. Additional users can register for the app and play at the same time. Users accumulate points by answering questions correctly, with a bonus awarded to the person who answers correctly first.

Deploy to Heroku

When you are ready to share the app, just create a new Heroku app, provision a Postgres database addon for your app, and then deploy the code. After you deploy you should bootstrap the database:

$ heroku run ./bootstrap.sh

Understanding the code

The components of the application are organized as follows:

component folder
client app client
..app code client/js
..html templates client/templates
..ionic/angular frameworks client/lib
express app server.js, server/*
..db migrations server/migrations
..question list server/load_question.js
admin app admin

Front-end app

The front-end app is an AngularJS single page application. Thus all the HTML and Javascripted are loaded and run in a single WebView control on the phone. Different screens and navigation are all drawn in the browser DOM.

Angular

Accessing Force.com

As an option, the app can be configured so that each person who registers to play is recorded as a Lead record in Salesforce. This template shows how to access the Force.com API to exchange data with a Salesforce account. See FORCE_README for full instructions.

Debugging

Install node-debug to use the Chrome debugger with Node.js:

$ npm install node-debug

And to use, just run with node-debugger. After the Chrome debugger opens, make sure to click Run so the server starts:

$ node-debug server.js

Building a native app

To bundle your client app as a native mobile app, you can use the Cordova tool. Note that to build a native app you will need the corresponding native build tools. So for iOS apps you will need Xcode installed, and for Android apps you will need to have the Android SDK installed.

Install Cordova:

$ sudo npm install -g cordova

Install an application simulator:

$ sudo npm install -g ios-sim

Initialize the wrapper:

$ mkdir wrapper
$ cd wrapper
$ cordova create . QuizLive
$ rm -rf www
$ ln -s ../client www

Now add one or more platform targets:

$ cordova platform add ios
$ cordova platform add android

Now build the native app:

$ cordova compile ios

And run in the emulator:

$ cordova run --emulator

Fixing AJAX calls

The Ajax calls used in the Angular client are written using simple relative paths. This means that they automatically use the host value inferred from the domain which served the client JS files. This all works properly when the client app is served from a web server.

However, when you package the client files into the Cordova wrapper, then they are provided to the mobile device from the local filesystem, rather than being served from the web. As a result there is no domain to tell the Ajax calls where to go. To correct this, you need to specify your web domain explicitly in all client Ajax calls, such as the login call:

https://github.com/heroku/mobile-template1/blob/master/client/js/services.js#L80

Contact

Scott Persinger [email protected]

License

See LICENSE. This code is available under the MIT license.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
polinema-mobile/2019-mobile03发布时间:2022-08-30
下一篇:
commadelimited/jQuery-Mobile-Icon-Pack: Extending the default jQuery Mobile icon ...发布时间:2022-08-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap