Skip to content

Instantly share code, notes, and snippets.

var server = app.listen(process.env.PORT || 8082, function () {
var host = server.address().address
var port = server.address().port
console.log("PSTN app listening at %s:%s Port", host, port)
});
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
const puppeteer = require('puppeteer');
var urlencodedParser = bodyParser.urlencoded({ extended: true });
//When a stream is added to a channel
client.on('stream-added', function (evt) {
client.subscribe(evt.stream, handleFail);
});
//When you subscribe to a stream
client.on('stream-subscribed', function (evt) {
let stream = evt.stream;
addVideoStream(stream.getId());
stream.play('remote-container');
addCanvas(stream.getId());
// The client joins the channel
client.join(null,"test",null, (uid)=>{
// Stream object associated with your web cam is initialized
let localStream = AgoraRTC.createStream({
streamID: uid,
audio: true,
video: true,
screen: false
});
// Client Setup
// Defines a client for RTC
let client = AgoraRTC.createClient({
mode: 'live',
codec: "h264"
});
// Client Setup
// Defines a client for Real Time Communication
client.init("82ed46ddc986446a97ead5c10d1c23ee",() => console.log("AgoraRTC client initialized") ,handleFail);
//leave channel
leavebtn.addEventListener("click",()=>{
channel.leave();
flag = false;
})
})
//logout
outbtn.addEventListener("click",()=>{
client.logout().then(()=> {console.log("Client logged out.")}).catch(()=> {console.log("log out failed")});
})
//send messages
sendbtn.addEventListener("click", ()=>{
channel.sendMessage({ text: msg.value }).then(() => {
/* Your code for handling events, such as a channel message-send success. */
chatbox.innerHTML += "<div class='message_holder'><span class='chat user1'>"+ msg.value + "</span></div>";
console.log("Successfully sent message!");
}).catch(error => {
/* Your code for handling events, such as a channel message-send failure. */
console.log("Error sending message!");
joinbtn.addEventListener("click", ()=>{
//join a channel
const channel = client.createChannel(chid.value); //pass your channel ID
channel.join().then(() => {
/* Your code for handling the event of a join-channel success. */
console.log('Channel joined!');
}).catch(error => {
/* Your code for handling the event of a join-channel failure. */
console.log('Channel join failed.');
});
function logger()
{
//initialize client
const client = AgoraRTM.createInstance(appid.value);
//check connection state
client.on('ConnectionStateChange', (newState, reason) => {
console.log('on connection state changed to ' + newState + ' reason: ' + reason);
});
var client = AgoraRTC.createClient(config);
function myfunction(){
let handlefail = function(err){
console.log("Error: ", err);
};
let remotecontainer = document.getElementById("remote1");
let remote_container = document.getElementById("remote2");
let appid = document.getElementById("appid");