angular-point-sync
Advanced tools
Comparing version 5.0.3 to 5.0.4
{ | ||
"name": "angular-point-sync", | ||
"version": "5.0.3", | ||
"version": "5.0.4", | ||
"description": "Supports 3-way data binding if you decide to incorporate firebase (any change by any user to a list item is mirrored across users). The data isn't saved to firebase but the change event is so all subscribers are notified to request an update from SharePoint.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -0,5 +1,7 @@ | ||
import { AngularPointModule } from 'angular-point'; | ||
import {SyncService} from './sync.service'; | ||
import {PresenceService} from './presence.service'; | ||
import {AngularPointModule} from 'angular-point'; | ||
import {PresenceService, IFirebaseUsersObject, IUserNotification} from './presence.service'; | ||
import {ISyncServiceChangeEvent, ISyncPoint} from './sync-point.factory'; | ||
import {ILockReference} from './lock.factory'; | ||
/** | ||
@@ -47,9 +49,4 @@ * @ngdoc service | ||
// Instantiate immediately | ||
.run(['apPresenceService', (apPresenceService) => { | ||
}]); | ||
.run(['apPresenceService', (apPresenceService) => { }]); | ||
export * from './lock.factory'; | ||
export * from './presence.service'; | ||
export * from './sync-point.factory'; | ||
export * from './sync.service'; | ||
export { ISyncServiceChangeEvent, SyncService, ILockReference, ISyncPoint, PresenceService, IFirebaseUsersObject, IUserNotification } |
import * as moment from 'moment'; | ||
import * as _ from 'lodash'; | ||
import {serviceIsInitialized, $firebaseArray, $q} from './sync.service'; | ||
export interface ILockReference { | ||
@@ -7,0 +7,0 @@ lockQueue: AngularFireArray; |
import * as toastr from 'toastr'; | ||
import * as _ from 'lodash'; | ||
import {SyncService, serviceIsInitialized} from './sync.service'; | ||
import {ISyncServiceInitializationParams} from './sync-point.factory'; | ||
var service: PresenceService; | ||
import { SyncService, serviceIsInitialized } from './sync.service'; | ||
import { ISyncServiceInitializationParams } from './sync-point.factory'; | ||
let service: PresenceService; | ||
export interface IFirebaseSessionObject extends AngularFireObject { | ||
@@ -13,3 +15,3 @@ browser: string; | ||
path: string; | ||
reload: boolean; //Hard refresh browser | ||
reload: boolean; // Hard refresh browser | ||
} | ||
@@ -27,6 +29,6 @@ | ||
export interface IFirebaseUsersObject { | ||
[key: number]: { //User ID | ||
connections: { [key: string]: IFirebaseSessionObject } //Object for each active connection | ||
lastOnline: number; //Timestamp | ||
} | ||
[key: number]: { // User ID | ||
connections: { [key: string]: IFirebaseSessionObject } // Object for each active connection | ||
lastOnline: number; // Timestamp | ||
}; | ||
} | ||
@@ -55,26 +57,23 @@ | ||
constructor(private $q: ng.IQService, $rootScope: angular.IRootScopeService, private $firebaseArray: AngularFireArrayService, private $firebaseObject: AngularFireObjectService, | ||
$location: angular.ILocationService, apSyncService: SyncService) { | ||
constructor(private $q: ng.IQService, $rootScope: angular.IRootScopeService, private $firebaseArray: AngularFireArrayService, | ||
private $firebaseObject: AngularFireObjectService, $location: angular.ILocationService, apSyncService: SyncService) { | ||
service = this; | ||
var deferred = $q.defer(); | ||
const deferred = $q.defer(); | ||
service.initializeSession = deferred.promise; | ||
//Wait for SyncService to be initialized with current users userId and firebaseUrl | ||
// Wait for SyncService to be initialized with current users userId and firebaseUrl | ||
serviceIsInitialized.then((initializationParamsObject: ISyncServiceInitializationParams) => { | ||
var userId = initializationParamsObject.userId; | ||
var firebaseUrl = initializationParamsObject.firebaseUrl; | ||
var firebaseRoot = firebaseUrl.replace('offline/', ''); | ||
const userId = initializationParamsObject.userId; | ||
const firebaseUrl = initializationParamsObject.firebaseUrl; | ||
const firebaseRoot = firebaseUrl.replace('offline/', ''); | ||
service.userConnectionUrl = firebaseUrl + 'users/' + userId + '/'; | ||
// var usersRef = new Firebase(firebaseUrl + 'users'); | ||
// service.users = $firebaseObject(usersRef).$loaded; | ||
// since I can connect from multiple devices or browser tabs, we store each connection instance separately | ||
// any time that connectionsRef's value is null (i.e. has no children) I am offline | ||
var thisConnectionRef = new Firebase(service.userConnectionUrl + 'connections'); | ||
const thisConnectionRef = new Firebase(service.userConnectionUrl + 'connections'); | ||
// stores the timestamp of my last disconnect (the last time I was seen online) | ||
var lastOnlineRef = new Firebase(service.userConnectionUrl + 'lastOnline'); | ||
var connectedRef = new Firebase(firebaseRoot + '.info/connected'); | ||
const lastOnlineRef = new Firebase(service.userConnectionUrl + 'lastOnline'); | ||
const connectedRef = new Firebase(firebaseRoot + '.info/connected'); | ||
@@ -96,3 +95,3 @@ | ||
//Update the current path whenever state changes | ||
// Update the current path whenever state changes | ||
$rootScope.$on('$stateChangeSuccess', function (event, current, previous, rejection) { | ||
@@ -111,7 +110,7 @@ service.sessionConnection.update({ | ||
var activeSessionObject = service.$firebaseObject(service.sessionConnection); | ||
const activeSessionObject = service.$firebaseObject(service.sessionConnection); | ||
deferred.resolve(activeSessionObject); | ||
// watch for events | ||
service.watchForReloadEvent(<any> activeSessionObject); | ||
service.watchForReloadEvent(<any>activeSessionObject); | ||
service.watchForNotifications(userId, activeSessionObject.$id); | ||
@@ -127,3 +126,3 @@ } | ||
.then(sessionConnectionUrl => { | ||
var sessionRef = new Firebase(sessionConnectionUrl); | ||
const sessionRef = new Firebase(sessionConnectionUrl); | ||
sessionRef.remove(); | ||
@@ -143,3 +142,3 @@ }); | ||
return service.getSessionConnectioUrl(userId, sessionKey).then((sessionConnectionUrl) => { | ||
var notificationsRef = new Firebase(sessionConnectionUrl + '/notifications'); | ||
const notificationsRef = new Firebase(sessionConnectionUrl + '/notifications'); | ||
return service.$firebaseArray(notificationsRef).$loaded(); | ||
@@ -164,3 +163,3 @@ }) | ||
if (!service.users) { | ||
var usersRef = new Firebase(initializationParamsObject.firebaseUrl + 'users'); | ||
const usersRef = new Firebase(initializationParamsObject.firebaseUrl + 'users'); | ||
service.users = service.$firebaseObject(usersRef); | ||
@@ -174,4 +173,4 @@ } | ||
service.getSessionConnectioUrl(userId, sessionKey).then((sessionConnectionUrl) => { | ||
var sessionRef = new Firebase(sessionConnectionUrl); | ||
var sessionObject: any = service.$firebaseObject(sessionRef); | ||
const sessionRef = new Firebase(sessionConnectionUrl); | ||
const sessionObject: any = service.$firebaseObject(sessionRef); | ||
sessionObject.$loaded() | ||
@@ -181,3 +180,3 @@ .then(() => { | ||
sessionObject.$save(); | ||
}) | ||
}); | ||
}); | ||
@@ -187,3 +186,3 @@ } | ||
sendUserNotification(userId: number, sessionKey: string, notification: IUserNotification): ng.IPromise<IUserNotification> { | ||
var deferred = this.$q.defer(); | ||
const deferred = this.$q.defer(); | ||
this.getSessionNotificationsArray(userId, sessionKey) | ||
@@ -200,3 +199,3 @@ .then((sessionNotifications) => { | ||
.then((notificationArray: AngularFireArray) => notificationArray.$watch((eventObject: any) => { | ||
//Trigger when a new notification is added to the session notifications array | ||
// Trigger when a new notification is added to the session notifications array | ||
if (eventObject.event === 'child_added') { | ||
@@ -223,4 +222,4 @@ _.each(notificationArray, (notification: IUserNotification, index) => { | ||
function identifyBrowser(): string { | ||
var ua = navigator.userAgent, tem, | ||
export function identifyBrowser(): string { | ||
let ua = navigator.userAgent, tem, | ||
M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; | ||
@@ -227,0 +226,0 @@ if (/trident/i.test(M[1])) { |
import * as _ from 'lodash'; | ||
import {Model} from 'angular-point'; | ||
import { Model } from 'angular-point'; | ||
import {serviceIsInitialized, $firebaseArray, $rootScope} from './sync.service'; | ||
@@ -59,6 +60,4 @@ | ||
}); | ||
} | ||
@@ -118,3 +117,3 @@ | ||
*/ | ||
subscribeToChanges(callback: Function, unsubscribeOnStateChange: boolean = true): Function { | ||
subscribeToChanges(callback: Function, unsubscribeOnStateChange = true): Function { | ||
const syncPoint = this; | ||
@@ -129,4 +128,2 @@ if (syncPoint.subscriptions.indexOf(callback) === -1) { | ||
if (unsubscribeOnStateChange) { | ||
//var $rootScope = $injector.get('$rootScope'); | ||
/** Unsubscribe from notifications when we leave this state */ | ||
@@ -133,0 +130,0 @@ $rootScope.$on('$stateChangeStart', () => { |
@@ -1,4 +0,6 @@ | ||
import {Model} from 'angular-point'; | ||
import { Model } from 'angular-point'; | ||
import {ISyncServiceInitializationParams, ISyncPoint, SyncPoint} from './sync-point.factory'; | ||
import {ILockReference, Lock} from './lock.factory'; | ||
import { ILockReference, Lock } from './lock.factory'; | ||
export let $q, | ||
@@ -11,12 +13,12 @@ $firebaseArray, | ||
export interface ISyncService { | ||
export interface SyncService { | ||
Lock: () => ng.IPromise<ILockReference>; | ||
createSyncPoint(model: Model): ISyncPoint; | ||
initialize(userId: number, firebaseUrl: string): void; | ||
Lock: () => ng.IPromise<ILockReference>; | ||
} | ||
export class SyncService implements ISyncService { | ||
export class SyncService implements SyncService { | ||
/** Minification safe - we're using leading and trailing underscores but gulp plugin doesn't treat them correctly */ | ||
static $inject = ['$firebaseArray', '$q', 'apListItemFactory', '$rootScope']; | ||
Lock = Lock; | ||
constructor(_$firebaseArray_, _$q_, _apListItemFactory_, _$rootScope_) { | ||
@@ -52,3 +54,2 @@ /** Expose to service scope */ | ||
Lock = Lock; | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
107042
633