Javascript SDK- Node.js - Error(Photon not defined.)

Options
Javascript SDK- Node.js - Error(Photon not defined.)

Code snippet
var DemoLoadBalancing = /** @class */ (function (_super) {
return DemoLoadBalancing;
}(Photon.LoadBalancing.LoadBalancingClient)); <<<<<<<<<<<<<<<<<<<<<<< ERROR

Comments

  • vadim
    vadim mod
    edited June 2018
    Options
    How do you load Photon lib in node environment? It should be something like this:
    load("Photon-Javascript_SDK.js"); s

    Also, js sdk relies on browser's WebSocket object, So you need to implement its interface with websocket you use in nodejs. Like this:
    
    // adapter for browser websocket
    var wsClient = require("ws")
    WebSocket = function (uri) {
    	var self = this;
    	this.socket = new wsClient(uri, {protocol: "Json"});
    	this.socket.onopen = function () {
    		self.onopen();
    	};
    	this.socket.onerror = function (error) {
    		self.onerror(error);
    	};
    	this.socket.onclose = function (ev) {
    		self.onclose(ev);
    	};
    	this.socket.onmessage = function (message) {
    	if (message.type === 'message') {
    		self.onmessage({data:message.data});
    	}
    	return true;
    };