NPM package for SDK?

I have been looking to see if there is a NPM package (for use with things like nodejs. I have not found one.

Am I missing it?

If not, there REALLY aught to be an npm package...


  • Apart from that, I am having a hell of a time getting this to import into my main.ts file in nodejs...
    const photon = require('libraries/photonsdk/Photon-Javascript_SDK');
    // import { Exitgames } from 'libraries/photonsdk/Photon-Javascript_SDK';

    It says module not found for the import, but doing a standard require does not seem to work even a little.
  • I have started to make my own modifications to try and get it to work, but after adding export too all of the photon modules, I still get:

    Unless I am doing something very wrong, this seems to be not ready for a node environment.
  • vadimvadim mod
    edited January 2019
    nodejs is not officially supported.

    Below is a sample app running in nodejs.
    To load Photon lib from local storage, 'fs' and 'vm' package are used.
    Since Photon js sdk relies on browser's WebSocket object, you need to implement its interface with websocket you use in nodejs.
    const appID = "app-id"
    const util = require('util')
    const assert = require('assert')
    const vm = require("vm");
    const fs = require("fs");
    const load = function(path, context) {
      var data = fs.readFileSync(path);
      vm.runInThisContext(data, path);
    var wsClient = require("ws")
    WebSocket = function (uri) {
    	var self = this;
    	this.socket = new wsClient(uri, {protocol: "Json"});
    	this.socket.onopen = function () {
    	this.socket.onerror = function (error) {
    	this.socket.onclose = function (ev) {
    	this.socket.onmessage = function (message) {
    		if (message.type === 'message') {
    		return true;
    WebSocket.prototype.send = function (data) {
    WebSocket.prototype.close = function () {
    var LBC = Photon.LoadBalancing.LoadBalancingClient;
    var lbc = new LBC(Photon.ConnectionProtocol.Ws, appID, "1.0");
    function raiseEvent() {
    	console.log("Event Out");
    	lbc.raiseEvent(1, { message: "hello" }, { receivers: Photon.LoadBalancing.Constants.ReceiverGroup.All});
    lbc.onStateChange = function (state) {
    	// "namespace" import for static members shorter access"State:", LBC.StateToName(state));
    	switch (state) {
    		case LBC.State.JoinedLobby:
    			this.joinRoom("node-", {createIfNotExists: true});
    		case LBC.State.Joined:
    //			lbc.disconnect();
    		case LBC.State.Disconnected:
    lbc.onEvent = function (code, data) {"Event In:", code, data);
    lbc.onOperationResponse = function (errorCode, errorMsg, code, content) {
    //"op resp:", errorCode, errorMsg, code, content);
    	if (errorCode) {
    		switch (code) {
    //			case Photon.LoadBalancing.Constants.OperationCode.JoinRandomGame:
    	//			break;
    				console.error("Operation Response error:", errorCode, errorMsg, code, content);
  • edited January 2019
    I see. I could be wrong, but won't electron complain if I use websockets in the main thread?

    Really they aught to just make an NPM package... I looked into it, but it looks like it would require a bit of restructuring.
  • edited January 2019
    Thanks for the info. Running through it now to get it working.
  • So not sure how this is being strung together...
    When I try to run, I still get
    ReferenceError: WebSocket is not defined
        at NameServerPeer.PhotonPeer.connect (lib/photonsdk/Photon-Javascript_SDK.js:442:36)
        at LoadBalancingClient.connectToNameServer (lib/photonsdk/Photon-Javascript_SDK.js:1778:41)
        at LoadBalancingClient.connectToRegionMaster (lib/photonsdk/Photon-Javascript_SDK.js:2252:31)
        at PhotonManager.start (C:\Repositories\ArcMages\arcmages-client\src\main\photonManager.js:102:13)
        at Object.<anonymous> (C:\Repositories\ArcMages\arcmages-client\main.js:19:8)
        at Object.<anonymous> (C:\Repositories\ArcMages\arcmages-client\main.js:121:3)
        at Module._compile (internal/modules/cjs/loader.js:693:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:704:10)
        at Module.load (internal/modules/cjs/loader.js:602:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:541:12)
    even though I am using your example.
  • vadimvadim mod
    edited January 2019
    WebSocket is defined as a global var in line #14 of code snippet i posted above.
    Does this code run alone work for you? Don't forget to set appID.
  • Played with it more, turns out that I needed to do quite a bit of rewriting of the SDK for it to work right - nodejs does not have a concept of a DOM, so Websocket was failing to run properly.
Sign In or Register to comment.