App.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <div>
  3. <navbar />
  4. <router-view />
  5. </div>
  6. </template>
  7. <script>
  8. export default {
  9. data: function () {
  10. return {};
  11. },
  12. beforeCreate: function () {
  13. this.$store.state.peer.on("open", (id) => {
  14. this.$store.state.id = id;
  15. });
  16. this.$store.state.peer.on("call", (call) => {
  17. if (
  18. this.$store.state.receiveCalls.findIndex((c) => c.peer == call.peer) !=
  19. -1
  20. )
  21. return false;
  22. call.on("close", () => {
  23. console.log("call closed");
  24. });
  25. call.on("stream", (remoteStream) => {
  26. console.log("call started");
  27. this.$store.state.remoteStreams.push(remoteStream);
  28. });
  29. this.$store.state.receiveCalls.push(call);
  30. });
  31. this.$store.state.peer.on("connection", (connection) => {
  32. connection.on("open", () => {
  33. console.log("connection openned");
  34. });
  35. connection.on("data", () => {
  36. console.log("connection sended data");
  37. });
  38. connection.on("close", () => {
  39. console.log("connection closed");
  40. });
  41. this.$store.state.receiveConnections.push(connection);
  42. });
  43. },
  44. mounted: async function () {
  45. let getUserMedia =
  46. navigator.mediaDevices.getUserMedia ||
  47. navigator.mediaDevices.webkitGetUserMedia ||
  48. navigator.mediaDevices.mozGetUserMedia;
  49. this.$store.state.myLocalVideoStream = await getUserMedia({
  50. video: true,
  51. audio: false,
  52. });
  53. },
  54. };
  55. </script>
  56. <style>
  57. </style>