You have
function onMessage (message) {
console.log (“Message received:” + message)
}
as described here - https://backendless.com/docs/js/pubsub_subscription_introduction.html ?
Can you run in debug mode and see where the error occurs?
You have
function onMessage (message) {
console.log (“Message received:” + message)
}
as described here - https://backendless.com/docs/js/pubsub_subscription_introduction.html ?
Can you run in debug mode and see where the error occurs?
Even if you will delete the message listener, you will get the error, which is thrown by socket.io, while trying to handshake.
One of the SDK dependencies is backendless-rt-client, which is establishing socket connection with Backendless.
In backendless-rt-client check src/socket.js, the error is logged (not thrown) from there, line 98.
Hi @vladimir-upirov,
I’m having the exact same issue with the SDK version 5.2.13.
I notice a GET request being repeteadly invoked ( /rt/lookup ) which doesn’t return error code but 200 and a response like “https://rt-app#.backendless.com:50010”.
Publish API seems to work properly though.
I just checked it, and looks like there are not any issue, everything works well
add a simple code into “./server/index.js” file :
const Backendless = require('backendless');
Backendless.initApp('YOUR_APP_ID', 'YOUR_JS_API_KEY');
const channel = Backendless.Messaging.subscribe('default');
channel.addMessageListener(message => console.log('message:', message));
run it: node server
publish a new message, and in terminal output the new messages appear
could you please provide steps to reproduce and env when do you run your code
Regards, Vlad
Sure, I’ll try to be as specific as possible. My project is based on Angular 7 + Ionic 4.
The MessagingService provides a function to post and subscribe to channels.
import {Injectable} from ‘@angular/core’;
import * as Backendless from ‘backendless’;
@Injectable({
providedIn: 'root'
})
export class MessagingService {
public getConversationChannel(channelId): Backendless.ChannelClass {
return Backendless.Messaging.subscribe(channelId);
}
public postMessage(message) {
return Backendless.Messaging.publish('default', message);
}
}
At my page/component layer, only 2 buttons are displayed: Join (subscribes to a channel [NOT WORKING]) and Post (posts into the channel).
<ion-header>
<ion-toolbar>
<ion-title>Chat</ion-title>
<ion-buttons slot="start">
<ion-back-button defaultHref="/"></ion-back-button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content>
<button (click)="initChannel()">JOIN</button>
<button (click)="postMessage()">POST</button>
</ion-content>
The TypeScript functions:
private conversationChannel;
initChannel() {
this.conversationChannel = this.messagingService.getConversationChannel('default');
console.log(this.conversationChannel);
this.conversationChannel.addMessageListener((message) => {
console.log('RT Received: ', message);
});
}
postMessage() {
this.messagingService.postMessage('hello world!');
}
Check what’s happening (I’ll attach to this reply some screenshots [I tried but not granted due to “new user”. Sorry about that]):
I assume I’m missing something, but cannot mind what.
Thanks in advance!
actually, the topic title says that issue is in NodeJS env, but you’ve got a problem in Ionic env, so it’s a little different problem
anyways, let’s try to figure out what’s going on here
could you please archive your project (or create another one with minimal code) for reproduce the problem and send it to us support@backendless.com, also please attach instruction how to install/run the app and we will take a look at the issue
and also you can try to enable debug mode, for that just add the next line right after Backendless.initApp(…)
Backendless.debugMode = true
maybe, there will be some helpful info
Regards, Vlad
I assumed that Backendless JS SDK worked the same for NodeJS, Angular, etc.
I’ll make a small project including what you request and be in touch!
Thanks
Hi @vladimir-upirov,
I sent an email to support@backendless.com on July 18th but I haven’t received any response yet. Is there any update regarding my ticket?
Thanks.
Hello @Enrique_Diaz
Sorry for the late response,
I’ve found the problem, the issue is with Angular and SocketIO library which is used in our JS-SDK
the latest comment looks like fixes the problem, just add the following line in …/src/polyfills.ts file
(window as any).global = window;
Regards, Vlad
Hi,
Thank you so much for the response. I applied the suggested workaround and it does work now as expected.
Regards!
Hi there,
I have the same issue in an Angular app where I am not receiving any messages.
The message is published (can see it in the backendless dashboard) but the message listener never receives it. There is no console error and I’ve tried the polyfill fix but no luck.
Any ideas or help would be great.
Thanks,
Iain
Angular: 9.0.7
backendless: 5.8.8
Hello @Iain_Todd
try to add the following code right after Backendless.initApp
to check the JS-SDK able to connect to RT-Server
Backendless.RT.addConnectErrorEventListener((...args) => console.log('addConnectErrorEventListener', ...args));
Backendless.RT.addConnectEventListener((...args) => console.log('addConnectEventListener', ...args));
Backendless.RT.addDisconnectEventListener((...args) => console.log('addDisconnectEventListener', ...args));
Backendless.RT.addReconnectAttemptEventListener((...args) => console.log('addReconnectAttemptEventListener', ...args));
Regards, Vlad
Thanks for the responsive reply @vladimir-upirov,
I’m seeing this in the console now…
addConnectErrorEventListener Cannot read property 'Blob' of undefined
addReconnectAttemptEventListener 1 400
addConnectErrorEventListener io is not a function
addReconnectAttemptEventListener 2 400
addConnectErrorEventListener io is not a function
addReconnectAttemptEventListener 3 400
addConnectErrorEventListener io is not a function
etc...
we will investigate it and notify you about any result asap
Hey @Iain_Todd
I just fixed it for Stencil, perhaps this also fixes your problem, could you please install the JS-SDK with test
tag
npm i backendless@test -S
Regards, Vlad
Thanks @vladimir-upirov, that has solved the issue.
Can confirm v5.8.8-test.2
is working for Angular v8.2.14
and v9.1.1