Uncaught TypeError: Cannot read properties of undefined (reading 'emit') - socket.io

I am trying to use socket.emit() in my frontend JavaScript file. I have linked the api and when I go to the websites console this error pops up:
login.js:12 Uncaught TypeError: Cannot read properties of undefined (reading 'emit')
at login (login.js:12:10)
here is my code:
var socket;
var login;
var user = document.getElementById("user");
var pass = document.getElementById("pass");
function onload(){
socket = io();
}
login = function(){
socket.emit("login", user.value, pass.value);
pass.value = "";
user.value = "";}
I dont know what to try can someone help

Related

Error: Expected an object as the target scope

2 days ago, my web-extensions program have no problem.
But today, same program make below error.
=====
Error: Expected an object as the target scope
Schemas.jsm:2641:15
let obj = Cu.createObjectIn(context.cloneScope);
=====
enviroment:
Firefox Developer Edition
60.0b2(64bit)
=====
This is java script for popup.
The point that the error is occur is below:
chrome.extension;
chrome; < no error
chrome.extension; < error
It is changed not to be able to access chrome.extension
on a window.unload event in a popup.
Now, I've resolved this error.
// error
window.unload = function() {
var ex = chrome.extension; //error : Expected an object as the target scope
}
// fixed
function access_extention() {
var ex = chrome.extension;
}
window.onblur = access_extention;
window.onbeforeunload = access_extention;

hyperledger composer deploy example code fails

Currently working with the latest releases of the hyperledger development environment and am working through the admin services. The example code for admin -> deploy is documented as:
// Deploy a Business Network Definition
var adminConnection = new AdminConnection();
var businessNetworkDefinition = BusinessNetworkDefinition.fromArchive(myArchive);
return adminConnection.deploy(businessNetworkDefinition)
.then(function(){
// Business network definition deployed
})
.catch(function(error){
// Add optional error handling here.
});
In the code as provided, the second line fails as BusinessNetworkDefinition is not a part of the composer-admin node module. I have two options for creating a BusinessNetworkDefinition, one is to use composer-client. This fails with the following message: TypeError: composerClient.BusinessNetworkDefinition is not a constructor
The code used for this attempt is summarized here:
'use strict';
var fs = require('fs');
var path = require('path');
var composer = require('composer-admin');
var composerClient = require('composer-client');
var composerCommon = require('composer-common');
var businessNetworkDefinition = new composerClient.BusinessNetworkDefinition();
The other option is to use composer-common, which fails with the following message: TypeError: businessNetworkDefinition.fromArchive is not a function
The code used for this attempt is:
var fs = require('fs');
var path = require('path');
var composer = require('composer-admin');
var composerClient = require('composer-client');
var composerCommon = require('composer-common');
var net_identifier = "zerotoblockchain-network#0.1.6";
var net_description = "Z2B network";
var net_package = require("../../../../network/package.json");
var net_readme = "../../../../README.md";
var businessNetworkDefinition = new composerCommon.BusinessNetworkDefinition(net_identifier, net_description, net_package, net_readme);
var archive = businessNetworkDefinition.fromArchive(req.body.myArchive);
where req.body.myArchive is the name of the archive file to be used in the fromArchive method. Inspecting the BusinessNetworkDefinition created via the new command shows the following:
object property: modelManager
object property: aclManager
object property: queryManager
object property: scriptManager
object property: introspector
object property: factory
object property: serializer
object property: metadata
So, two questions:
One: What was created with the new command and
Two: How do I correctly create a BusinessNetworkDefinition object which as a fromArchive() function in it?
The example code in the hyperledger composer documentation is flawed. Following is code which will successfully execute a business network deploy.
(1) Required definitions:
let fs = require('fs');
let path = require('path');
let composerAdmin = require('composer-admin');
const BusinessNetworkDefinition = require('composer-common').BusinessNetworkDefinition;
The following is written as an exportable, routable routine in nodejs and has been tested through from client (browser). Client passes in name of network to deploy. File layout is:
root/network/dist/network-archive-file.bna
(2) Read in the archive file and create an admin connection:
/**
* Deploys a new BusinessNetworkDefinition to the Hyperledger Fabric. The connection must be connected for this method to succeed.
* #param {express.req} req - the inbound request object from the client
* req.body.myArchive: _string - string name of object
* req.body.deployOptions: _object - string name of object
* #param {express.res} res - the outbound response object for communicating back to client
* #param {express.next} next - an express service to enable post processing prior to responding to the client
* returns composerAdmin.connection - either an error or a connection object
* #function
*/
exports.deploy = function(req, res, next) {
let newFile = path.join(path.dirname(require.main.filename),'network/dist',req.body.myArchive);
let archiveFile = fs.readFileSync(newFile);
let adminConnection = new composerAdmin.AdminConnection();
(3) Invoke the (asynchronous) fromArchive function and then deploy the result of the fromArchive invocation.
return BusinessNetworkDefinition.fromArchive(archiveFile)
.then(function(archive) {
adminConnection.connect(config.composer.connectionProfile, config.composer.adminID, config.composer.adminPW)
.then(function(){
adminConnection.deploy(archive)
(4). Respond to the (browser based) request:
.then(function(){
console.log('business network deploy successful: ');
res.send({deploy: 'succeeded'});
})
.catch(function(error){
console.log('business network deploy failed: ',error);
res.send({deploy: error});
});
... (5) and for anyone copying all the code, a few closing braces:
});
});
};

