DEVELOPERS BLOG

Building and Porting WebWorks Plugins with the Open Academy

UCOSP

This past term with the Open Academy project was quite productive. Many of you will be familiar with the program and its Canadian University version called UCOSP. If not, the program invites upper year university students to contribute to open source projects for a term and get course credit. We have been working with the program for two full years now, both with the Canadian program in the fall and the International version in the winter term.

With the launch of WebWorks 2.0 during this term, we focused on porting plugins from the WebWorks 1.0 format and added a few useful ones as well. In all, we ported seven plugins to the new format, added two new ones and new features to two more. You can see our plugins in our repository here.

Before we talk about what’s next with the program, let’s hear from three of the participants in their own words. First up is James from Brock University in Ontario:

I started the semester working on porting over the vibration plugin. This took some time since I had a new system to learn. Luckily with available templates and native code for the plugin, the task was not too hard. It was time-consuming to learn the differences between the old plugin and the WebWorks 2.0/Cordova structure.

By the end of the code sprint at Facebook I was able to finish up the vibration plugin with Tim’s help to ensure everything that was needed had been done, including allowing it have a callback function, which again took some time to figure out went somewhat smoothly. The code sprint was a fantastic opportunity for us to get some work done and get immediate help from our mentors, making the first plugin ports much easier to understand so that we could contribute our work to the open source WebWorks plugins.

After I finished the vibration plugin, it was time to start working on writing a new plugin. I decided I was up to the challenge of working on an audio recorder plugin. Now I had to learn more about the native code. I had a slight idea of how it all worked from working on porting the last plugin, but I had never used BlackBerry native code before. Luckily I had some experience with C++ so writing the code was not too difficult.

The difficult part was making sure that everything worked together: the native code, the JavaScript code, as well as ensuring that I was calling the functions properly in the test app. After figuring out which libraries I had to import, and which functions needed to be called to get the device to record and save an audio file using the audiorecorder documentation, the plugin was now finished. The hardest part of this plugin was that I needed to save an audio file to see if it worked; if a file didn’t show up, then it meant I made a mistake, but there were many places that the error could be. That took up a lot of my time until I decided to start over with the knowledge I had gained, and it took no time at all to get the plugin working. Soon I was able to see an audio file saved in the directory I told it to save to.

I have had the opportunity to learn a lot in the past couple months and consider it valuable to my education. It should help me when I am finished with school and working on real world projects. It is exciting to see that WebWorks 2.0 has gone gold during the duration of the semester and hopefully developers will make use of our plugins to make things easier for them while working with WebWorks/Cordova.

Thanks to Tim for his help; it sounds like the whole group working on the BlackBerry plugins is getting a lot done and learning a lot while doing it.

Second, let’s hear from Morgan of Simon Fraser University in British Columbia:

I’d like to talk about a few topics: briefly my reasons for entering UCOSP and choosing to work on BlackBerry 10 WebWorks plugins, what open source software has come to mean to me because of UCOSP, the plugins that I have ported from WebWorks 1.0 to 2.0 and finally my next WebWorks project.

As a university student, I saw UCOSP as an opportunity to expand my programming knowledge and resume with real world experience. I chose to work on WebWorks because I have been a fan of BlackBerry since the release of BlackBerry 10, and also because WebWorks plugin development provides me an ideal mix of new languages and paradigms to learn – the web programming side – and a language I have plenty of experience with: C++. The fact that WebWorks was open source appealed to me but was not a significant factor in my choice of project.

However, through my experience with WebWorks I have learned to appreciate open source as a platform of opportunity: a platform to gain experience, to learn, to create, and to contribute to the community. Open source helps build experience and knowledge at the same time by allowing easy access to fantastic projects to contribute to, and the opportunity to study code by other developers.

Open source also allows us to build and monetize our own ideas. For example, as a gamer and developer I have always wanted to create games, and the MIT licensed Cocos2d-X has provided me with an excellent avenue to create my own inventions. Cocos2d-X is a mobile 2d game engine built to provide easy access to beginner developers and enough power to experienced developers, all the while providing cross-platform support. It is easy to understand: every game object in your game is a subclass of a class called CCNode, which implements the composite pattern. By creating a CCScene class to act as the backdrop of your game, and by adding CCSprite objects as children to CCScene, a game can be easily populated with sprites. These sprites can then be manipulated and animated by passing in CCActions to their “runAction” interface inherited from CCNode. And because CCNode implements the composite pattern, any action ran on it is ran on its children.

If you are interested in making 2d games for BlackBerry visit the Cocos2d-X webpage and read this article on the BlackBerry developer blog. A version that enables HTML5 development can be found here.

Finally, open source projects allow contribution to communities. The open source nature of WebWorks has afforded me the opportunity to contribute to the BlackBerry community. During the spring semester I ported two plugins from WebWorks 1.0 to 2.0. The first is a thumbnail plugin which can resize images, and the second is a screenshot plugin. My next project is to extend the functionality of the ExtractZipFile plugin to enable it to be able to compress files and folders using Minizip into .zip format. I hope you found this post inspiring!

Finally, let’s hear from Alexandre of the Université de Sherbrooke in Quebec:

The first thing we had to do was to port a plugin from WebWorks to WebWorks 2/Cordova. My plugin was DeviceInfo. DeviceInfo is used to give the developer some information about the device, such as the phone model, the type of keyboard, the mobile country code and much more. The task has been more challenging than expected. Since the plugins use many different frameworks and languages (BlackBerry SDK, JNEXT, Cordova, C++, JavaScript), I had a lot of difficulty understanding each of them and their relation to one another. Also, I had some difficulties using the WebWorks framework itself and the Momentics IDE. However, once everything had been mastered, the process went perfectly.

On the weekend of February 7th – 9th we had the chance to visit Facebook’s headquarters in Menlo Park, California. On the first day, Scott Chacon spoke about Git and GitHub. We learned how to use Git and GitHub; one of the most useful points of this was to learn how to do a pull request. Since all our plugins are hosted on GitHub, this talk was very useful. Afterwards we moved to Facebook’s office to start the sprint.

The purpose of the weekend was to meet our team and talk with our mentor, Tim Windsor, about the projects and ask our questions. During that weekend, I finished porting the DeviceInfo plugin and started a pull request to merge it with the community repository. At the end of the sprint I was assigned my second task: to port the ScreenDisplay plugin. Porting the ScreenDisplay went pretty easily since it was the second plugin I worked on.

My third and final task was to create a new plugin called EmailSender. The purpose of this plugin is to be able to send an email directly from an app not using BlackBerry’s composer. This task was the most challenging of all, since it used some libraries I’ve never used during the semester. I also discovered that I had to set some permissions for the app to be able to use the plugin. Finally, after my pull request, our mentor asked me to add a new feature to the plugin: to allow the user to be able to select an email account on the device instead of using the default account.

This last semester was very nice and I learned a lot about the open source community, GitHub, BlackBerry and working in a remote environment. During our weekly meeting with our mentor, we had the chance to ask questions and get updates from the team. Tim was always there for us to answer our questions and helping us; thank you Tim!

UCOSP is going to try a new spring/summer term this year with four students. We’re going to continue to work on plugins, focusing specifically on the rest of the PhoneGap-Build plugins to add BlackBerry 10 support.

We’ll be starting with a kickoff event on May 12 and 13 at the BlackBerry Jam Space in the Communitech Hub. If you’re interested in following along with the student project, watch #bbucosp on twitter, and all the code will be going into the public BlackBerry repositories on GitHub.

If you want to get involved yourself, contact me to get started: @timothywindsor on Twitter or on GitHub.

About timwin1