I am having issues with connecting to my Prosody server using the stanza +esm cdn dist.
The websocket connection works with a standard WebSocket object connection in the HTML file (see first script) however the second script using Stanza cdn errors.
The wss connection works fine with stanza package in a node script. I just can’t get it to work with cdn ESM link in a standard, standalone HTML file. Any assistance would be appreciated.
Connection error: TypeError: Cannot read properties of undefined (reading ‘call’)
at new ti (_stream_duplex.js:58:14) at new Oh (websocket.js:9:9) at Kh.connect (Client.js:300:31) at index.html:22:16
HTML file:
<html>
<head>
<title>Stanza.js +ESM</title>
</head>
<body>
<script>
// this works
const socket = new WebSocket('wss://test.com:5281/xmpp-websocket', 'xmpp');
socket.onopen = () => console.log('Connected!');
socket.onerror = (err) => console.error('WebSocket Error:', err);
</script>
<script type="module">
// this errors
import * as stanza from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'
const client = stanza.createClient({
jid: '[email protected]',
password: 'password',
resource: 'web',
transports: {
websocket: 'wss://test.com:5281/xmpp-websocket'
}
});
console.log(client);
console.log(client.config);
client.on('session:started', () => {
console.log('Stanza Connected');
client.getRoster();
client.sendPresence();
});
client.on('chat', msg => {
console.log('Received chat:', msg);
});
client.connect().catch(err => {
console.error('Connection error:', err);
});
client.on('connected', () => console.log('Connected to XMPP server'));
function sendMessage() {
client.sendMessage({
to: '[email protected]',
body: 'Hello from Stanza WEB!',
type: 'chat'
});
}
</script>
</body>
</html>```