This commit is contained in:
Peter Maquiran
2021-08-19 09:10:38 +01:00
parent 94ec7f2651
commit 724445084a
3 changed files with 61 additions and 9 deletions
+34 -6
View File
@@ -23,10 +23,24 @@ export class SynchroService {
private id: string = uuidv4();
public conected = false
private url: string = ''
callback = function(){}
constructor(){}
setUrl(wss:wss) {
setUrl() {
let header ={
id:'1234',
bluePrint: '12312123',
jwt: uuidv4()
}
let wss: wss ={
header,
url: 'wss://synchro-server.herokuapp.com/ws/some_url/',
type: 'reflect'
}
this.url = `${wss.url}${wss.header.id}/${wss.header.jwt}/${wss.header.bluePrint}/${this.id}/`
}
@@ -42,19 +56,28 @@ export class SynchroService {
private onopen = () =>{
console.log('open ======================= welcome to socket server')
// this.connection.send(JSON.stringify({user:'user1'}));
}
public $send = (object: any) => {
let sendData = JSON.stringify(Object.assign({}, object));
public $send(object: any) {
let message = {
message: '{"person.adress.country":"1Angola"}',
username: '',
idConnection: this.id
}
let sendData = JSON.stringify(Object.assign({}, message));
this.connection.send(sendData);
}
private onmessage = async (event: any)=> {
// alert('message')
this.callback()
}
private onclose=(event:any)=>{
private onclose=(event:any)=> {
setTimeout(() => {
if (event.wasClean) {
console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
@@ -72,3 +95,8 @@ export class SynchroService {
console.log(`[error] ${event.message}`);
}
}
export const connection = new SynchroService()
connection.setUrl()
connection.connect()