2020-04-12 14:25:42 +00:00
|
|
|
<template>
|
|
|
|
<div class="wrapper">
|
|
|
|
<div v-if="loading">
|
|
|
|
<Loading />
|
|
|
|
</div>
|
2020-04-14 00:56:04 +00:00
|
|
|
<div v-else class>
|
2020-04-14 15:06:09 +00:00
|
|
|
<div class="floating-host is-flex" style="position:fixed;top:60px;left:100px">
|
|
|
|
<h1 class="subtitle m-r-md">Host:</h1>
|
|
|
|
<div class="me">
|
|
|
|
<figure class="image is-24x24">
|
|
|
|
<img
|
2020-04-28 03:04:09 +00:00
|
|
|
:src="isHost? user.avatar : callManager.peer.avatar"
|
2020-04-14 15:06:09 +00:00
|
|
|
class="is-rounded is-avatar"
|
|
|
|
@click="changeHost()"
|
|
|
|
/>
|
|
|
|
</figure>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-04-14 01:40:10 +00:00
|
|
|
<div class="video-strip m-b-md is-outlined">
|
2020-04-14 00:56:04 +00:00
|
|
|
<video
|
|
|
|
:src-object.prop.camel="localStream"
|
|
|
|
autoplay
|
|
|
|
playsinline
|
|
|
|
muted="true"
|
2020-04-14 01:40:10 +00:00
|
|
|
style="max-width:20%"
|
2020-04-14 00:56:04 +00:00
|
|
|
/>
|
2020-04-14 01:40:10 +00:00
|
|
|
<video :src-object.prop.camel="remoteStream" autoplay style="max-width:20%" />
|
2020-04-14 00:56:04 +00:00
|
|
|
</div>
|
2020-04-14 15:06:09 +00:00
|
|
|
<div class="is-flex">
|
|
|
|
<div class="go-left m-r-sm" style="display: flex; align-items: center;">
|
|
|
|
<button class="button is-outlined" :disabled="!isHost" @click="onLeftClicked()">
|
|
|
|
<i class="fa fa-fw fa-arrow-left"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
2020-04-14 00:56:04 +00:00
|
|
|
<flipbook
|
|
|
|
class="flipbook"
|
|
|
|
:pages="createPages(book)"
|
|
|
|
forwardDirection="left"
|
|
|
|
:zooms="null"
|
2020-04-14 15:06:09 +00:00
|
|
|
:enabled="isHost"
|
2020-04-14 00:56:04 +00:00
|
|
|
@flip-left-end="onFlip('left')"
|
|
|
|
@flip-right-end="onFlip('right')"
|
|
|
|
ref="flipbook"
|
2020-04-14 15:06:09 +00:00
|
|
|
v-slot="flipbook"
|
|
|
|
>
|
|
|
|
<div class="page-progress has-text-centered m-b-none">
|
|
|
|
<p>Page {{ flipbook.page }} of {{ flipbook.numPages }}</p>
|
|
|
|
</div>
|
|
|
|
</flipbook>
|
|
|
|
<div class="go-right m-l-sm" style="display: flex; align-items: center;">
|
|
|
|
<button class="button is-outlined" :disabled="!isHost" @click="onRightClicked()">
|
|
|
|
<i class="fa fa-fw fa-arrow-right"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
2020-04-14 00:56:04 +00:00
|
|
|
</div>
|
2020-04-12 14:25:42 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Loading from "../../shared/components/Loading/Loading.vue";
|
|
|
|
import WebsocketService from "../scripts/websocket.service";
|
2020-04-12 23:33:24 +00:00
|
|
|
import CallManager, { ECallEvents } from "../classes/call.manager";
|
2020-04-14 15:06:09 +00:00
|
|
|
import Flipbook from "../components/flipbook/flipbook.cjs.js";
|
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,
|
|
|
|
Flipbook
|
2020-04-12 14:25:42 +00:00
|
|
|
},
|
|
|
|
name: "Call",
|
2020-04-14 15:06:09 +00:00
|
|
|
mounted() {
|
|
|
|
const self = this;
|
|
|
|
setTimeout(() => {
|
|
|
|
self.isMounted = true;
|
|
|
|
}, 1000);
|
|
|
|
},
|
2020-04-12 14:25:42 +00:00
|
|
|
async created() {
|
|
|
|
this.loading = true;
|
|
|
|
try {
|
2020-04-12 23:33:24 +00:00
|
|
|
const callId = Number(this.$route.params.id);
|
2020-04-12 14:25:42 +00:00
|
|
|
const ws = await WebsocketService.getInstance();
|
2020-04-14 15:06:09 +00:00
|
|
|
this.callManager = new CallManager(ws, callId, this.user.id);
|
2020-04-12 23:33:24 +00:00
|
|
|
this.callManager.on(ECallEvents.CLOSE, this.callEnded);
|
2020-04-14 00:56:04 +00:00
|
|
|
this.callManager.on(ECallEvents.ACTION_BOOK_FLIP, this.onRemoteFlip);
|
2020-04-12 23:33:24 +00:00
|
|
|
const success = await this.callManager.connectToCall({
|
2020-04-12 23:45:05 +00:00
|
|
|
video: true,
|
2020-04-12 23:33:24 +00:00
|
|
|
audio: true
|
|
|
|
});
|
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-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-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-04-14 00:56:04 +00:00
|
|
|
onFlip(direction: "left" | "right") {
|
2020-04-14 15:06:09 +00:00
|
|
|
if (this.isHost)
|
2020-04-14 00:56:04 +00:00
|
|
|
this.callManager.send(`book:action:flip-page`, { direction });
|
|
|
|
},
|
2020-04-14 15:06:09 +00:00
|
|
|
onLeftClicked() {
|
|
|
|
this.$refs.flipbook.flipLeft();
|
|
|
|
},
|
|
|
|
onRightClicked() {
|
|
|
|
this.$refs.flipbook.flipRight();
|
|
|
|
},
|
2020-04-14 00:56:04 +00:00
|
|
|
onRemoteFlip(payload) {
|
|
|
|
switch (payload.direction) {
|
|
|
|
case "left":
|
|
|
|
this.$refs.flipbook.flipLeft();
|
|
|
|
break;
|
|
|
|
case "right":
|
|
|
|
this.$refs.flipbook.flipRight();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
createPages(book) {
|
|
|
|
const pages = [null];
|
|
|
|
for (let i = 1; i < book.pages + 1; i++) {
|
|
|
|
pages.push(`/u/images/${i}.JPG`);
|
|
|
|
}
|
|
|
|
return pages;
|
|
|
|
},
|
2020-04-12 23:33:24 +00:00
|
|
|
callEnded(callId) {
|
|
|
|
this.notify({ message: `Call #${callId} Ended` });
|
|
|
|
this.$router.push({ path: `/` });
|
|
|
|
},
|
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
|
|
|
this.isHost = this.callManager.isHost;
|
|
|
|
},
|
|
|
|
changeHost() {
|
|
|
|
this.callManager.changeHost();
|
|
|
|
},
|
2020-04-12 14:25:42 +00:00
|
|
|
...mapActions(["notify"])
|
|
|
|
},
|
|
|
|
computed: {
|
2020-04-14 15:06:09 +00:00
|
|
|
...mapGetters(["user"])
|
2020-04-12 14:25:42 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2020-04-14 00:56:04 +00:00
|
|
|
book: {
|
|
|
|
title: "Taylor",
|
|
|
|
pages: 34
|
|
|
|
},
|
2020-04-12 14:25:42 +00:00
|
|
|
loading: true,
|
2020-04-13 00:37:58 +00:00
|
|
|
localStream: null,
|
|
|
|
remoteStream: null,
|
2020-04-14 15:06:09 +00:00
|
|
|
callManager: null,
|
|
|
|
isHost: false,
|
|
|
|
// currentPage: 0,
|
|
|
|
// totalPages: 34,
|
|
|
|
isMounted: false
|
2020-04-12 14:25:42 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
beforeCreate: () => {}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
2020-04-14 00:56:04 +00:00
|
|
|
|