Skip to content

Meetecho Janus Server, javascript wrapper library with all bells and whistles

Notifications You must be signed in to change notification settings

flutterjanus/JanusJs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c80a42f · Aug 1, 2023

History

71 Commits
Aug 1, 2023
Jul 20, 2023
Aug 1, 2023
Jul 20, 2023
Jul 20, 2023
Aug 1, 2023
Nov 10, 2022
May 10, 2022
Nov 10, 2022
Jul 20, 2023
Jul 20, 2023
Aug 1, 2023
Aug 1, 2023
Jul 20, 2023

Repository files navigation

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 })
})