@chat21/chat21-web-widget 5.0.59-rc.3 → 5.0.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/package.json +1 -1
- package/src/chat21-core/providers/abstract/notifications.service.ts +1 -1
- package/src/chat21-core/providers/chat-manager.ts +1 -1
- package/src/chat21-core/providers/firebase/firebase-notifications.ts +162 -69
- package/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts +1 -0
- package/src/chat21-core/providers/mqtt/mqtt-notifications.ts +40 -19
- package/src/chat21-core/utils/constants.ts +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# chat21-web-widget ver 5.0
|
|
2
2
|
|
|
3
|
+
### 5.0.59 in PROD
|
|
4
|
+
|
|
5
|
+
### 5.0.59-rc.4
|
|
6
|
+
- bug-fixed: texarea remains disabled if messages array has the last (non ordered) timestamp message set with 'disabledTextArea' set to true
|
|
7
|
+
|
|
3
8
|
### 5.0.59-rc.3
|
|
4
9
|
- bug-fixed: if mobileMarginX or MobileMarginY is set, widget do not fit on fullscreen once is opened
|
|
5
10
|
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@ export abstract class NotificationsService {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
abstract initialize(tenant: string, vapidKey: string): void;
|
|
20
|
+
abstract initialize(tenant: string, vapidKey: string, platform: string): void;
|
|
21
21
|
abstract getNotificationPermissionAndSaveToken(currentUserUid: string): void;
|
|
22
22
|
abstract removeNotificationsInstance(callback: (string) => void): void;
|
|
23
23
|
|
|
@@ -184,7 +184,7 @@ export class ChatManager {
|
|
|
184
184
|
getConversationHandlerByConversationId(conversationId): any {
|
|
185
185
|
let handler = null;
|
|
186
186
|
this.handlers.forEach(conv => {
|
|
187
|
-
|
|
187
|
+
this.logger.log('[CHAT MANAGER]forEach ***', conversationId, this.handlers, conv);
|
|
188
188
|
if (conv.conversationWith === conversationId) {
|
|
189
189
|
handler = conv;
|
|
190
190
|
return;
|
|
@@ -1,79 +1,82 @@
|
|
|
1
|
-
import { LoggerInstance } from './../logger/loggerInstance';
|
|
2
1
|
import { Injectable } from '@angular/core';
|
|
3
2
|
// services
|
|
4
3
|
import { NotificationsService } from '../abstract/notifications.service';
|
|
5
|
-
|
|
4
|
+
import { LoggerInstance } from '../logger/loggerInstance';
|
|
5
|
+
import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
|
|
6
6
|
// firebase
|
|
7
|
-
// import firebase from 'firebase/app';
|
|
7
|
+
// import * as firebase from 'firebase/app';
|
|
8
|
+
import firebase from "firebase/app";
|
|
9
|
+
import 'firebase/messaging';
|
|
10
|
+
import 'firebase/auth';
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
@Injectable({ providedIn: 'root' })
|
|
10
13
|
|
|
11
|
-
// @Injectable({ providedIn: 'root' })
|
|
12
|
-
@Injectable()
|
|
13
14
|
export class FirebaseNotifications extends NotificationsService {
|
|
14
|
-
|
|
15
|
-
// public BUILD_VERSION: string;
|
|
15
|
+
|
|
16
16
|
private FCMcurrentToken: string;
|
|
17
17
|
private userId: string;
|
|
18
18
|
private tenant: string;
|
|
19
19
|
private vapidkey: string;
|
|
20
|
-
private
|
|
21
|
-
|
|
20
|
+
private platform: string;
|
|
22
21
|
private logger: LoggerService = LoggerInstance.getInstance();
|
|
23
22
|
constructor() {
|
|
24
23
|
super();
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
initialize(tenant: string, vapId: string, platform: string): void {
|
|
28
27
|
this.tenant = tenant
|
|
29
28
|
this.vapidkey = vapId
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
const { default: firebase} = await import("firebase/app");
|
|
33
|
-
this.firebase = firebase
|
|
29
|
+
platform === 'desktop'? this.platform = 'ionic' : this.platform = platform
|
|
30
|
+
this.logger.log('[FIREBASE-NOTIFICATIONS] initialize - tenant ', this.tenant, this.platform)
|
|
34
31
|
|
|
35
32
|
if (!('serviceWorker' in navigator)) {
|
|
36
33
|
// , disable or hide UI.
|
|
37
34
|
this.logger.error("[FIREBASE-NOTIFICATIONS] initialize - Service Worker isn't supported on this browser", navigator)
|
|
38
35
|
return;
|
|
39
36
|
}
|
|
40
|
-
if (('serviceWorker' in navigator)) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (serviceWorkerRegistrations.length > 0) {
|
|
45
|
-
serviceWorkerRegistrations.forEach(registration => {
|
|
46
|
-
this.logger.log("[FIREBASE-NOTIFICATIONS] initialize - Service Worker is supported on this browser registration ", registration)
|
|
47
|
-
// this.logger.log("[FIREBASE-NOTIFICATIONS] initialize - Service Worker is supported on this browser registrations scriptURL", registrations.active.scriptURL)
|
|
48
|
-
// this.logger.log("[FIREBASE-NOTIFICATIONS] initialize - Service Worker is supported on this browser registrations state", registrations.active.state)
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
} else {
|
|
52
|
-
this.logger.log("[FIREBASE-NOTIFICATIONS] initialize - Service Worker is supported on this browser - !not registered",)
|
|
37
|
+
// if (('serviceWorker' in navigator)) {
|
|
38
|
+
// navigator.serviceWorker.register('firebase-messaging-sw.js')
|
|
39
|
+
// .then(function (registration) {
|
|
40
|
+
// console.log('[FIREBASE-NOTIFICATIONS] initialize serviceWorker Registration successful, scope is:', registration.scope);
|
|
53
41
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
|
|
43
|
+
// // this.logger.log("[FIREBASE-NOTIFICATIONS] initialize - Service Worker is supported on this browser ", navigator)
|
|
44
|
+
// // navigator.serviceWorker.getRegistrations().then((serviceWorkerRegistrations) => {
|
|
45
|
+
// // this.logger.log("[FIREBASE-NOTIFICATIONS] initialize - Service Worker is supported on this browser serviceWorkerRegistrations", serviceWorkerRegistrations)
|
|
46
|
+
// // if (serviceWorkerRegistrations.length > 0) {
|
|
47
|
+
// // serviceWorkerRegistrations.forEach(registration => {
|
|
48
|
+
// // this.logger.log("[FIREBASE-NOTIFICATIONS] initialize - Service Worker is supported on this browser registration ", registration)
|
|
49
|
+
// // // this.logger.log("[FIREBASE-NOTIFICATIONS] initialize - Service Worker is supported on this browser registrations scriptURL", registrations.active.scriptURL)
|
|
50
|
+
// // // this.logger.log("[FIREBASE-NOTIFICATIONS] initialize - Service Worker is supported on this browser registrations state", registrations.active.state)
|
|
51
|
+
|
|
52
|
+
// // });
|
|
53
|
+
// // } else {
|
|
54
|
+
// // this.logger.log("[FIREBASE-NOTIFICATIONS] initialize - Service Worker is supported on this browser - !not registered",)
|
|
55
|
+
// // // navigator.serviceWorker.register('http://localhost:8101/firebase-messaging-sw.js')
|
|
56
|
+
// // // .then(function (registration) {
|
|
57
|
+
// // // console.log('Service worker successfully registered.');
|
|
58
|
+
// // // return registration;
|
|
59
|
+
// // // }).catch(function (err) {
|
|
60
|
+
// // // console.error('Unable to register service worker.', err);
|
|
61
|
+
// // // });
|
|
62
|
+
// // }
|
|
63
|
+
// // });
|
|
64
|
+
// }).catch(function (err) {
|
|
65
|
+
// console.log('Service worker registration failed, error:', err);
|
|
66
|
+
// });
|
|
67
|
+
// }
|
|
57
68
|
}
|
|
58
69
|
|
|
70
|
+
|
|
71
|
+
|
|
59
72
|
getNotificationPermissionAndSaveToken(currentUserUid) {
|
|
60
73
|
// this.tenant = this.getTenant();
|
|
61
|
-
this.logger.log('[FIREBASE-NOTIFICATIONS] calling requestPermission - tenant ', this.tenant)
|
|
62
|
-
this.logger.log('[FIREBASE-NOTIFICATIONS] calling requestPermission - currentUserUid ', currentUserUid)
|
|
74
|
+
this.logger.log('initialize FROM [APP-COMP] - [FIREBASE-NOTIFICATIONS] calling requestPermission - tenant ', this.tenant, ' currentUserUid ', currentUserUid)
|
|
75
|
+
// this.logger.log('[FIREBASE-NOTIFICATIONS] calling requestPermission - currentUserUid ', currentUserUid)
|
|
63
76
|
this.userId = currentUserUid;
|
|
64
|
-
// Service Worker explicit registration to explicitly define sw location at a path
|
|
65
|
-
// const swRegistration = async () => {
|
|
66
|
-
// try {
|
|
67
|
-
// await navigator.serviceWorker.register('http://localhost:8101/firebase-messaging-sw.js');
|
|
68
|
-
// } catch (error) {
|
|
69
|
-
// console.error(error);
|
|
70
|
-
// }
|
|
71
|
-
// }
|
|
72
|
-
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const messaging = this.firebase.messaging();
|
|
78
|
+
if (firebase.messaging.isSupported()) {
|
|
79
|
+
const messaging = firebase.messaging();
|
|
77
80
|
// messaging.requestPermission()
|
|
78
81
|
Notification.requestPermission().then((permission) => {
|
|
79
82
|
if (permission === 'granted') {
|
|
@@ -91,46 +94,136 @@ export class FirebaseNotifications extends NotificationsService {
|
|
|
91
94
|
});
|
|
92
95
|
} else {
|
|
93
96
|
this.logger.log('[FIREBASE-NOTIFICATIONS] >>>> FIREBASE MESSAGING IS NOT SUPPORTED')
|
|
97
|
+
|
|
98
|
+
// if(this.platform == 'android' || this.platform === 'ios'){
|
|
99
|
+
// this.logger.log('[MQTTNotificationService] >>>> FIREBASE MESSAGING: use FCM plugin')
|
|
100
|
+
// this.fcm.onTokenRefresh().subscribe(FCMtoken => {
|
|
101
|
+
// // Register your new token in your back-end if you want
|
|
102
|
+
// // backend.registerToken(token);
|
|
103
|
+
// this.FCMcurrentToken = FCMtoken;
|
|
104
|
+
// console.log("[MQTTNotificationService] FCM: onTokenRefresh --->", FCMtoken);
|
|
105
|
+
// this.updateToken(FCMtoken, currentUserUid)
|
|
106
|
+
// });
|
|
107
|
+
// this.fcm.requestPushPermission().then((permission) => {
|
|
108
|
+
// console.log("[MQTTNotificationService] FCM: requestPushPermission --->", permission);
|
|
109
|
+
// if(permission === true){
|
|
110
|
+
// this.fcm.getToken().then(FCMtoken => {
|
|
111
|
+
// console.log("[MQTTNotificationService] FCM: getToken --->", FCMtoken);
|
|
112
|
+
// this.FCMcurrentToken = FCMtoken;
|
|
113
|
+
// this.updateToken(FCMtoken, currentUserUid)
|
|
114
|
+
// });
|
|
115
|
+
// }
|
|
116
|
+
// });
|
|
117
|
+
|
|
118
|
+
// }
|
|
94
119
|
}
|
|
95
120
|
}
|
|
96
121
|
|
|
122
|
+
|
|
123
|
+
// getNotificationPermissionAndSaveToken(currentUserUid) {
|
|
124
|
+
// // this.tenant = this.getTenant();
|
|
125
|
+
// this.logger.log('[FIREBASE-NOTIFICATIONS] calling requestPermission - tenant ', this.tenant)
|
|
126
|
+
// this.logger.log('[FIREBASE-NOTIFICATIONS] calling requestPermission - currentUserUid ', currentUserUid)
|
|
127
|
+
// this.userId = currentUserUid;
|
|
128
|
+
// const messaging = firebase.messaging();
|
|
129
|
+
// if (firebase.messaging.isSupported()) {
|
|
130
|
+
// // messaging.requestPermission()
|
|
131
|
+
// Notification.requestPermission().then((permission) => {
|
|
132
|
+
// if (permission === 'granted') {
|
|
133
|
+
// this.logger.log('[FIREBASE-NOTIFICATIONS] >>>> requestPermission Notification permission granted.');
|
|
134
|
+
// messaging.getToken({ vapidKey: 'BOsgS2ADwspKdWAmiFDZXEYqY1HSYADVfJT3j67wsySh3NxaViJqoabPJH8WM02wb5r8cQIm5TgM0UK047Z1D1c'}).then((currentToken) => {
|
|
135
|
+
// if (currentToken) {
|
|
136
|
+
// this.sendTokenToServer(currentToken);
|
|
137
|
+
// // updateUIForPushEnabled(currentToken);
|
|
138
|
+
|
|
139
|
+
// } else {
|
|
140
|
+
// // Show permission request UI
|
|
141
|
+
// console.log('No registration token available. Request permission to generate one.');
|
|
142
|
+
// // ...
|
|
143
|
+
// }
|
|
144
|
+
// }).catch((err) => {
|
|
145
|
+
// console.log('An error occurred while retrieving token. ', err);
|
|
146
|
+
// // ...
|
|
147
|
+
// });
|
|
148
|
+
|
|
149
|
+
// resetUI()
|
|
150
|
+
|
|
151
|
+
// } else {
|
|
152
|
+
// this.logger.error('Unable to get permission to notify.');
|
|
153
|
+
// }
|
|
154
|
+
// })
|
|
155
|
+
|
|
156
|
+
// }
|
|
157
|
+
// }
|
|
158
|
+
|
|
159
|
+
// sendTokenToServer(currentToken) {
|
|
160
|
+
// if (!this.isTokenSentToServer()) {
|
|
161
|
+
// console.log('Sending token to server...');
|
|
162
|
+
// // TODO(developer): Send the current token to your server.
|
|
163
|
+
// this.setTokenSentToServer(true);
|
|
164
|
+
// } else {
|
|
165
|
+
// console.log('Token already sent to server so won\'t send it again ' +
|
|
166
|
+
// 'unless it changes');
|
|
167
|
+
// }
|
|
168
|
+
// }
|
|
169
|
+
|
|
170
|
+
// isTokenSentToServer() {
|
|
171
|
+
// return window.localStorage.getItem('sentToServer') === '1';
|
|
172
|
+
// }
|
|
173
|
+
|
|
174
|
+
// setTokenSentToServer(sent) {
|
|
175
|
+
// window.localStorage.setItem('sentToServer', sent ? '1' : '0');
|
|
176
|
+
// }
|
|
177
|
+
|
|
97
178
|
removeNotificationsInstance(callback: (string) => void) {
|
|
98
179
|
var self = this;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const connectionsRefinstancesId = urlNodeFirebase + '/users/' + this.userId + '/instances/'
|
|
113
|
-
this.logger.log('[FIREBASE-NOTIFICATIONS] >>>> connectionsRefinstancesId ', connectionsRefinstancesId);
|
|
180
|
+
// firebase.auth().onAuthStateChanged(function (user) {
|
|
181
|
+
// if (user) {
|
|
182
|
+
// self.logger.debug('[FIREBASE-NOTIFICATIONS] - FB User is signed in. ', user)
|
|
183
|
+
// self.logger.log('[FIREBASE-NOTIFICATIONS] >>>> removeNotificationsInstance > this.userId', self.userId);
|
|
184
|
+
// self.logger.log('[FIREBASE-NOTIFICATIONS] >>>> removeNotificationsInstance > FCMcurrentToken', self.FCMcurrentToken);
|
|
185
|
+
// // this.logger.log('[FIREBASE-NOTIFICATIONS] >>>> removeNotificationsInstance > this.tenant', this.tenant);
|
|
186
|
+
// } else {
|
|
187
|
+
// self.logger.debug('[FIREBASE-NOTIFICATIONS] - No FB user is signed in. ', user)
|
|
188
|
+
// }
|
|
189
|
+
// });
|
|
190
|
+
const urlNodeFirebase = '/apps/' + self.tenant
|
|
191
|
+
const connectionsRefinstancesId = urlNodeFirebase + '/users/' + self.userId + '/instances/'
|
|
192
|
+
self.logger.log('[FIREBASE-NOTIFICATIONS] >>>> connectionsRefinstancesId ', connectionsRefinstancesId);
|
|
114
193
|
let connectionsRefURL = '';
|
|
115
194
|
if (connectionsRefinstancesId) {
|
|
116
|
-
connectionsRefURL = connectionsRefinstancesId +
|
|
117
|
-
const connectionsRef =
|
|
118
|
-
|
|
119
|
-
|
|
195
|
+
connectionsRefURL = connectionsRefinstancesId + self.FCMcurrentToken;
|
|
196
|
+
const connectionsRef = firebase.database().ref().child(connectionsRefURL);
|
|
197
|
+
self.logger.log('[FIREBASE-NOTIFICATIONS] >>>> connectionsRef ', connectionsRef);
|
|
198
|
+
self.logger.log('[FIREBASE-NOTIFICATIONS] >>>> connectionsRef url ', connectionsRefURL);
|
|
120
199
|
connectionsRef.off()
|
|
121
200
|
connectionsRef.remove()
|
|
122
201
|
.then(() => {
|
|
123
|
-
|
|
202
|
+
self.logger.log("[FIREBASE-NOTIFICATIONS] >>>> removeNotificationsInstance > Remove succeeded.")
|
|
124
203
|
callback('success')
|
|
125
204
|
}).catch((error) => {
|
|
126
|
-
|
|
205
|
+
self.logger.error("[FIREBASE-NOTIFICATIONS] >>>> removeNotificationsInstance Remove failed: " + error.message)
|
|
127
206
|
callback('error')
|
|
128
207
|
}).finally(() => {
|
|
129
|
-
|
|
208
|
+
self.logger.log('[FIREBASE-NOTIFICATIONS] COMPLETED');
|
|
130
209
|
})
|
|
131
210
|
}
|
|
211
|
+
|
|
132
212
|
}
|
|
133
213
|
|
|
214
|
+
// removeNotificationsInstance() {
|
|
215
|
+
// let promise = new Promise((resolve, reject) => {
|
|
216
|
+
// this.appStoreService.getInstallation(this.projectId).then((res) => {
|
|
217
|
+
// console.log("Get Installation Response: ", res);
|
|
218
|
+
// resolve(res);
|
|
219
|
+
// }).catch((err) => {
|
|
220
|
+
// console.error("Error getting installation: ", err);
|
|
221
|
+
// reject(err);
|
|
222
|
+
// })
|
|
223
|
+
// })
|
|
224
|
+
// return promise;
|
|
225
|
+
// }
|
|
226
|
+
|
|
134
227
|
|
|
135
228
|
// ********** PRIVATE METHOD - START ****************//
|
|
136
229
|
private updateToken(FCMcurrentToken, currentUserUid) {
|
|
@@ -149,14 +242,14 @@ export class FirebaseNotifications extends NotificationsService {
|
|
|
149
242
|
const device_model = {
|
|
150
243
|
device_model: navigator.userAgent,
|
|
151
244
|
language: navigator.language,
|
|
152
|
-
platform:
|
|
245
|
+
platform: this.platform,
|
|
153
246
|
platform_version: this.BUILD_VERSION
|
|
154
247
|
}
|
|
155
248
|
|
|
156
249
|
updates[connectionsRefinstancesId + connection] = device_model;
|
|
157
250
|
|
|
158
251
|
this.logger.log('[FIREBASE-NOTIFICATIONS] >>>> getPermission > updateToken in DB', updates);
|
|
159
|
-
|
|
252
|
+
firebase.database().ref().update(updates)
|
|
160
253
|
}
|
|
161
254
|
// ********** PRIVATE METHOD - END ****************//
|
|
162
255
|
|
|
@@ -102,6 +102,7 @@ export class MQTTConversationHandler extends ConversationHandlerService {
|
|
|
102
102
|
this.chat21Service.chatClient.lastMessages(this.conversationWith, (err, messages) => {
|
|
103
103
|
if (!err) {
|
|
104
104
|
this.logger.log('[MQTTConversationHandlerSERVICE] message lastMessages:', messages);
|
|
105
|
+
messages.sort(compareValues('timestamp', 'asc'));
|
|
105
106
|
messages.forEach(message => {
|
|
106
107
|
// this.addedMessage(msg);
|
|
107
108
|
const msg: MessageModel = message;
|
|
@@ -1,49 +1,48 @@
|
|
|
1
|
-
|
|
2
1
|
import { Injectable } from '@angular/core';
|
|
3
2
|
// services
|
|
4
3
|
import { NotificationsService } from '../abstract/notifications.service';
|
|
5
4
|
import { LoggerInstance } from '../logger/loggerInstance';
|
|
6
5
|
import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
|
|
7
|
-
|
|
8
6
|
// firebase
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import firebase from "firebase/app";
|
|
8
|
+
import 'firebase/messaging';
|
|
9
|
+
import 'firebase/auth';
|
|
11
10
|
// chat21
|
|
12
11
|
import { Chat21Service } from './chat-service';
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
@Injectable({
|
|
14
|
+
providedIn: 'root'
|
|
15
|
+
})
|
|
16
16
|
export class MQTTNotifications extends NotificationsService {
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
// public BUILD_VERSION: string;
|
|
19
19
|
private FCMcurrentToken: string;
|
|
20
20
|
private userId: string;
|
|
21
21
|
private tenant: string;
|
|
22
22
|
private vapidkey: string;
|
|
23
|
-
private
|
|
24
|
-
|
|
23
|
+
private platform: string;
|
|
25
24
|
private logger: LoggerService = LoggerInstance.getInstance();
|
|
26
25
|
|
|
27
26
|
constructor(
|
|
28
|
-
public chat21Service: Chat21Service
|
|
27
|
+
public chat21Service: Chat21Service,
|
|
29
28
|
) {
|
|
30
29
|
super();
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
initialize(tenant: string, vapId: string, platform: string): void {
|
|
34
33
|
this.tenant = tenant;
|
|
35
34
|
this.vapidkey = vapId;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.firebase = firebase
|
|
39
|
-
|
|
35
|
+
platform === 'desktop'? this.platform = 'ionic' : this.platform = platform
|
|
36
|
+
this.logger.log('[MQTTNotificationService] initialize - tenant ', this.tenant, this.platform)
|
|
40
37
|
return;
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
getNotificationPermissionAndSaveToken(currentUserUid) {
|
|
41
|
+
console.log("[MQTTNotificationService] getNotificationPermissionAndSaveToken()",currentUserUid);
|
|
44
42
|
this.userId = currentUserUid;
|
|
45
|
-
if (
|
|
46
|
-
|
|
43
|
+
if (firebase.messaging.isSupported()) {
|
|
44
|
+
console.log("[MQTTNotificationService] firebase.messaging.isSupported -> YES");
|
|
45
|
+
const messaging = firebase.messaging();
|
|
47
46
|
// messaging.requestPermission()
|
|
48
47
|
Notification.requestPermission().then((permission) => {
|
|
49
48
|
if (permission === 'granted') {
|
|
@@ -61,6 +60,28 @@ export class MQTTNotifications extends NotificationsService {
|
|
|
61
60
|
});
|
|
62
61
|
} else {
|
|
63
62
|
this.logger.log('[MQTTNotificationService] >>>> FIREBASE MESSAGING IS NOT SUPPORTED')
|
|
63
|
+
|
|
64
|
+
// if(this.platform == 'android' || this.platform === 'ios'){
|
|
65
|
+
// this.logger.log('[MQTTNotificationService] >>>> FIREBASE MESSAGING: use FCM plugin')
|
|
66
|
+
// this.fcm.onTokenRefresh().subscribe(FCMtoken => {
|
|
67
|
+
// // Register your new token in your back-end if you want
|
|
68
|
+
// // backend.registerToken(token);
|
|
69
|
+
// this.FCMcurrentToken = FCMtoken;
|
|
70
|
+
// console.log("[MQTTNotificationService] FCM: onTokenRefresh --->", FCMtoken);
|
|
71
|
+
// this.saveToken(FCMtoken, currentUserUid)
|
|
72
|
+
// });
|
|
73
|
+
// this.fcm.requestPushPermission().then((permission) => {
|
|
74
|
+
// console.log("[MQTTNotificationService] FCM: requestPushPermission --->", permission);
|
|
75
|
+
// if(permission === true){
|
|
76
|
+
// this.fcm.getToken().then(FCMtoken => {
|
|
77
|
+
// console.log("[MQTTNotificationService] FCM: getToken --->", FCMtoken);
|
|
78
|
+
// this.FCMcurrentToken = FCMtoken;
|
|
79
|
+
// this.saveToken(FCMtoken, currentUserUid)
|
|
80
|
+
// });
|
|
81
|
+
// }
|
|
82
|
+
// });
|
|
83
|
+
|
|
84
|
+
// }
|
|
64
85
|
}
|
|
65
86
|
}
|
|
66
87
|
|
|
@@ -83,7 +104,7 @@ export class MQTTNotifications extends NotificationsService {
|
|
|
83
104
|
let connectionsRefURL = '';
|
|
84
105
|
if (connectionsRefinstancesId) {
|
|
85
106
|
connectionsRefURL = connectionsRefinstancesId + self.FCMcurrentToken;
|
|
86
|
-
const connectionsRef =
|
|
107
|
+
const connectionsRef = firebase.database().ref().child(connectionsRefURL);
|
|
87
108
|
self.logger.log('[MQTTNotificationService] >>>> connectionsRef ', connectionsRef);
|
|
88
109
|
self.logger.log('[MQTTNotificationService] >>>> connectionsRef url ', connectionsRefURL);
|
|
89
110
|
connectionsRef.off()
|
|
@@ -107,7 +128,7 @@ export class MQTTNotifications extends NotificationsService {
|
|
|
107
128
|
const device_model = {
|
|
108
129
|
device_model: navigator.userAgent,
|
|
109
130
|
language: navigator.language,
|
|
110
|
-
platform:
|
|
131
|
+
platform: this.platform,
|
|
111
132
|
platform_version: this.BUILD_VERSION
|
|
112
133
|
}
|
|
113
134
|
this.chat21Service.chatClient.saveInstance(FCMcurrentToken,device_model,(err, response) => {
|
|
@@ -38,12 +38,20 @@ export const BCK_COLOR_CONVERSATION_UNSELECTED = '#FFFFFF ';
|
|
|
38
38
|
|
|
39
39
|
export const TYPE_SUPPORT_GROUP = 'support-group';
|
|
40
40
|
export const CHANNEL_TYPE_GROUP = 'group';
|
|
41
|
+
export const CHANNEL_TYPE_CHAT21 = 'chat21';
|
|
42
|
+
export const CHANNEL_TYPE_EMAIL = 'email';
|
|
43
|
+
export const CHANNEL_TYPE_FORM = 'form';
|
|
44
|
+
export const CHANNEL_TYPE_MESSANGER = 'messanger';
|
|
45
|
+
export const CHANNEL_TYPE_WHATSAPP = 'whatsapp';
|
|
46
|
+
export const CHANNEL_TYPE_TELEGRAM = 'telegram';
|
|
41
47
|
|
|
42
48
|
// TYPES MESSAGES
|
|
43
49
|
export const TYPE_MSG_TEXT = 'text';
|
|
44
50
|
export const TYPE_MSG_IMAGE = 'image';
|
|
45
51
|
export const TYPE_MSG_FILE = 'file';
|
|
46
52
|
export const TYPE_MSG_BUTTON = 'button';
|
|
53
|
+
export const TYPE_MSG_EMAIL = 'email';
|
|
54
|
+
export const TYPE_MSG_FORM = 'form';
|
|
47
55
|
|
|
48
56
|
export const MAX_WIDTH_IMAGES = 230;
|
|
49
57
|
export const MIN_WIDTH_IMAGES = 130;
|