123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- import { Helpers } from '/core/helpers.js';
- class ReflectorClient {
- constructor() {
- console.log("reflector client constructor");
- this.helpers = new Helpers;
- this.socket = undefined;
- }
- connect(component_uri_or_json_or_object, path){
- function isSocketIO07() {
-
- return true
- }
- try {
- let objToRef = this.helpers.reduceSaveObject(path);
- var options = {
-
-
-
- query: {
- pathname: window.location.pathname.slice( 1,
- window.location.pathname.lastIndexOf("/") ),
- appRoot: "./public",
- path: JSON.stringify(objToRef)
- },
-
-
-
-
- secure: window.location.protocol === "https:",
-
-
-
- reconnection: false,
- upgrade: false,
- transports: ['websocket']
- };
- if ( isSocketIO07() ) {
-
- var host = window._app.reflectorHost;
-
- this.socket = io.connect( host, options );
-
- }
- } catch ( e ) {
-
-
-
-
-
-
-
-
-
-
-
-
- }
- if ( this.socket ) {
- this.socket.on('connect_error', function(err) {
- console.log(err);
- var errDiv = document.createElement("div");
- errDiv.innerHTML = "<div class='vwf-err' style='z-index: 10; position: absolute; top: 80px; right: 50px'>Connection error!" + err + "</div>";
- document.querySelector('body').appendChild(errDiv);
-
- });
- this.socket.on( "connect", function() {
- vwf.logger.infox( "-socket", "connected" );
- if ( isSocketIO07() ) {
- vwf.moniker_ = this.id;
- } else {
- vwf.moniker_ = this.transport.sessionid;
- }
- } );
-
-
-
-
-
-
-
- this.socket.on( "message", function( message ) {
-
- try {
- if ( isSocketIO07() ) {
- var fields = message;
- } else {
- var fields = JSON.parse( message );
- }
- fields.time = Number( fields.time );
-
- fields.origin = "reflector";
-
-
- if(_app.config.streamMsg) {
- vwf.virtualTime.streamAdapter.induce(fields);
- } else {
- vwf.virtualTime.insert( fields, !fields.action );
- }
-
-
-
-
-
-
-
-
-
-
-
- } catch ( e ) {
- vwf.logger.warn( fields.action, fields.node, fields.member, fields.parameters,
- "exception performing action:", vwf.utility.exceptionMessage( e ) );
- }
- } );
- this.socket.on( "disconnect", function() {
- vwf.logger.infox( "-socket", "disconnected" );
-
- window.location = window.location.href;
- } );
- this.socket.on( "error", function() {
-
- document.querySelector('body').innerHTML = "<div class='vwf-err'>WebSockets connections are currently being blocked. Please check your proxy server settings.</div>";
-
- } );
- if ( !isSocketIO07() ) {
-
- this.socket.connect();
- }
- } else if ( component_uri_or_json_or_object ) {
-
-
-
-
-
-
- this.createNode( component_uri_or_json_or_object, "application" );
- } else {
-
- }
- }
- }
- export { ReflectorClient }
|