Issue deleting Google Shared Contact

I've been able to successfully add a contact via the API but I can't delete contacts that I've created.
https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/shared-contacts
function deletecontact()
{
SharedContactsApp.setOAuth2AccessToken(getSharedContactsService().getAccessToken ());
var contacts = SharedContactsApp.getContactById('5c8b05ab8c9f68c6');
SharedContactsApp.deleteContact('5c8b05ab8c9f68c6');
}
I get the following error message:
TypeError: Cannot call method "getElements" of undefined. (line 200, file "Code", project "SharedContactsApp")
How to remove this error?
Additionally...
I've tried to set a Job Title using the code below but get the following error:
ReferenceError:"profile" is not defined. (line 142, file "Code")
function changeJobTitle2()
{
SharedContactsApp.setOAuth2AccessToken(getSharedContactsService().getAccessToken ());
var contact = SharedContactsApp.getContactById('82f05968956d66f');
profile.setJobTitle('Google Apps Expert');
}
I figured it out.
function hailmary()
{
SharedContactsApp.setOAuth2AccessToken(getSharedContactsService().getAccessToken());
var contact = SharedContactsApp.getContactById('82f05968956d66f');
SharedContactsApp.deleteContact(contact)
}

Codeigniter Flexi Auth library loads sometimes

I am working on the log in system for a site using Flexi Auth in Codeigniter V 2.1.4. I am trying to pass a user's log in status to a menu that changes dynamically depending whether a user is logged in or not. This is the code i am using:
public function create_page($pgName = 'home')
{
$this->config->load('tera_site', TRUE);
$this->load->library('flexi_auth_lite');
// Cunstruct Page data
$data['pgName'] = $pgName;
if ($this->session->userdata('admin') === FALSE){$data['admin'] = 0;}else{$data['admin'] = $this->session->userdata('admin');}
$data['siteTitle'] = $this->config->item('siteTitle','tera_site');
// This is the line the Error is thrown from:
$data['loggedIn'] = $this->flexi_auth_lite->is_logged_in();
$data['header'] = $this->load->view('include/header', $data, TRUE);
$data['pages'] = $this->config->item('pages','tera_site');
$data['footer'] = $this->load->view('include/footer', False, TRUE);
$data['sideBar'] = $this->load->view('include/side_bar_view', $data, TRUE);
$this->load->model('page_model');
$data['pgData'] = $this->page_model->getPage($pgName);
// load the Catcha Library
$this->load->library('captcha_my');
if($data['pgData']['Captcha'] = 1) {
$data['Captcha'] = $this->captcha_my->createCaptcha();
} else if ($this->session->userdata('captchaCheck') == true) {
$data['Captcha'] = $this->captcha_my->createCaptcha();
}
return $data;
This is the error:
Severity: Notice
Message: Undefined property: Main::$flexi_auth_lite
Fatal error: Call to a member function is_logged_in() on a non-object
The code worked at one time, but even when it did it threw the same error when i called the function is_admen() from flexi_auth. Flexi_auth.php and Flexi_auth_lite.php are in application/libraries directory.
if you look into the demo files, there is a controller 'auth_lite.php'
it says
// IMPORTANT! This global must be defined BEFORE the flexi auth library is loaded!
// It is used as a global that is accessible via both models and both libraries, without it, flexi auth will not work.
$this->auth = new stdClass;
// Load 'lite' flexi auth library by default.
// If preferable, functions from this library can be referenced using 'flexi_auth' as done below.
// This prevents needing to reference 'flexi_auth_lite' in some files, and 'flexi_auth' in others, everything can be referenced by 'flexi_auth'.
$this->load->library('flexi_auth_lite', FALSE, 'flexi_auth');

Passing a path on a function (Uncaught Error: Syntax error, unrecognized expression)

today I'm struggling with an "Uncaught Error: Syntax error, unrecognized expression:".
I would pass a path to a function that preload images but when I'm going to call it, I get the error:
preLoader('img/realizzazione-impianti-fotovoltaici-header.png');
This is the function:
var preLoader = function (arrayOfImages){
$(arrayOfImages).each(function(){
//$('<img/>')[0].src = this;
var cacheImage = document.createElement('img');
cacheImage.src = this;
cacheImg.push(cacheImage);
});//each
}//preLoader

Resources