2020-04-12 14:25:42 +00:00
|
|
|
<template>
|
2020-04-29 23:45:50 +00:00
|
|
|
<div class="is-fullwidth">
|
2020-04-12 14:25:42 +00:00
|
|
|
<div v-if="loading">
|
|
|
|
<Loading />
|
|
|
|
</div>
|
2020-04-14 00:56:04 +00:00
|
|
|
<div v-else class>
|
2020-04-29 23:45:50 +00:00
|
|
|
<VideoStrip :localStream="localStream" :remoteStream="remoteStream" />
|
2020-05-03 22:38:33 +00:00
|
|
|
<transition :name="stateTransitionName">
|
|
|
|
<router-view></router-view>
|
|
|
|
</transition>
|
2020-04-12 14:25:42 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Loading from "../../shared/components/Loading/Loading.vue";
|
2020-05-01 05:55:26 +00:00
|
|
|
import CallManager, { ECallEvents } from "../ws/call.manager";
|
|
|
|
import WebsocketService from "../ws/websocket.service";
|
2020-04-29 23:45:50 +00:00
|
|
|
import VideoStrip from "./call_views/VideoStrip.vue";
|
2020-04-12 14:25:42 +00:00
|
|
|
import Services from "../../services/index";
|
|
|
|
import { mapActions, mapGetters } from "vuex";
|
|
|
|
export default {
|
|
|
|
components: {
|
2020-04-14 00:56:04 +00:00
|
|
|
Loading,
|
2020-04-29 23:45:50 +00:00
|
|
|
VideoStrip
|
2020-04-12 14:25:42 +00:00
|
|
|
},
|
|
|
|
name: "Call",
|
|
|
|
async created() {
|
|
|
|
this.loading = true;
|
|
|
|
try {
|
2020-04-12 23:33:24 +00:00
|
|
|
const callId = Number(this.$route.params.id);
|
2020-05-01 05:55:26 +00:00
|
|
|
const ws = await WebsocketService.getInstance();
|
|
|
|
this.callManager = ws.callManager;
|
|
|
|
this.callManager.on(ECallEvents.CLOSE, this.endCall);
|
2020-04-29 23:45:50 +00:00
|
|
|
|
2020-05-01 05:55:26 +00:00
|
|
|
const success = await this.callManager.connectToCall(
|
|
|
|
this.user.id,
|
|
|
|
{
|
|
|
|
video: true,
|
|
|
|
audio: true
|
|
|
|
},
|
|
|
|
callId
|
|
|
|
);
|
2020-04-14 15:06:09 +00:00
|
|
|
this.callManager.on(
|
|
|
|
ECallEvents.CALL_HOST_CHANGED,
|
|
|
|
this.onRemoteHostChanged
|
|
|
|
);
|
2020-04-12 14:25:42 +00:00
|
|
|
if (!success) {
|
|
|
|
this.notify({ message: "Can find this call...", level: "danger" });
|
|
|
|
this.$router.push({ path: `/` });
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-01 05:55:26 +00:00
|
|
|
this.callStarted();
|
2020-04-12 23:53:24 +00:00
|
|
|
this.localStream = await this.callManager.getUserMedia();
|
2020-04-12 23:33:24 +00:00
|
|
|
this.remoteStream = this.callManager.getRemoteStream();
|
2020-04-12 14:25:42 +00:00
|
|
|
this.notify({ message: "Connected!", level: "success" });
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
this.notify({ message: e.message, level: "danger" });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.loading = false;
|
|
|
|
},
|
|
|
|
async beforeDestroy() {
|
|
|
|
console.log("destroyed");
|
2020-04-12 23:33:24 +00:00
|
|
|
this.callManager.close();
|
2020-05-01 05:55:26 +00:00
|
|
|
this.callEnded();
|
2020-04-12 14:25:42 +00:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
methods: {
|
2020-04-12 23:33:24 +00:00
|
|
|
async setupCall(): Promise<boolean> {
|
|
|
|
return true;
|
|
|
|
},
|
2020-05-01 05:55:26 +00:00
|
|
|
endCall(callId) {
|
2020-04-12 23:33:24 +00:00
|
|
|
this.notify({ message: `Call #${callId} Ended` });
|
2020-04-29 23:45:50 +00:00
|
|
|
this.$router.replace({ path: `/` });
|
2020-04-12 23:33:24 +00:00
|
|
|
},
|
2020-04-14 15:06:09 +00:00
|
|
|
onRemoteHostChanged(payload) {
|
|
|
|
console.log("-----------");
|
|
|
|
console.log(payload);
|
2020-04-28 03:04:09 +00:00
|
|
|
this.peer = this.callManager.peer;
|
2020-04-14 15:06:09 +00:00
|
|
|
},
|
|
|
|
changeHost() {
|
|
|
|
this.callManager.changeHost();
|
|
|
|
},
|
2020-05-01 05:55:26 +00:00
|
|
|
...mapActions(["notify", "callStarted", "callEnded"])
|
2020-04-12 14:25:42 +00:00
|
|
|
},
|
|
|
|
computed: {
|
2020-05-01 05:55:26 +00:00
|
|
|
...mapGetters(["user", "inCall"])
|
2020-04-12 14:25:42 +00:00
|
|
|
},
|
2020-05-03 22:38:33 +00:00
|
|
|
watch: {
|
|
|
|
$route(to, from) {
|
|
|
|
const toDepth = to.path.split("/").length;
|
|
|
|
const fromDepth = from.path.split("/").length;
|
|
|
|
this.stateTransitionName =
|
|
|
|
toDepth < fromDepth ? "slide-right" : "slide-left";
|
|
|
|
}
|
|
|
|
},
|
2020-04-12 14:25:42 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
loading: true,
|
2020-04-13 00:37:58 +00:00
|
|
|
localStream: null,
|
2020-05-01 05:55:26 +00:00
|
|
|
remoteStream: null,
|
2020-05-03 22:38:33 +00:00
|
|
|
callManager: null as CallManager,
|
|
|
|
stateTransitionName: "slide-left"
|
2020-04-12 14:25:42 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
beforeCreate: () => {}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
2020-04-14 00:56:04 +00:00
|
|
|
|