2022-01-07 09:03:15 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { SocketInterfaceService } from './interface/socket-interface.service'
|
|
|
|
|
import { environment } from 'src/environments/environment';
|
2022-01-07 11:21:14 +01:00
|
|
|
import { v4 as uuidv4 } from 'uuid'
|
2022-01-07 09:03:15 +01:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class RocketChatClientService {
|
|
|
|
|
|
|
|
|
|
private SocketInterfaceService = new SocketInterfaceService()
|
|
|
|
|
|
2022-01-07 14:29:41 +01:00
|
|
|
constructor() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private returns() {}
|
2022-01-07 11:21:14 +01:00
|
|
|
|
|
|
|
|
connect(url = 'wss://gabinetedigitalchat.dyndns.info/websocket') {
|
|
|
|
|
|
|
|
|
|
this.SocketInterfaceService.connect(url);
|
|
|
|
|
|
|
|
|
|
const connectMessage = {
|
|
|
|
|
msg: "connect",
|
|
|
|
|
version: "1",
|
|
|
|
|
support: ["1"]
|
|
|
|
|
}
|
|
|
|
|
this.SocketInterfaceService.send(connectMessage)
|
2022-01-07 09:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
login(user) {
|
2022-01-07 14:29:41 +01:00
|
|
|
const requestId = uuidv4()
|
|
|
|
|
|
2022-01-07 09:03:15 +01:00
|
|
|
const loginRequest = {
|
|
|
|
|
msg: "method",
|
|
|
|
|
method: "login",
|
2022-01-07 14:29:41 +01:00
|
|
|
id: requestId,
|
2022-01-07 09:03:15 +01:00
|
|
|
params: [
|
|
|
|
|
{
|
|
|
|
|
"user": { "username": user.username },
|
|
|
|
|
"password": {
|
|
|
|
|
"digest": user.password,
|
|
|
|
|
"algorithm":"sha-256"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2022-01-07 14:29:41 +01:00
|
|
|
this.SocketInterfaceService.send(loginRequest, requestId)
|
|
|
|
|
|
|
|
|
|
return requestId
|
2022-01-07 09:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logout(){ }
|
|
|
|
|
|
2022-01-07 11:21:14 +01:00
|
|
|
send(roomId, message, option) {
|
2022-01-07 14:29:41 +01:00
|
|
|
const requestId = uuidv4()
|
|
|
|
|
|
2022-01-07 11:21:14 +01:00
|
|
|
var request = {
|
2022-01-07 14:29:41 +01:00
|
|
|
msg: "method",
|
|
|
|
|
method: "sendMessage",
|
|
|
|
|
id: requestId,
|
|
|
|
|
params: [{
|
|
|
|
|
_id: "message-id" || uuidv4(),
|
|
|
|
|
rid: "room-id" || roomId,
|
|
|
|
|
msg: "Hello World!" || message
|
2022-01-07 11:21:14 +01:00
|
|
|
}]
|
2022-01-07 14:29:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.SocketInterfaceService.send(request, requestId);
|
2022-01-07 11:21:14 +01:00
|
|
|
|
2022-01-07 14:29:41 +01:00
|
|
|
return requestId;
|
2022-01-07 11:21:14 +01:00
|
|
|
}
|
2022-01-07 09:03:15 +01:00
|
|
|
|
|
|
|
|
receive() {}
|
|
|
|
|
joinRoom(){}
|
|
|
|
|
deleteMessage() {}
|
2022-01-07 11:21:14 +01:00
|
|
|
createRoom() {}
|
2022-01-07 14:29:41 +01:00
|
|
|
|
|
|
|
|
subscribe() {
|
|
|
|
|
var subscribeRequest = {
|
|
|
|
|
"msg": "sub",
|
|
|
|
|
"id": "unique-id",
|
|
|
|
|
"name": "stream-notify-room",
|
|
|
|
|
"params":[
|
|
|
|
|
"room-id/event",
|
|
|
|
|
false
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.SocketInterfaceService.send(subscribeRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private disconnect = () => {
|
|
|
|
|
|
|
|
|
|
}
|
2022-01-07 09:03:15 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window['RocketChatClientService'] = new RocketChatClientService();
|