0.0.40 • Published 9 months ago

vue-peer v0.0.40

Weekly downloads
-
License
-
Repository
gitlab
Last release
9 months ago

Vue Peer

With this package, you can have video calls along with two or multi-person chat communication. You can easily bind and display your streams in any video element you want.

Installation

Install vue-peer with npm

  npm install vue-peer

Start backend:

    cd ./node_module/vue-peer/backend
    node server.js

usage in front:

    cd ./node_module/vue-peer/backend
    node server.js

Import plugin in application vue:

    import { createApp } from "vue";
    import App from "./App.vue";
    import { VuePeerPlugin } from "./main";

    const app = createApp(App);

    app.use(VuePeerPlugin); /// <=========== import plugin
    app.mount("#app");

Usage in script

    import { ref } from "vue";
    import {
        VuePeer,
        VuePeerStream,
        VuePeerSocketEvent,
        type MessageType,
    } from "./main";

    interface Metadata {
    user: string; // is require
    role: number; // your props
    }
    
    const localStream = ref();
    const peers = ref<any>([]);

    const srv = ref<VuePeer<Metadata, string>>(
        new VuePeer<Metadata, string>({
            socketUrl: "http://localhost:8282/",
            room: "test1",
            // user: getUser(),
            metadata: { role: 1, user: getUser()},
            showLogs: true,
        })
    );

    srv.value.on(VuePeerSocketEvent.LOCAL_VIDEO, (stream: MediaStream) => {
        localStream.value = stream;
    });

    srv.value.on(VuePeerSocketEvent.USER_JOINED, (sessions: VuePeerStream[]) => {
        peers.value = sessions.filter((f) => f.stream);
    });

Usage in html:

    <video v-src-object="localStream" muted autoplay></video>
    <hr />
    <!-- <div ref="videos"></div> -->
    <p>{{ peers.length }}</p>
    <template v-for="(item, index) in peers" :key="index">
        <p>{{ item.user }}</p>
        <video v-src-object="item.stream" muted autoplay></video>
    </template>

API Reference

Get all items

  vue-peer events 
Event nameParameterDescription
messageMessageType<T>When recieve data mesage
local_videoMediaStreamWhen ready your camera
user_joinedMediaStreamWhen join another user
error_in_peerErrorerror in peerjs
error_in_socketErrorerror in socket
error_in_navigatorErrorerror in navigator

Using enums for the above events:\

import { VuePeerSocketEvent} from "vue-peer"

Get item

  Apis
ParameterTypeDescription
sendMessageToto:string, userMsg:Tsend message to a user
sendMessageToAlluserMsg:Tsend message to all users
  • Here, T refers to the type that you provided for sending data. For example:\
const srv = ref<VuePeer<Metadata, string>>(  /// T = string
  new VuePeer<Metadata, string>({
      socketUrl: "http://localhost:8282/",
      room: "test1",
      // user: getUser(),
      metadata: { role: 1, user: getUser()},
      showLogs: true,
  })
);

srv.sendMessageToAll("hello world");

Authors

0.0.40

9 months ago

0.0.20

9 months ago

0.0.21

9 months ago

0.0.22

9 months ago

0.0.23

9 months ago

0.0.24

9 months ago

0.0.25

9 months ago

0.0.37

9 months ago

0.0.15

9 months ago

0.0.38

9 months ago

0.0.16

9 months ago

0.0.39

9 months ago

0.0.17

9 months ago

0.0.18

9 months ago

0.0.19

9 months ago

0.0.30

9 months ago

0.0.31

9 months ago

0.0.32

9 months ago

0.0.10

9 months ago

0.0.33

9 months ago

0.0.11

9 months ago

0.0.34

9 months ago

0.0.12

9 months ago

0.0.35

9 months ago

0.0.13

9 months ago

0.0.36

9 months ago

0.0.14

9 months ago

0.0.26

9 months ago

0.0.9

9 months ago

0.0.27

9 months ago

0.0.8

9 months ago

0.0.28

9 months ago

0.0.29

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago