i am new at webrtc and rtsp, while trying to make a project on webrtc i came to a halt in my code and after weeks of online search adn usng chatgpt am still not able to resolve my problem. I want to stream my ipcamera to webrtc but the code is not working properly.am not above to start the stream.
the code is given below
const wrtc = require('wrtc');
const kurento = require('kurento-client');
const mqtt = require('mqtt');
const node_ffmpeg_stream = require('node-ffmpeg-stream');
const mqttonline_connection = require('../../mqttconnection/online_mqtt_connection');
const clientonline = mqttonline_connection.returnconnection();
const topiconline = mqttonline_connection.topic;
const RTSP_URL = 'rtsp://admin:[email protected]:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1';
async function startStreaming() {
try {
// Create Kurento client and pipeline
const kurentoClient = await kurento('ws://localhost:8888/kurento');
const pipeline = await kurentoClient.create('MediaPipeline');
// Create WebRTC endpoint
const webRtcEndpoint = await pipeline.create('WebRtcEndpoint');
webRtcEndpoint.setMaxVideoRecvBandwidth(10000000); // Set max bandwidth to 10 Mbps
// Create RTSP source and connect it to the WebRTC endpoint
const rtspEndpoint = await pipeline.create('RtspEndpoint', {uri: RTSP_URL});
rtspEndpoint.connect(webRtcEndpoint);
// Start streaming
webRtcEndpoint.gatherCandidates();
// Subscribe to ICE candidate events and send them via MQTT
webRtcEndpoint.on('OnIceCandidate', event => {
const candidate = kurento.getComplexType('IceCandidate')(event.candidate);
clientonline.publish('sdp', JSON.stringify(candidate));
});
// Subscribe to ICE connection state events and log them
webRtcEndpoint.on('IceConnectionStateChanged', event => {
console.log(`ICE connection state changed to ${event.state}`);
});
// Generate SDP offer and send it via MQTT
const sdpOffer = await webRtcEndpoint.generateOffer();
clientonline.publish('sdp', JSON.stringify(sdpOffer));
// Start the RTSP source
rtspEndpoint.play();
// Listen for incoming SDP answers via MQTT and set them on the WebRTC endpoint
clientonline.subscribe('answer');
clientonline.on('message', (topic, message) => {
if (topic === 'answer') {
const sdpAnswer = JSON.parse(message);
webRtcEndpoint.processAnswer(sdpAnswer);
}
});
// Listen for incoming ICE candidates via MQTT and add them to the WebRTC endpoint
clientonline.subscribe('candidate');
clientonline.on('message', (topic, message) => {
if (topic === 'candidate') {
const candidate = JSON.parse(message);
webRtcEndpoint.addIceCandidate(candidate);
}
});
// Handle errors
webRtcEndpoint.on('Error', error => {
console.error('WebRTC endpoint error:', error);
});
rtspEndpoint.on('Error', error => {
console.error('RTSP endpoint error:', error);
});
pipeline.on('Error', error => {
console.error('Pipeline error:', error);
});
} catch (error) {
console.error('Error starting streaming:', error);
}
}
startStreaming();
am getting the error as
Error starting streaming: SyntaxError: Unknown type '[object Object]'
at getConstructor (/home/user/Desktop/ghome/node_modules/kurento-client/lib/MediaObjectCreator.js:55:17)
at createConstructor (/home/user/Desktop/ghome/node_modules/kurento-client/lib/MediaObjectCreator.js:74:21)
at createMediaObject (/home/user/Desktop/ghome/node_modules/kurento-client/lib/MediaObjectCreator.js:140:23)
at MediaObjectCreator.create (/home/user/Desktop/ghome/node_modules/kurento-client/lib/MediaObjectCreator.js:263:12)
at startStreaming (/home/user/Desktop/ghome/extra/webrtc/mqttwrtc.js:25:41)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
type: {
params: 'rtsp://admin:[email protected]:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1',
type: 'RtspEndpoint'
}
}