Skip to content

Commit

Permalink
Merge pull request #1 from goodvidio/browser-decorator
Browse files Browse the repository at this point in the history
Add support for browser decorator
  • Loading branch information
varemenos authored Nov 23, 2016
2 parents d1271f8 + edd23d7 commit d10e6ac
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 51 deletions.
77 changes: 71 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,71 @@
try {
module.exports = require('./lib');
} catch(error) {
require('coffee-script');
module.exports = require('./src');
}
var iectrl = require('iectrl');
var vmNames = iectrl.IEVM.names;
var finalExports = {};

vmNames.forEach(function ( vmName ) {
finalExports['launcher:' + vmName] = ['type', IEVMLauncher];
});

function IEVMLauncher ( id, vmName, logger, baseBrowserDecorator ) {

var log = logger.create('launcher.ievms');

baseBrowserDecorator(this);

this.id = id;
this.name = vmName;
this.vm = iectrl.IEVM.find(this.name)[0];
this.wasRunning = false;
this.captured = false;

this.start = function ( url ) {
var vmUrl;
var self = this;
vmUrl = (String(url) + '?id=' + this.id).replace('localhost', iectrl.IEVM.hostIp);
return this.vm.running().then(function ( running ) {
self.wasRunning = running;
if (running) {
log.info('Opening VM ' + self.name);
return self.vm.open(vmUrl);
}
return self.vm.start(true).then(function () {
log.info('Opening VM ' + self.name);
return self.vm.open(vmUrl);
});
});
};

this.kill = function ( done ) {
var self = this;
log.info('Closing VM');
return this.vm.close().then(function () {
if ( self.wasRunning ) {
return done();
}
log.info('Stopping VM ' + self.name);
return self.vm.stop().then(function () {
return done();
});
}).catch(done);
};

this.forceKill = function () {
var self = this;
log.info('Force stopping VM ' + self.name);
return self.kill(function () {
self.emit('done');
});
};

this.markCaptured = function () {
this.captured = true;
};

this.isCaptured = function () {
return this.captured;
};
}

IEVMLauncher.$inject = ['id', 'name', 'logger', 'baseBrowserDecorator'];

module.exports = finalExports;
45 changes: 0 additions & 45 deletions src/index.coffee

This file was deleted.

0 comments on commit d10e6ac

Please sign in to comment.