Using the JavaScript Distribution

This page provides important information for users of the Ice for JavaScript distribution.

On this page:

Overview of the Ice for JavaScript Distribution

Ice for JavaScript is available as a npm package. The following npm packages are provided for Node.js developers:

  • ice - Ice for JavaScript run time
  • slice2js - Slice-to-JavaScript compiler
  • gulp-ice-builder - Gulp plug-in to integrate slice2js with the gulp build system


Installing the Ice for JavaScript Distribution

Using NPM

Install the Ice for JavaScript run time libraries using npm:

 npm install ice --save

This package also includes the browser version of Ice for JavaScript in node_modules/lib.

Using CDN

Ice for JavaScript browser libraries are available at https://cdnjs.com/libraries/ice/3.7.100

Slice-to-JavaScript Compiler

The Slice-to-JavaScript compiler (slice2js) can be installed with this command:

npm install --save-dev slice2js

This command builds the compiler from source therefore you must have a supported C++ compiler installed.

In order to use slice2js on the command line, use the npm --global option to install this package.

The slice2js package includes all of the standard Slice files and automatically adds the slice directory to the include file search path.

Using Ice for JavaScript

The Ice manual provides a complete description of the JavaScript mapping.

Node.js Applications

You can use several top-level Ice packages in your Node.js applications, as shown below:

JavaScript
const {Ice, Glacier2, IceStorm, IceGrid} = require('ice').Ice;
const communicator = Ice.initialize(process.argv);
const proxy = communicator.stringToProxy("hello:tcp -h localhost -p 10000");

Browser Applications

Add the necessary <script> tags to your html to include the Ice for JavaScript components you require:

<script src="https://cdnjs.cloudflare.com/ajax/libs/ice/3.7.100/Ice.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ice/3.7.100/Glacier2.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ice/3.7.100/IceStorm.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ice/3.7.100/IceGrid.js"></script>
<script type="text/javascript">

const communicator = Ice.initialize();
const proxy = communicator.stringToProxy("hello:ws -h localhost -p 10002");
</script> 

For older browsers that do not support all of the required EcmaScript 6 features used by Ice for JavaScript, we provide a pre-compiled version of the libraries using the Babel JavaScript compiler. These libraries depend on the babel polyfill run time and are available in the es5 subdirectory with the same names as the main libraries:

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.23.0/polyfill.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ice/3.7.100/es5/Ice.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ice/3.7.100/es5/Glacier2.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ice/3.7.100/es5/IceStorm.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ice/3.7.100/es5/IceGrid.js"></script>
<script type="text/javascript">

const communicator = Ice.initialize();
const proxy = communicator.stringToProxy("hello:ws -h localhost -p 10002");
</script> 

Minified versions are available with the .min.js extension.

Slice-to-JavaScript Compiler

You can execute the Slice-to-JavaScript compiler from code as shown below:

JavaScript
var slice2js = require('slice2js');
slice2js.compile(["Hello.ice"]);

If you installed the slice2js package globally, you can also run slice2js on the command line.

Refer to the manual for a description of the arguments accepted by slice2js.

 

Using the Sample Programs

The Ice sample programs are provided in a GitHub repository. You can browse this repository to see build and usage instructions for all supported programming languages. Simply clone this repository:

git clone -b 3.7 https://github.com/zeroc-ice/ice-demos.git
cd ice-demos