Giter Club home page Giter Club logo

janusjs's Introduction

JanusJs

Fully functional reactive and promisified wrapper around native janusjs

Install

npm install typed_janus_js

Build for distribution

./build_janus.sh
npm run build

Usage Examples

// video call screensharing example code
// you can see complete code in action under vanila-js example
import { JanusJs, JanusVideoCallPlugin } from 'typed_janus_js'
import { config } from './conf'

const janus = new JanusJs(config.meetecho)
await janus.init({ debug: false })
const session = await janus.createSession()
const publisher = await session.attach(JanusVideoCallPlugin)
publisher.onMessage.subscribe((msg) => {
    if (msg.jsep) {
        publisher.handleRemoteJsep({ jsep: msg.jsep })
    }
})
const remoteVideo = document.getElementById('remotevideo')
let remoteStream = new MediaStream()
console.log(remoteVideo)
publisher.onRemoteTrack.subscribe(({ mid, on, track }) => {
    if (on) {
        remoteStream.addTrack(track)
    } else {
        remoteStream.removeTrack(track)
    }
})
remoteVideo.srcObject = remoteStream

const username = prompt('Enter your name: ')
await publisher.register(username)
const user = prompt('Enter user you want to call: ')
await publisher.call(
    user,
    await publisher.createOffer({
        tracks: [
            { type: 'audio', capture: true, recv: true },
            { type: 'screen', capture: true, recv: true },
        ],
    })
)
// video room example code
// you can see complete code in action under vanila-js example
import { JanusJs, JanusVideoRoomPlugin } from 'typed_janus_js'
import { config } from './conf'
const janus = new JanusJs(config.meetecho)
await janus.init({ debug: false })
const session = await janus.createSession()
const publisher = await session.attach(JanusVideoRoomPlugin)
const subscriber = await session.attach(JanusVideoRoomPlugin)

const username = prompt('Enter your name: ')
await publisher.joinRoomAsPublisher(1234, { display: username })
await publisher.publishAsPublisher(
    await publisher.createOffer({ media: { audio: true, video: true } }),
    { bitrate: 2000000 }
)

publisher.onMessage.subscribe(async ({ jsep, message }) => {
    const result = message?.result
    const event = result?.event
    console.log(message, jsep)
    if (jsep) {
        publisher.handleRemoteJsep({ jsep })
    }
})
// console.log(await publisher.listParticipants(1234));
subscriber.onMessage.subscribe(async ({ jsep, message }) => {
    if (jsep) {
        publisher.handleRemoteJsep({ jsep })
    }
})

subscriber.onRemoteTrack.subscribe((track, on, mid) => {
    console.log({ track, on, mid })
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.