import { User } from "./User"; import { Service } from "./Service"; import { IProtocol } from "../../protocol/invoke/IProtocol"; import { Invoke } from "../../protocol/invoke/Invoke"; import { WebClientDriver } from "../../protocol/communicator/client_driver/WebClientDriver"; /** * A driver of remote client. * * The {@link Client} is an abstract class representing and interacting with a remote client. It deals the network * communication with the remote client and shifts {@link Invoke} message to related {@link User} and {@link Service} * objects. * * Extends this {@link Client} class and override the {@link createService} method, a factory method creating a child * {@link Service} object. Note that, {@link Client} represents a remote client, not *an user*, a specific *web page* * or *service*. Do not define logics about user or account information. It must be declared in the parent * {@link User} class. Also, don't define processes of a specific a web page or service. Defines them in the child * {@link Service} class. * * * * * * @handbook [Templates - Cloud Service](https://github.com/samchon/framework/wiki/TypeScript-Templates-Cloud_Service) * @author Jeongho Nam */ export declare abstract class Client implements IProtocol { /** * @hidden */ private user_; /** * @hidden */ private no_; /** * @hidden */ private communicator_; /** * @hidden */ private service_; /** * Construct from parent {@link User} and communicator. * * @param user Parent {@link User} object. * @param driver Communicator with remote client. */ constructor(user: User, driver: WebClientDriver); /** * Default Destructor. * * This {@link destructor destructor()} method is called when the {@link Client} object is destructed and this * {@link Client} object is destructed when connection with the remote client is closed or this {@link Client} * object is {@link User.erase erased} from its parent {@link User} object. * * Note that, don't call this {@link destructor destructor()} method by yourself. It must be called automatically * by those *destruction* cases. Also, if your derived {@link Client} class has something to do on the * *destruction*, then overrides this {@link destructor destructor()} method and defines the something to do. * Overriding this {@link destructor destructor()}, don't forget to calling ```super.destructor();``` on tail. * * ```typescript * class MyUser extends service.Client * { * protected destructor(): void * { * // DO SOMETHING * this.do_something(); * * // CALL SUPER.DESTRUCTOR() ON TAIL. DON'T FORGET THIS * super.destructor(); * } * } * ``` */ protected destructor(): void; /** * Factory method creating {@link Service} object. * * @param path Requested path. * @return A newly created {@link Service} object or ```null```. */ protected abstract createService(path: string): Service; /** * Close connection. */ close(): void; /** * Get parent {@link User} object. * * Get the parent {@link User} object, who is groupping {@link Client} objects with same session id. * * @return The parent {@link User} object. */ getUser(): User; /** * Get child {@link Service} object. * * @return The child {@link Service} object. */ getService(): Service; /** * Get sequence number. * * Get sequence number of this {@link Client} object in the parent {@link User} object. This sequence number also * be a *key* in the parent {@link User} object, who extended the ```std.HashMap```. * * @return Sequence number. */ getNo(): number; /** * Change related {@link Service} object. * * @param path Requested, identifier path. */ protected changeService(path: string): void; /** * Change {@link Service} to another. * * @param service {@link service} object to newly assigned. */ protected changeService(service: Service): void; /** * Send an {@link Invoke} message. * * Sends an {@link Invoke} message to remote client. * * @param invoke An {@link Invoke} messgae to send to remote client. */ sendData(invoke: Invoke): void; /** * Handle a replied {@link Invoke} message. * * The default {@link Client.replyData Client.replyData()} shifts chain to its parent {@link User} and belonged * {@link Service} objects, by calling the the {@link User.replyData User.replyData()} and * {@link Service.replyData Service.replyData()} methods. * * Note that, {@link Client} represents a remote client, not *an user*, a specific *web page* or *service*. Do not * define logics about user or account information. It must be declared in the parent {@link User} class. Also, * don't define processes of a specific a web page or service. Defines them in the child {@link Service} class. * * ```typescript * class service.Client * { * public replyData(invoke: Invoke): void * { * // SHIFT TO PARENT USER * // THE PARENT USER ALSO MAY SHIFT TO ITS PARENT SERVER * this.getUser().replyData(invoke); * * // SHIFT TO BELOGED SERVICE * if (this.getService() != null) * this.getService().replyData(invoke); * } * } * * class MyClient extends service.Client * { * public replyData(invoke: Invoke): void * { * if (invoke.getListener() == "do_something_in_client_level") * this.do_something_in_client_level(); * else * super.replyData(invoke); * } * } * ``` * * @param invoke An {@link Invoke invoke} message to be handled in {@link Client} level. */ replyData(invoke: Invoke): void; }