App.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. call.on("stream", remoteStream => {
  18. console.log("call started");
  19. this.$store.state.remoteStreams.push(remoteStream);
  20. });
  21. call.active = false;
  22. this.$store.state.receiveCalls.push(call);
  23. });
  24. this.$store.state.peer.on("connection", connection => {
  25. connection.on("open", () => {
  26. console.log("connection openned");
  27. });
  28. connection.on("data", (data) => {
  29. if(data=='PAIR_CLOSED'){
  30. this.$store.commit('close',connection.peer)
  31. }
  32. });
  33. connection.on("close", () => {
  34. console.log("connection closed");
  35. });
  36. this.$store.state.receiveConnections.push(connection);
  37. });
  38. },
  39. mounted: async function() {
  40. let getUserMedia =
  41. navigator.mediaDevices.getUserMedia ||
  42. navigator.mediaDevices.webkitGetUserMedia ||
  43. navigator.mediaDevices.mozGetUserMedia;
  44. this.$store.state.myLocalVideoStream = await getUserMedia({
  45. video: true,
  46. audio: false
  47. });
  48. }
  49. };
  50. </script>
  51. <style>
  52. </style>