The _chatDataProducer isn’t being created, preventing messages from being sent, despite attempts to trigger it within sendChatMessage and after transport connects. More testing is needed.
i can not see message that i send in client side even in demo code
when i send message it call sendChatMessage and in that function i check that this._chatDataProducer is created or not i can see its state is ‘open’ but i receive error log and enableChatDataProducer() is fire but throw an error :
my browser log :
mediasoup-demo:RoomClient sendChatMessage() [text:“Hiii”] +10s
RoomClient.js:1772 this._chatDataProducer in sendChatMessage DataProducer {_events: {…}, _eventsCount: 1, _maxListeners: Infinity, _closed: false, _observer: EnhancedEventEmitter, …}
RoomClient.js:1772 this._chatDataProducer type object
RoomClient.js:1773 DataChannel readyState: open
RoomClient.js:1788 mediasoup-client:DataProducer send() +17s
RoomClient.js:1789 message has been sent: Hiii
mediasoup-demo:RoomClient chat DataProducer “bufferedamountlow” event +8ms
my function that i print log :
async sendChatMessage(text) {
logger.debug('sendChatMessage() \[text:"%s"\]', text);
// Check if chatDataProducer exists and is ready
if (!this.\_chatDataProducer) {
logger.log('sendChatMessage() | No chat DataProducer available');
return;
}
console.log('this.\_chatDataProducer in sendChatMessage', this.\_chatDataProducer);
console.log('this.\_chatDataProducer type', typeof this.\_chatDataProducer);
console.log('DataChannel readyState:', this.\_chatDataProducer.\_dataChannel?.readyState);
// Check if the data channel is open
if (this.\_chatDataProducer.\_dataChannel?.readyState !== 'open') {
logger.log('sendChatMessage() | DataChannel not open, state:',
this.\_chatDataProducer.\_dataChannel?.readyState);
return;
}
try {
// send() doesn't return anything, it's a void method
this.\_chatDataProducer.send(text);
console.log('message has been sent:', text);
} catch (log) {
logger.log('chat DataProducer.send() failed:%o', error);
store.dispatch(requestActions.notify({
type: 'error',
text: \`Failed to send message: ${error.message}\`
}));
}
}
async enableChatDataProducer() {
logger.debug('enableChatDataProducer()');
if (!this.\_useDataChannel)
return;
// Check if already exists
if (this.\_chatDataProducer) {
logger.debug('Chat DataProducer already exists');
return;
}
try {
// Create chat DataProducer.
this.\_chatDataProducer = await this.\_sendTransport.produceData({
ordered: false,
maxRetransmits: 1,
label: 'chat',
priority: 'medium',
appData: { info: 'my-chat-DataProducer' }
});
console.log('Chat DataProducer created:', this.\_chatDataProducer.id);
// Wait for the data channel to be open
await new Promise((resolve, reject) => {
const dataChannel = this.\_chatDataProducer.\_dataChannel;
if (dataChannel.readyState === 'open') {
resolve();
return;
}
const onOpen = () => {
dataChannel.removeEventListener('open', onOpen);
resolve();
};
const onError = (error) => {
dataChannel.removeEventListener('error', onError);
reject(error);
};
dataChannel.addEventListener('open', onOpen);
dataChannel.addEventListener('error', onError);
// Timeout after 5 seconds
setTimeout(() => reject(new Error('DataChannel open timeout')), 5000);
});
// ... rest of your existing code for event listeners and store dispatch
} catch (error) {
logger.log('enableChatDataProducer() | failed:%o', error);
// Reset the producer on error
this.\_chatDataProducer = null;
// store.dispatch(requestActions.notify({
// type: 'error',
// text: \`Error enabling chat DataProducer: ${error.message}\`
// }));
throw error;
}
}