So I am a newbie at Meteor and in Bigbluebutton 2.4 I have to make a simple message that goes to all the users in a meeting. even without the meeting criteria I still cant get them on my frontend In the code I can subscribe to the ptzmessage and I see it in Meteor.connection._subscriptions list on the browser
componentDidMount() {
const { onVideoItemMount, cameraId } = this.props;
console.log("subscribing")
Meteor.subscribe('ptzmessage').ready()
this.subscription = Meteor.subscribe('ptzmessage');
// Retry after 5 seconds if not ready
this.retryTimeout = setTimeout(() => {
if (!this.subscription.ready()) {
console.log("Retrying subscription...");
this.subscription = Meteor.subscribe('ptzmessage');
}
console.log(" subscription completed...");
}, 5000);
this.tracker = Tracker.autorun(() => {
console.log("Fetching messages...");
const messages = PtzMessages.find({}).fetch();
this.setState({ messages });
console.log('Received Messages:', messages);
});
this is the Api file in import/api/ptzmessage and imported in the frontend and the backend
import { Mongo } from 'meteor/mongo';
// Define PtzMessages collection
export const PtzMessages = new Mongo.Collection('ptzmessages');
if (Meteor.isServer) {
PtzMessages._ensureIndex({ meetingId: 1 });
}
this is the server code when I press button send message it adds it in the collection
import { Meteor } from 'meteor/meteor';
import { PtzMessages } from '../index.js';
Meteor.publish('ptzmessage', function () {
console.log(`Client ${this.connection.id} subscribed to ptzmessage`);
return PtzMessages.find();
});
Meteor.methods({
sendPtzMessage(message) {
console.log("#####################################################################################api hit")
PtzMessages.insert({ text: message, createdAt: new Date() }, (err, res) => {
if (err) {
console.error("Insert Error:", err);
} else {
console.log("Message inserted successfully:", res);
}
});
}
});
infact in the frontend Meteor.connection._mongo_livedata_collections.ptzmessages.find().fetch();
get me the latest messages but I dont get them real time on the Tracker.
Stuff like this is done in other code that works what am I doing wrong?