Created
January 5, 2016 10:11
-
-
Save mrzmyr/0003b3e03340745967ef to your computer and use it in GitHub Desktop.
ConnectSDK Angular 1.x Service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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