I'm trying to use the phoenix-channels package on npm inside a node that I'm creating. I'm following the instructions. I've got it working fine in nodejs on its own.
const { Socket } = require('phoenix-channels')
let socket = new Socket("https://192.168.1.113:4445/socket")
socket.connect()
// Now that you are connected, you can join channels with a topic:
let channel = socket.channel("room:lobby", {})
channel.on("new_msg", payload => {
console.log(`${payload.body}`);
});
channel.join()
.receive("ok", resp => { console.log("Joined successfully", resp) })
.receive("error", resp => { console.log("Unable to join", resp) })
I've installed phoenix channels under the ~/.node-red
and I can see it:
I've added it to my settings.js file:
Now the instructions say I can use it by referencing the "phxModule" which is how I named it in the above settings.js file. My node does appear in the editor, but I get this error:
Now (and I'm not a javascript expert), what's wrong with the node code that I'm using? I thought I was supposed to, as per the instructions linked above, reference it using global.get
?
🦎tbrowne@nano:~/code/node-red-nodes/phoenix$ cat phoenix.js
module.exports = function(RED) {
function PhoenixNode(config) {
RED.nodes.createNode(this,config);
var node = this;
node.on('input', function(msg) {
msg.payload = msg.payload.toLowerCase();
node.send(msg);
});
const { Socket } = global.get('phxModule');
let socket = new Socket("https://192.168.1.113:4445/socket");
socket.connect();
let channel = socket.channel("room:lobby", {});
console.log("hello from phoenix node");
channel.on("new_msg", payload => {
node.send({"payload": payload});
});
channel.join()
.receive("ok", resp => { node.send({"payload": resp}) })
.receive("error", resp => { node.send({"payload": "Unable to join"}) })
}
RED.nodes.registerType("phoenix",PhoenixNode);
}
Why am I getting this TypeError: global.get is not a function
issue?