chat4app-client-angular 0.0.1
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/README.md +24 -0
- package/karma.conf.js +44 -0
- package/ng-package.json +7 -0
- package/package.json +11 -0
- package/src/lib/chat4app-client-angular.component.spec.ts +25 -0
- package/src/lib/chat4app-client-angular.component.ts +20 -0
- package/src/lib/chat4app-client-angular.module.ts +12 -0
- package/src/lib/chat4app-client-angular.service.spec.ts +16 -0
- package/src/lib/chat4app-client-angular.service.ts +556 -0
- package/src/public-api.ts +7 -0
- package/src/test.ts +26 -0
- package/tsconfig.lib.json +26 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +17 -0
- package/tslint.json +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Chat4appClientAngular
|
|
2
|
+
|
|
3
|
+
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 11.1.1.
|
|
4
|
+
|
|
5
|
+
## Code scaffolding
|
|
6
|
+
|
|
7
|
+
Run `ng generate component component-name --project chat4app-client-angular` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project chat4app-client-angular`.
|
|
8
|
+
> Note: Don't forget to add `--project chat4app-client-angular` or else it will be added to the default project in your `angular.json` file.
|
|
9
|
+
|
|
10
|
+
## Build
|
|
11
|
+
|
|
12
|
+
Run `ng build chat4app-client-angular` to build the project. The build artifacts will be stored in the `dist/` directory.
|
|
13
|
+
|
|
14
|
+
## Publishing
|
|
15
|
+
|
|
16
|
+
After building your library with `ng build chat4app-client-angular`, go to the dist folder `cd dist/chat4app-client-angular` and run `npm publish`.
|
|
17
|
+
|
|
18
|
+
## Running unit tests
|
|
19
|
+
|
|
20
|
+
Run `ng test chat4app-client-angular` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
|
21
|
+
|
|
22
|
+
## Further help
|
|
23
|
+
|
|
24
|
+
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
package/karma.conf.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Karma configuration file, see link for more information
|
|
2
|
+
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
|
3
|
+
|
|
4
|
+
module.exports = function (config) {
|
|
5
|
+
config.set({
|
|
6
|
+
basePath: '',
|
|
7
|
+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
|
8
|
+
plugins: [
|
|
9
|
+
require('karma-jasmine'),
|
|
10
|
+
require('karma-chrome-launcher'),
|
|
11
|
+
require('karma-jasmine-html-reporter'),
|
|
12
|
+
require('karma-coverage'),
|
|
13
|
+
require('@angular-devkit/build-angular/plugins/karma')
|
|
14
|
+
],
|
|
15
|
+
client: {
|
|
16
|
+
jasmine: {
|
|
17
|
+
// you can add configuration options for Jasmine here
|
|
18
|
+
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
|
|
19
|
+
// for example, you can disable the random execution with `random: false`
|
|
20
|
+
// or set a specific seed with `seed: 4321`
|
|
21
|
+
},
|
|
22
|
+
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
|
23
|
+
},
|
|
24
|
+
jasmineHtmlReporter: {
|
|
25
|
+
suppressAll: true // removes the duplicated traces
|
|
26
|
+
},
|
|
27
|
+
coverageReporter: {
|
|
28
|
+
dir: require('path').join(__dirname, '../../coverage/chat4app-client-angular'),
|
|
29
|
+
subdir: '.',
|
|
30
|
+
reporters: [
|
|
31
|
+
{ type: 'html' },
|
|
32
|
+
{ type: 'text-summary' }
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
reporters: ['progress', 'kjhtml'],
|
|
36
|
+
port: 9876,
|
|
37
|
+
colors: true,
|
|
38
|
+
logLevel: config.LOG_INFO,
|
|
39
|
+
autoWatch: true,
|
|
40
|
+
browsers: ['Chrome'],
|
|
41
|
+
singleRun: false,
|
|
42
|
+
restartOnFileChange: true
|
|
43
|
+
});
|
|
44
|
+
};
|
package/ng-package.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { Chat4appClientAngularComponent } from './chat4app-client-angular.component';
|
|
4
|
+
|
|
5
|
+
describe('Chat4appClientAngularComponent', () => {
|
|
6
|
+
let component: Chat4appClientAngularComponent;
|
|
7
|
+
let fixture: ComponentFixture<Chat4appClientAngularComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
await TestBed.configureTestingModule({
|
|
11
|
+
declarations: [ Chat4appClientAngularComponent ]
|
|
12
|
+
})
|
|
13
|
+
.compileComponents();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
fixture = TestBed.createComponent(Chat4appClientAngularComponent);
|
|
18
|
+
component = fixture.componentInstance;
|
|
19
|
+
fixture.detectChanges();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should create', () => {
|
|
23
|
+
expect(component).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Component, OnInit } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
@Component({
|
|
4
|
+
selector: 'lib-chat4app-client-angular',
|
|
5
|
+
template: `
|
|
6
|
+
<p>
|
|
7
|
+
chat4app-client-angular works!
|
|
8
|
+
</p>
|
|
9
|
+
`,
|
|
10
|
+
styles: [
|
|
11
|
+
]
|
|
12
|
+
})
|
|
13
|
+
export class Chat4appClientAngularComponent implements OnInit {
|
|
14
|
+
|
|
15
|
+
constructor() { }
|
|
16
|
+
|
|
17
|
+
ngOnInit(): void {
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { Chat4appClientAngularComponent } from './chat4app-client-angular.component';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@NgModule({
|
|
7
|
+
declarations: [Chat4appClientAngularComponent],
|
|
8
|
+
imports: [
|
|
9
|
+
],
|
|
10
|
+
exports: [Chat4appClientAngularComponent]
|
|
11
|
+
})
|
|
12
|
+
export class Chat4appClientAngularModule { }
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { Chat4appClientAngularService } from './chat4app-client-angular.service';
|
|
4
|
+
|
|
5
|
+
describe('Chat4appClientAngularService', () => {
|
|
6
|
+
let service: Chat4appClientAngularService;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
TestBed.configureTestingModule({});
|
|
10
|
+
service = TestBed.inject(Chat4appClientAngularService);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should be created', () => {
|
|
14
|
+
expect(service).toBeTruthy();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
import { Injectable, OnInit } from '@angular/core';
|
|
2
|
+
import * as Stomp from 'stompjs';
|
|
3
|
+
import * as SockJS from 'sockjs-client';
|
|
4
|
+
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
5
|
+
import { Observable } from 'rxjs';
|
|
6
|
+
import * as moment from 'moment';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@Injectable({
|
|
11
|
+
providedIn: 'root'
|
|
12
|
+
})
|
|
13
|
+
export class Chat4appClientAngularService implements OnInit {
|
|
14
|
+
|
|
15
|
+
chatServer = "";
|
|
16
|
+
chatUrl = "";
|
|
17
|
+
|
|
18
|
+
sock: any;
|
|
19
|
+
stompClient: any;
|
|
20
|
+
|
|
21
|
+
constructor( private http: HttpClient) {
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
ngOnInit(): void {
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
config(chat4AppConfig: Chat4AppConfig) {
|
|
28
|
+
this.chatServer = chat4AppConfig.endpoint;
|
|
29
|
+
this.chatUrl = chat4AppConfig.endpoint + "/api/v1/" ;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
init(callback: any, chatCallback?: IChatCallback, token?: string) {
|
|
33
|
+
|
|
34
|
+
if (!this.chatServer || this.chatServer.trim().length == 0){
|
|
35
|
+
throw new Error("Invalid endpoint");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
this.getTokenChat4app().subscribe((res: any) => {
|
|
39
|
+
this.setTokenChat4app(res.token);
|
|
40
|
+
|
|
41
|
+
if (chatCallback && token) {
|
|
42
|
+
this.connectWebsocket(chatCallback, token);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
callback(res.token);
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getChatUrlDownload(messageFileId: string) {
|
|
50
|
+
return this.chatUrl + "chatmessage/getFile?messageFileId=" + messageFileId;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
getMessageChat(chatId: string, fromId: string, toId: string): Observable<Array<ChatMessage4App>> {
|
|
55
|
+
let url = this.chatUrl + "chatmessage/" + chatId + "/" + fromId + "/" + toId;
|
|
56
|
+
|
|
57
|
+
return this.http.get<Array<ChatMessage4App>>(url,
|
|
58
|
+
{
|
|
59
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
getMessageChatByGrop(chatId: string, groupId: string, fromId: string): Observable<Array<ChatMessage4App>> {
|
|
64
|
+
let url = this.chatUrl + "chatmessage/byGroup/" + chatId + "/" + groupId + "/" + fromId;
|
|
65
|
+
|
|
66
|
+
return this.http.get<Array<ChatMessage4App>>(url,
|
|
67
|
+
{
|
|
68
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
addMessageChat(chatMessage4App: ChatMessage4App): Observable<ChatMessage4App> {
|
|
75
|
+
let url = this.chatUrl + "chatmessage/" + chatMessage4App.chatId;
|
|
76
|
+
|
|
77
|
+
return this.http.post<ChatMessage4App>(url, chatMessage4App,
|
|
78
|
+
{
|
|
79
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
props(chatFilterRequest4App: Array<ChatFilterRequest4App>): Observable<ChatUserResponse4App> {
|
|
84
|
+
let url = this.chatUrl + "chatmessage/props";
|
|
85
|
+
|
|
86
|
+
return this.http.post<ChatUserResponse4App>(url, chatFilterRequest4App,
|
|
87
|
+
{
|
|
88
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
removeUsersChat(chatId: string, chatUsersId?: string[], chatUsersExternalId?: string[]): Observable<ChatUser4App[]> {
|
|
95
|
+
let params = new Array();
|
|
96
|
+
if (chatUsersId && chatUsersId.length > 0) {
|
|
97
|
+
|
|
98
|
+
chatUsersId.forEach(cui => {
|
|
99
|
+
params.push("chatUserId=" + cui);
|
|
100
|
+
});
|
|
101
|
+
} else if (chatUsersExternalId && chatUsersExternalId.length > 0) {
|
|
102
|
+
chatUsersExternalId.forEach(cuei => {
|
|
103
|
+
params.push("chatUserExternalId=" + cuei);
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let url = this.chatUrl + "chatuser/" + chatId + "?" + params.join("&");
|
|
109
|
+
|
|
110
|
+
return this.http.delete<ChatUser4App[]>(url,
|
|
111
|
+
{
|
|
112
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
removeUserChat(chatId: string, chatUserId?: string, chatUserExternalId?: string): Observable<ChatUser4App> {
|
|
117
|
+
let param = "";
|
|
118
|
+
if (chatUserId) {
|
|
119
|
+
param = "chatUserId=" + chatUserId;
|
|
120
|
+
} else {
|
|
121
|
+
param = "chatUserExternalId=" + chatUserExternalId;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let url = this.chatUrl + "chatuser/" + chatId + "?" + param;
|
|
125
|
+
|
|
126
|
+
return this.http.delete<ChatUser4App>(url,
|
|
127
|
+
{
|
|
128
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
updateUserChat(chatId: string, charUser4AppUpdate: ChatUser4App): Observable<ChatUser4App> {
|
|
133
|
+
|
|
134
|
+
let url = this.chatUrl + "chatuser/" + chatId;
|
|
135
|
+
|
|
136
|
+
return this.http.put<ChatUser4App>(url, charUser4AppUpdate,
|
|
137
|
+
{
|
|
138
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
createUserChat(chatId: string, chatUser4App: ChatUser4App): Observable<ChatUser4App> {
|
|
144
|
+
let url = this.chatUrl + "chatuser/" + chatId;
|
|
145
|
+
|
|
146
|
+
return this.http.post<ChatUser4App>(url, chatUser4App,
|
|
147
|
+
{
|
|
148
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
createUsersChat(chatId: string, chatUser4App: ChatUser4App[]): Observable<ChatUser4App[]> {
|
|
153
|
+
let url = this.chatUrl + "chatuser/users/" + chatId;
|
|
154
|
+
|
|
155
|
+
return this.http.post<ChatUser4App[]>(url, chatUser4App,
|
|
156
|
+
{
|
|
157
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
createChat(chat4app: Chat4App): Observable<Chat4App> {
|
|
163
|
+
let url = this.chatUrl + "chat";
|
|
164
|
+
|
|
165
|
+
return this.http.post<Chat4App>(url, chat4app,
|
|
166
|
+
{
|
|
167
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
createUpdateChat(chat4app: Chat4App): Observable<Chat4App> {
|
|
171
|
+
let url = this.chatUrl + "chat";
|
|
172
|
+
|
|
173
|
+
return this.http.put<Chat4App>(url, chat4app,
|
|
174
|
+
{
|
|
175
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
getLastMessageGroup(chatExternalId: string, groupId: string): Observable<ChatUserResponse4App> {
|
|
181
|
+
|
|
182
|
+
let url = this.chatUrl + "chatmessage/lastMessageGroup?chatExternalId=" + chatExternalId + "&groupId=" + groupId;
|
|
183
|
+
|
|
184
|
+
return this.http.get<ChatUserResponse4App>(url,
|
|
185
|
+
{
|
|
186
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
187
|
+
})
|
|
188
|
+
}
|
|
189
|
+
getLastMessage(chatExternalId: string, chatUserExternalId: string): Observable<ChatUserResponse4App> {
|
|
190
|
+
|
|
191
|
+
let url = this.chatUrl + "chatmessage/lastMessage?chatExternalId=" + chatExternalId + "&chatUserExternalId=" + chatUserExternalId;
|
|
192
|
+
|
|
193
|
+
return this.http.get<ChatUserResponse4App>(url,
|
|
194
|
+
{
|
|
195
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
countNotReadMessages(chatUserExternalId: string, chatExternalId?: string, groupId?: string): Observable<ChatUserResponse4App> {
|
|
199
|
+
|
|
200
|
+
let url = this.chatUrl + "chatmessage/countNotReadMessages?chatUserExternalId=" + chatUserExternalId;
|
|
201
|
+
|
|
202
|
+
if (chatExternalId && chatExternalId.length > 0) {
|
|
203
|
+
url += "&chatExternalId=" + chatExternalId;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (groupId && groupId.length > 0) {
|
|
207
|
+
url += "&groupId=" + groupId;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return this.http.get<ChatUserResponse4App>(url,
|
|
211
|
+
{
|
|
212
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
213
|
+
})
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
getChatByExternalId(externalId: string): Observable<Chat4App> {
|
|
218
|
+
|
|
219
|
+
let url = this.chatUrl + "chat?externalId=" + externalId;
|
|
220
|
+
|
|
221
|
+
return this.http.get<Chat4App>(url,
|
|
222
|
+
{
|
|
223
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
224
|
+
})
|
|
225
|
+
}
|
|
226
|
+
readMessage(chatMessageId: string, toId?: string): Observable<void> {
|
|
227
|
+
|
|
228
|
+
let url = this.chatUrl + "chatmessage/read/" + chatMessageId;
|
|
229
|
+
|
|
230
|
+
if (toId && toId.length > 0) {
|
|
231
|
+
url += "/" + toId;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return this.http.put<void>(url, null,
|
|
235
|
+
{
|
|
236
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
online(chatId: string, chatUserId: string): Observable<number> {
|
|
240
|
+
|
|
241
|
+
let url = this.chatUrl + "chatmessage/online/" + chatId + "/" + chatUserId;
|
|
242
|
+
|
|
243
|
+
return this.http.get<number>(url,
|
|
244
|
+
{
|
|
245
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
sendFile(chatId: string, fromId: string, toId: string, fileToUpload: File): Observable<ChatMessageFile4App> {
|
|
251
|
+
const endpoint = this.chatUrl + "chatmessage/sendFile/" + chatId + "/" + fromId + "/" + toId;
|
|
252
|
+
|
|
253
|
+
const formData: FormData = new FormData();
|
|
254
|
+
formData.append('file', fileToUpload);
|
|
255
|
+
|
|
256
|
+
return this.http
|
|
257
|
+
.post<ChatMessageFile4App>(endpoint, formData,
|
|
258
|
+
{
|
|
259
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
sendFileGroup(chatId: string, fromId: string, groupId: string, fileToUpload: File): Observable<ChatMessageFile4App> {
|
|
264
|
+
const endpoint = this.chatUrl + "chatmessage/sendFileGroup/" + chatId + "/" + fromId + "/" + groupId;
|
|
265
|
+
|
|
266
|
+
const formData: FormData = new FormData();
|
|
267
|
+
formData.append('file', fileToUpload);
|
|
268
|
+
|
|
269
|
+
return this.http
|
|
270
|
+
.post<ChatMessageFile4App>(endpoint, formData,
|
|
271
|
+
{
|
|
272
|
+
headers: new HttpHeaders().set('Authorization', this.getBearerToken())
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
/* Token */
|
|
278
|
+
getBearerToken(): string {
|
|
279
|
+
|
|
280
|
+
let ret = "Bearer " + window.sessionStorage.getItem("chat4AppSessionToken");
|
|
281
|
+
|
|
282
|
+
return ret;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
getTokenChat4app() {
|
|
286
|
+
return this.http.post("/rest/secured/chat-helper", null);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
setTokenChat4app(chat4AppSessionToken: string) {
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
window.sessionStorage.setItem("chat4AppSessionToken", chat4AppSessionToken);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
/* Connection */
|
|
297
|
+
|
|
298
|
+
onMessageFirebaseReceived(data: any, chatCallback: IChatCallback) {
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
//alert("onMessageReceived connectFirebase");
|
|
302
|
+
|
|
303
|
+
if (data.type == "msg") {
|
|
304
|
+
|
|
305
|
+
let chat4appMessage = new Chat4AppMessageReceive();
|
|
306
|
+
chat4appMessage.data.chatId = data.chatId;
|
|
307
|
+
chat4appMessage.data.chatMessageId = data.chatMessageId;
|
|
308
|
+
chat4appMessage.data.externalId = data.externalId;
|
|
309
|
+
chat4appMessage.data.fromId = data.fromId;
|
|
310
|
+
chat4appMessage.data.toId = data.toId;
|
|
311
|
+
chat4appMessage.data.dateHour = data.dateHour;
|
|
312
|
+
chat4appMessage.data.type = data.type;
|
|
313
|
+
chat4appMessage.notification.body = data.body;
|
|
314
|
+
|
|
315
|
+
if (data.fileId && data.fileId.length > 0) {
|
|
316
|
+
chat4appMessage.data.fileId = data.fileId;
|
|
317
|
+
chat4appMessage.data.fileName = data.fileName;
|
|
318
|
+
chat4appMessage.data.fileSize = data.fileSize;
|
|
319
|
+
chat4appMessage.data.fileType = data.fileType;
|
|
320
|
+
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
let datTmp = new Map<string, string>();
|
|
324
|
+
|
|
325
|
+
for (let key in data) {
|
|
326
|
+
datTmp.set(key, data[key]);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
chat4appMessage.data.all = datTmp;
|
|
330
|
+
|
|
331
|
+
chatCallback.onMessage(chat4appMessage);
|
|
332
|
+
|
|
333
|
+
} else if ((data.type == "on" || data.type == "off")) {
|
|
334
|
+
let chat4appMessage = new Chat4AppMessageReceive();
|
|
335
|
+
chat4appMessage.data.chatId = data.chatId;
|
|
336
|
+
chat4appMessage.data.chatMessageId = data.chatMessageId;
|
|
337
|
+
chat4appMessage.data.externalId = data.externalId;
|
|
338
|
+
chat4appMessage.data.fromId = data.fromId;
|
|
339
|
+
chat4appMessage.data.toId = data.toId;
|
|
340
|
+
chat4appMessage.data.dateHour = data.dateHour;
|
|
341
|
+
chat4appMessage.data.type = data.type;
|
|
342
|
+
|
|
343
|
+
let datTmp = new Map<string, string>();
|
|
344
|
+
|
|
345
|
+
for (let key in data) {
|
|
346
|
+
datTmp.set(key, data[key]);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
chat4appMessage.data.all = datTmp;
|
|
350
|
+
|
|
351
|
+
chatCallback.onOffline(chat4appMessage);
|
|
352
|
+
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
connectWebsocket(chatCallback: IChatCallback, token: string) {
|
|
357
|
+
this.disconnect();
|
|
358
|
+
|
|
359
|
+
let securityToken = this.getBearerToken();
|
|
360
|
+
|
|
361
|
+
this.sock = new SockJS(this.chatServer + '/stomp/gkz-stomp-endpoint?token=' + securityToken);
|
|
362
|
+
this.stompClient = Stomp.over(this.sock);
|
|
363
|
+
this.stompClient.debug = function (msg: any) {
|
|
364
|
+
//console.log(msg);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
this.stompClient.connect({}, (frame: any) => {
|
|
368
|
+
//console.log(frame);
|
|
369
|
+
|
|
370
|
+
this.stompClient.subscribe('/queue/' + token, (msg: any) => {
|
|
371
|
+
//console.log('mensagem', msg);
|
|
372
|
+
|
|
373
|
+
if (msg.command == "MESSAGE") {
|
|
374
|
+
|
|
375
|
+
//console.log(msg)
|
|
376
|
+
|
|
377
|
+
let msgObj = JSON.parse(msg.body);
|
|
378
|
+
|
|
379
|
+
let datTmp = new Map<string, string>();
|
|
380
|
+
|
|
381
|
+
for (let key in msgObj.data) {
|
|
382
|
+
datTmp.set(key, msgObj.data[key]);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
msgObj.data.all = datTmp;
|
|
386
|
+
|
|
387
|
+
if (msgObj.data.type == "msg") {
|
|
388
|
+
chatCallback.onMessage(msgObj);
|
|
389
|
+
} else if ((msgObj.data.type == "on" || msgObj.data.type == "off")) {
|
|
390
|
+
chatCallback.onOffline(msgObj);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
//callback(msg.body);
|
|
394
|
+
// ichatcallback.forEach((iChat)=>{
|
|
395
|
+
// iChat.onMessage(JSON.parse(msg.body) );
|
|
396
|
+
// });
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
});
|
|
400
|
+
},
|
|
401
|
+
(message: any) => {
|
|
402
|
+
// check message for disconnect
|
|
403
|
+
//console.log("Disconnect");
|
|
404
|
+
|
|
405
|
+
setTimeout(() => {
|
|
406
|
+
this.connectWebsocket(chatCallback, token);
|
|
407
|
+
}, 500);
|
|
408
|
+
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
disconnect() {
|
|
414
|
+
// console.log("disconnect")
|
|
415
|
+
try {
|
|
416
|
+
if (this.stompClient) {
|
|
417
|
+
this.stompClient.disconnect();
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
} catch (e) {
|
|
421
|
+
console.log(e);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
convertChat4AppMessageReceiveToChatMessage4App(msg: Chat4AppMessageReceive): ChatMessage4App{
|
|
426
|
+
let message = new ChatMessage4App();
|
|
427
|
+
message.body = msg.notification.body;
|
|
428
|
+
message.chatId = msg.data.chatId;
|
|
429
|
+
message.fromId = msg.data.fromId;
|
|
430
|
+
message.toId = msg.data.toId;
|
|
431
|
+
message.dateHourIncluded = moment.utc(msg.data.dateHour, "DD-MM-YYYY hh:mm:ss").toDate();
|
|
432
|
+
|
|
433
|
+
if (msg.data.fileId && msg.data.fileId.length > 0) {
|
|
434
|
+
let messageFile = new ChatMessageFile4App();
|
|
435
|
+
|
|
436
|
+
messageFile.id = msg.data.fileId;
|
|
437
|
+
messageFile.name = msg.data.fileName;
|
|
438
|
+
messageFile.size = msg.data.fileSize;
|
|
439
|
+
messageFile.type = msg.data.fileType;
|
|
440
|
+
|
|
441
|
+
message.chatMessageFile = messageFile;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return message;
|
|
445
|
+
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
export class Chat4App {
|
|
452
|
+
id: string;
|
|
453
|
+
configId: string;
|
|
454
|
+
externalId: string;
|
|
455
|
+
title: string;
|
|
456
|
+
status: ChatStatus4App;
|
|
457
|
+
users: Array<ChatUser4App>;
|
|
458
|
+
|
|
459
|
+
}
|
|
460
|
+
export class ChatUser4App {
|
|
461
|
+
id: string;
|
|
462
|
+
name: string;
|
|
463
|
+
clientToken: string;
|
|
464
|
+
picturePath: string;
|
|
465
|
+
email: string;
|
|
466
|
+
externalId: string;
|
|
467
|
+
status: ChatUserStatus4App;
|
|
468
|
+
}
|
|
469
|
+
export class ChatMessage4App {
|
|
470
|
+
id: string;
|
|
471
|
+
fromId: string;
|
|
472
|
+
toId: string;
|
|
473
|
+
chatId: string;
|
|
474
|
+
title: string;
|
|
475
|
+
body: string;
|
|
476
|
+
meta: Array<ChatMessageMeta4App>;
|
|
477
|
+
groupId: string;
|
|
478
|
+
read: Boolean;
|
|
479
|
+
dateHourIncluded: Date;
|
|
480
|
+
chatMessageFile: ChatMessageFile4App;
|
|
481
|
+
}
|
|
482
|
+
export class ChatMessageFile4App {
|
|
483
|
+
id: string;
|
|
484
|
+
name: string;
|
|
485
|
+
type: string;
|
|
486
|
+
size: number;
|
|
487
|
+
fullPath: string;
|
|
488
|
+
}
|
|
489
|
+
export class ChatMessageMeta4App {
|
|
490
|
+
name: string;
|
|
491
|
+
value: string;
|
|
492
|
+
}
|
|
493
|
+
export class Chat4AppMessageReceive {
|
|
494
|
+
data: Chat4AppMessageReceiveData = new Chat4AppMessageReceiveData();
|
|
495
|
+
notification: Chat4AppMessageReceiveNotification = new Chat4AppMessageReceiveNotification();
|
|
496
|
+
token: string;
|
|
497
|
+
}
|
|
498
|
+
export class Chat4AppMessageReceiveData {
|
|
499
|
+
toId: string;
|
|
500
|
+
chatId: string;
|
|
501
|
+
dateHour: string;
|
|
502
|
+
chatMessageId: string;
|
|
503
|
+
externalId: string;
|
|
504
|
+
type: string;
|
|
505
|
+
fromId: string;
|
|
506
|
+
fileId: string;
|
|
507
|
+
fileName: string;
|
|
508
|
+
fileSize: number;
|
|
509
|
+
fileType: string;
|
|
510
|
+
all: Map<string, string>;
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
}
|
|
515
|
+
export class Chat4AppMessageReceiveNotification {
|
|
516
|
+
body: string;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export class ChatUserResponse4App {
|
|
520
|
+
totalMessages: number;
|
|
521
|
+
chat: Chat4App;
|
|
522
|
+
chatMessage: ChatMessage4App;
|
|
523
|
+
chats: ChatUserResponse4App[];
|
|
524
|
+
}
|
|
525
|
+
export class ChatFilterRequest4App {
|
|
526
|
+
type: ChatFilterType;
|
|
527
|
+
chatExternalId: string;
|
|
528
|
+
chatUserExternalId: string;
|
|
529
|
+
groupId: string;
|
|
530
|
+
}
|
|
531
|
+
export class Chat4AppConfig {
|
|
532
|
+
constructor(public endpoint: string) {
|
|
533
|
+
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
export enum ChatStatus4App {
|
|
539
|
+
CREATED = "CREATED",
|
|
540
|
+
CLOSED = "CLOSED"
|
|
541
|
+
|
|
542
|
+
}
|
|
543
|
+
export enum ChatUserStatus4App {
|
|
544
|
+
REMOVED = "REMOVED"
|
|
545
|
+
|
|
546
|
+
}
|
|
547
|
+
export enum ChatFilterType {
|
|
548
|
+
COUNT_NOT_READ = 1,
|
|
549
|
+
LAST_MESSAGE = 2
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
export interface IChatCallback {
|
|
553
|
+
onMessage(msg: Chat4AppMessageReceive): void;
|
|
554
|
+
onOffline(msg: Chat4AppMessageReceive): void;
|
|
555
|
+
}
|
|
556
|
+
|
package/src/test.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
|
2
|
+
|
|
3
|
+
import 'zone.js/dist/zone';
|
|
4
|
+
import 'zone.js/dist/zone-testing';
|
|
5
|
+
import { getTestBed } from '@angular/core/testing';
|
|
6
|
+
import {
|
|
7
|
+
BrowserDynamicTestingModule,
|
|
8
|
+
platformBrowserDynamicTesting
|
|
9
|
+
} from '@angular/platform-browser-dynamic/testing';
|
|
10
|
+
|
|
11
|
+
declare const require: {
|
|
12
|
+
context(path: string, deep?: boolean, filter?: RegExp): {
|
|
13
|
+
keys(): string[];
|
|
14
|
+
<T>(id: string): T;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// First, initialize the Angular testing environment.
|
|
19
|
+
getTestBed().initTestEnvironment(
|
|
20
|
+
BrowserDynamicTestingModule,
|
|
21
|
+
platformBrowserDynamicTesting()
|
|
22
|
+
);
|
|
23
|
+
// Then we find all the tests.
|
|
24
|
+
const context = require.context('./', true, /\.spec\.ts$/);
|
|
25
|
+
// And load the modules.
|
|
26
|
+
context.keys().map(context);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
+
{
|
|
3
|
+
"extends": "../../tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "../../out-tsc/lib",
|
|
6
|
+
"target": "es2015",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"inlineSources": true,
|
|
10
|
+
"types": [],
|
|
11
|
+
"lib": [
|
|
12
|
+
"dom",
|
|
13
|
+
"es2018"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"angularCompilerOptions": {
|
|
17
|
+
"skipTemplateCodegen": true,
|
|
18
|
+
"strictMetadataEmit": true,
|
|
19
|
+
"enableResourceInlining": true,
|
|
20
|
+
"enableIvy": false
|
|
21
|
+
},
|
|
22
|
+
"exclude": [
|
|
23
|
+
"src/test.ts",
|
|
24
|
+
"**/*.spec.ts"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
+
{
|
|
3
|
+
"extends": "../../tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "../../out-tsc/spec",
|
|
6
|
+
"types": [
|
|
7
|
+
"jasmine"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src/test.ts"
|
|
12
|
+
],
|
|
13
|
+
"include": [
|
|
14
|
+
"**/*.spec.ts",
|
|
15
|
+
"**/*.d.ts"
|
|
16
|
+
]
|
|
17
|
+
}
|