50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
import { connectVoicesocket, disconnectVoicesocket, sendMessage, hangup } from "@/websocket/voiceSocket";
|
|
import { defineStore } from "pinia";
|
|
|
|
export const voiceStore = defineStore("voice", {
|
|
state: () => ({
|
|
isConnected: false
|
|
}),
|
|
actions: {
|
|
connect() {
|
|
connectVoicesocket();
|
|
this.isConnected = true;
|
|
},
|
|
disconnect() {
|
|
disconnectVoicesocket();
|
|
this.isConnected = false;
|
|
},
|
|
startCall(from, from_name, from_avatar, to) {
|
|
if (this.isConnected) {
|
|
const message = {
|
|
type: "incomingcall",
|
|
from: from,
|
|
from_name: from_name,
|
|
from_avatar: from_avatar,
|
|
to: to
|
|
}
|
|
sendMessage(JSON.stringify(message))
|
|
} else {
|
|
console.log("voice socket is not connected")
|
|
}
|
|
},
|
|
pickup(from,to){
|
|
if (this.isConnected) {
|
|
const message ={
|
|
type: "pickup",
|
|
from: from,
|
|
to: to
|
|
}
|
|
sendMessage(JSON.stringify(message))
|
|
} else {
|
|
console.log("voice socket is not connected")
|
|
}
|
|
},
|
|
hangup(){
|
|
hangup()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
) |