Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{
//
// Get a proxy to the default router and down-cast it to Glacier2.Router
// interface to ensure Glacier2 server is available.
//
console.log("This demo accepts any user-id / password combination.");
process.stdout.write("user id: ");
const id = await getline();
process.stdout.write("password: ");
const password = await getline();
const session = await router.createSession(id, password);
return Demo.ChatSessionPrx.uncheckedCast(session);
}
catch(ex)
{
if(ex instanceof Glacier2.PermissionDeniedException)
{
console.log("permission denied:\n" + ex.reason);
}
else if(ex instanceof Glacier2.CannotCreateSessionException)
{
console.log("cannot create session:\n" + ex.reason);
}
else
{
throw ex;
}
}
}
{
//
// Get a proxy to the default rotuer and down-cast it to Glacier2.Router
// interface to ensure Glacier2 server is available.
//
console.log("This demo accepts any user-id / password combination.");
process.stdout.write("user id: ");
const id = await getline();
process.stdout.write("password: ");
const password = await getline();
const session = await router.createSession(id, password);
return Demo.ChatSessionPrx.uncheckedCast(session);
}
catch(ex)
{
if(ex instanceof Glacier2.PermissionDeniedException)
{
console.log("permission denied:\n" + ex.reason);
}
else if(ex instanceof Glacier2.CannotCreateSessionException)
{
console.log("cannot create session:\n" + ex.reason);
}
else
{
throw ex;
}
}
}
//
// Create a session with the Glacier2 router.
//
const username = $("#username").val() as string;
const password = $("#password").val() as string;
const session = await router.createSession(username, password);
await run(router, ChatSessionPrx.uncheckedCast(session));
}
catch(ex)
{
console.log(ex.toString());
//
// Handle any exceptions that occurred during session creation.
//
if(ex instanceof Glacier2.PermissionDeniedException)
{
await setState(State.Disconnected, "permission denied:\n" + ex.reason);
}
else if(ex instanceof Glacier2.CannotCreateSessionException)
{
await setState(State.Disconnected, "cannot create session:\n" + ex.reason);
}
else if(ex instanceof Ice.ConnectFailedException)
{
await setState(State.Disconnected, "connection to server failed");
}
else
{
await setState(State.Disconnected, ex.toString());
}
}
//
// Get a proxy to the Glacier2 router using checkedCast to ensure
// the Glacier2 server is available.
//
const router = await Glacier2.RouterPrx.checkedCast(communicator.getDefaultRouter());
const username = $("#username").val() as string;
const password = $("#password").val() as string;
const session = await router.createSession(username, password);
await runWithSession(router, Demo.ChatSessionPrx.uncheckedCast(session));
}
catch(ex)
{
//
// Handle any exceptions that occurred during session creation.
//
if(ex instanceof Glacier2.PermissionDeniedException)
{
await error("permission denied:\n" + ex.reason);
}
else if(ex instanceof Glacier2.CannotCreateSessionException)
{
await error("cannot create session:\n" + ex.reason);
}
else if(ex instanceof Ice.ConnectFailedException)
{
await error("connection to server failed");
}
else
{
await error(ex.toString());
}
}