방송 송출
const config = {
credential: {
key: ‘key’,
serviceId: ‘serviceid’
},
view: {
remote: ‘#remoteVideo’,
local: ‘#localVideo’
},
media: {
video: {
maxBandwidth: ‘1500’,
codec: ‘vp8’
},
audio: true
},
rtc: {
audioType: ‘music’
}
};
const listener = {
onCreate(chid) {
console.log(`EVENT FIRED: onCreate: ${chid}`);
livecastSave(chid);
},
onConnect(chid) {
console.log(`EVENT FIRED: onConnect: ${chid}`);
},
onComplete() {
console.log('EVENT FIRED: onComplete');
},
onDisconnectChannel() {
// is called when other peer hang up.
remon.close();
isConnected = false;
},
onJoin(chid) {
console.log('EVENT FIRED: onJoin');
},
onClose() {
console.log('EVENT FIRED: onClose');
remon.close();
},
onError(error) {
console.log(`EVENT FIRED: onError: ${error}`);
},
onStat(result) {
console.log(`EVENT FIRED: onStat: ${result}`);
}
};
const remon = new Remon({config, listener});
function start() {
if (isConnected) {
isConnected = false;
remon.close();
} else {
isConnected = true;
var myChannelId = getRandomId();
remon.createCast(myChannelId);
}
}
function getRandomId() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 5; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return Date.now() + "_" + text;
}
시청
var listener = {
onCreate(chid) {
console.log(EVENT FIRED: onCreate: ${chid}
);
},
onConnect(chid) {
console.log(EVENT FIRED: onConnect: ${chid}
);
},
onComplete() {
console.log(‘EVENT FIRED: onComplete’);
},
onDisconnectChannel() {
// is called when other peer hang up.
remon.close();
isConnected = false;
},
onJoin(chid) {
console.log(‘EVENT FIRED: onJoin’);
},
onClose() {
console.log(‘EVENT FIRED: onClose’);
remon.close();
},
onError(error) {
console.log(EVENT FIRED: onError: ${error}
);
},
onStat(result) {
console.log(EVENT FIRED: onStat: ${result}
);
}
};
var config = {
credential: {
key: ‘key’,
serviceId: ‘serviceid’
},
view: {
remote: ‘#remoteVideo’
}
};
const remon = new Remon({ config: config, listener });
$(function() {
remon.joinCast('1593498136182_CWoXQ');
});
방송 송출 및 시청 코드는 위와 같이 되어 있습니다.