Connecting to Photon Cloud from Node.js or .Net Core

Hi,

As much as I searched I couldn't find the JavaScript Client SDK to download, even though there were links on the Photon website.
Also I was wandering if anybody tried to use this SDK from Node.js. I'm assuming that it should work if you do some changes.
One more thing, I know that there is C# Client SDK for Photon, does anyone know if there are plans to make it work with .Net Core?

Thanks in advance guys.

Hope it makes sense what I've written.

Comments

  • vadimvadim admin
    Please find javascript realtime sdk: https://www.photonengine.com/sdks#html5-javascript

    No changes required to use Photon in node.js. Take a look at the test:

    // install:
    // npm install websocket
    // run:
    // node test.js
    
    // evaluating libs with vars in current context instead of 'require'
    var util = require('util')
    var vm = require("vm");
    var fs = require("fs");
    var load = function(path, context) {
      var data = fs.readFileSync(path);
      vm.runInThisContext(data, path);
    }
    
    var WebSocketClient = require("WebSocket").client
    
    // adapter for browser websocket
    WebSocket = function (uri) {
    	console.info("============", uri);
    	var self = this;
    	this.connection = null;
    	this.socket = new WebSocketClient();
    	this.socket.on('connectFailed', function (errorDescription) {
    		self.onerror(errorDescription);
    	})
    	this.socket.on('connect', function (connection) {
    		console.info("============");
    		self.connection = connection;
    
    		connection.on('error', function (error) {
    			console.info("WS error:", error);
    			self.onerror(error);
    		});
    
    		connection.on('close', function (ev) {
    			console.info("WS close:", ev);
    			self.onclose(ev);
    		});
    
    		connection.on('message', function (message) {
    //			console.info("WS message:", message);
    			if (message.type === 'utf8') {
    				self.onmessage({data:message.utf8Data});
    			}
    			return true;
    		});
    
    		self.onopen();
    	});
    	this.socket.connect(uri);
    }
    
    WebSocket.prototype.send = function (data) {
    	if(this.connection)
    		this.connection.sendUTF(data);
    }
    
    WebSocket.prototype.close = function () {
    	if(this.connection)
    		this.connection.close();
    }
    ///////
    
    load("./Photon-Javascript_SDK.js")
    
    var AppInfo = {
    //    MasterAddress: "app-eu.exitgamescloud.com:9090",
        MasterAddress: "localhost:9090",
        AppId: "<no-app-id>",
        AppVersion: "1.0",
    }
    
    var LBC = Photon.LoadBalancing.LoadBalancingClient;
    var lbc = new LBC(AppInfo.MasterAddress, AppInfo.AppId, AppInfo.AppVersion);
    
    lbc.onStateChange = function (state) {
    	// "namespace" import for static members shorter access	
    	console.info("State:", LBC.StateToName(state));
    	switch (state) {
    		case LBC.State.JoinedLobby:
    			this.createRoom("node-");
    			break;
    		case LBC.State.Joined:
    			break;
    		default:
    			break;
    	}
    };
    
    lbc.onEvent = function (code, data) {
    	console.info("Event:", code, data);
    	lbc.raiseEvent(code, data);
    }
    
    lbc.onOperationResponse = function (errorCode, errorMsg, code, content) {
    	console.info("op resp:", errorCode, errorMsg, code, content);
    	if (errorCode) {
    		switch (code) {
    //			case Photon.LoadBalancing.Constants.OperationCode.JoinRandomGame:
    	//			break;
    			default:
    				console.error("Operation Response error:", errorCode, errorMsg, code, content);
    				break;
    		}
    	}
    };
    
    lbc.connect()
    
    
  • Hi,

    Thank you for responding. I already made it work with Node.js. I used websocket module, but in general it's the same.

    Now I have a weird issue that I can't see rooms created from Unity3D, even though I'm using the same appID.

    Regards,
    Ivan
  • Hi @BigGiantHead.

    If you are using PUN on Unity3D, then be aware that PUN adds its own version to the app version and that not just the appID, but also the app version must match for clients to see each other.

    Please see http://forum.photonengine.com/discussion/comment/32107/#Comment_32107 for further information.

  • Hi,

    Oh man, didn't think that this could happen. I'll try it right away.
    Thanks.
  • Works... ;)
Sign In or Register to comment.