Skip to content

Instantly share code, notes, and snippets.

@mrzmyr
Created January 5, 2016 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrzmyr/0003b3e03340745967ef to your computer and use it in GitHub Desktop.
Save mrzmyr/0003b3e03340745967ef to your computer and use it in GitHub Desktop.
ConnectSDK Angular 1.x Service
angular.module('app')
.service('beamerService', function ($q) {
if(!window.cordova) {
window.ConnectSDK = {
discoveryManager: {
startDiscovery: angular.noop,
pickDevice: angular.noop
}
}
}
this.startDiscovery = function () {
ConnectSDK.discoveryManager.startDiscovery();
}
this.openPicker = function () {
var defer = $q.defer();
ConnectSDK.discoveryManager
.pickDevice()
.success(function (device) {
this.currentDevice = device;
defer.resolve(device);
}.bind(this))
.error(function (err) {
console.error(err);
defer.reject(err);
})
return defer.promise;
}
this.showMedia = function (url, mimeType, options) {
var defer = $q.defer();
var onDeviceConnected = function () {
this.currentDevice
.getMediaPlayer()
.displayImage(url, mimeType, options || {})
.success(function (launchSession, mediaControl) {
this.launchSession = launchSession;
defer.resolve({
launchSession: launchSession,
mediaControl: mediaControl
});
}.bind(this))
.error(function (err) {
console.error(err.message);
defer.reject(err);
})
}
if(!this.currentDevice) {
console.error('No current device selected');
defer.reject('No current device selected')
} else {
if (this.currentDevice.isReady()) {
onDeviceConnected.call(this);
} else {
this.currentDevice.on("ready", onDeviceConnected.bind(this));
this.currentDevice.connect();
}
}
return defer.promise;
}
this.reset = function () {
this.currentDevice = null;
this.launchSession && this.launchSession.close();
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment