Javascript
Oracle JET
Oracle JET 3 – How to add third party libraries – For example socket.io
yo oraclejet socketIoIntegration --template=basic
{
"name": "v7-LED-APP",
"version": "1.0.0",
"description": "virtual7 LED APP",
"author": {
"name": "Enno Schulte",
"homepage": "https://blog.virtual7.de"
},
"dependencies": {
"oraclejet": "~3.0.0",
"socket.io-client": "*"
},
"devDependencies": {
"font-awesome": "^4.7.0",
"grunt": "^1.0.1",
"grunt-oraclejet": "~3.0.0",
"load-grunt-config": "0.19.2",
"node-sass": "^4.2.0",
"oraclejet-tooling": "~3.0.0",
"ws": "2.3.1"
},
"engines": {
"node": ">=0.10.0"
},
"private": true
}

Project structure with integrated socket.ioSeems like we have all we need to get started. Now comes the tricky part. To use our newly added library we need to make a reference in the oracle jet-build.js script. In older versions you had to add your 3rd party libraries to a bower-copy task. Now all we need to do, is to tell this build script from where to where it should copy our library files.
copyCustomLibsToStaging: {
fileList: [{cwd: 'node_modules/socket.io-client/dist/',
src: ['**', '!test.js'],
dest: 'web/js/libs/socket.io-client'}]
},
{
"knockout": "libs/knockout/knockout-3.4.0",
"jquery": "libs/jquery/jquery-3.1.0.min",
"jqueryui-amd": "libs/jquery/jqueryui-amd-1.12.0.min",
"promise": "libs/es6-promise/es6-promise.min",
"hammerjs": "libs/hammer/hammer-2.0.8.min",
"ojdnd": "libs/dnd-polyfill/dnd-polyfill-1.0.0.min",
"ojs": "libs/oj/v2.2.0/min",
"ojL10n": "libs/oj/v2.2.0/ojL10n",
"ojtranslations": "libs/oj/v2.2.0/resources",
"text": "libs/require/text",
"signals": "libs/js-signals/signals.min",
"socket.io": "libs/socket.io-client/dist/socket.io.slim"
}
requirejs.config(
{
baseUrl: 'js',
// Path mappings for the logical module names
paths: //injector:mainReleasePaths
{
'knockout': 'libs/knockout/knockout-3.4.0.debug',
'jquery': 'libs/jquery/jquery-3.1.1',
'jqueryui-amd': 'libs/jquery/jqueryui-amd-1.12.0',
'promise': 'libs/es6-promise/es6-promise',
'hammerjs': 'libs/hammer/hammer-2.0.8',
'ojdnd': 'libs/dnd-polyfill/dnd-polyfill-1.0.0',
'ojs': 'libs/oj/v3.0.0/debug',
'ojL10n': 'libs/oj/v3.0.0/ojL10n',
'ojtranslations': 'libs/oj/v3.0.0/resources',
'text': 'libs/require/text',
'signals': 'libs/js-signals/signals',
'customElements': 'libs/webcomponents/CustomElements',
'proj4': 'libs/proj4js/dist/proj4-src',
'css': 'libs/require-css/css',
'socket.io': 'libs/socket.io-client/socket.io.slim',
'colorModel': 'models/colorModel'
}
//endinjector
// Shim configurations for modules that do not expose AMD
shim: {
'jquery': {
exports: ['jQuery', '$']
},
'socket.io': {
exports: ['io']
}
}
}
);
require(['ojs/ojcore', 'knockout', 'appController', 'socket.io', 'ojs/ojknockout',
'ojs/ojmodule', 'ojs/ojrouter', 'ojs/ojnavigationlist', 'ojs/ojbutton', 'ojs/ojtoolbar'],
function (oj, ko, app, io) { // this callback gets executed when all required modules are loaded
$(function () {
console.log('Socket.IO Protocol: ', io.protocol);
function init() {
oj.Router.sync().then(
function () {
// Bind your ViewModel for the content of the whole page body.
ko.applyBindings(app, document.getElementById('globalBody'));
},
function (error) {
oj.Logger.error('Error in root start: ' + error.message);
}
);
}
// If running in a hybrid (e.g. Cordova) environment, we need to wait for the deviceready
// event before executing any code that might interact with Cordova APIs or plugins.
if ($(document.body).hasClass('oj-hybrid')) {
document.addEventListener("deviceready", init);
} else {
init();
}
});
}
);
