import { Injectable } from '@angular/core'; import * as Cookies from 'js-cookie'; export class ChatSession { private _authToken: string; private _userid: string; private _me: any; // chat 用户信息 constructor() { this.init(); } init(token?: string, userId?: string, me?: any) { if (token !== undefined && userId !== undefined) { Cookies.set('rc_token', token); Cookies.set('rc_uid', userId); Cookies.set('chatMe', JSON.stringify(me)); this._authToken = token; this._userid = userId; this._me = me; } else { this._authToken = Cookies.get('rc_token'); this._userid = Cookies.get('rc_uid'); const meStr = Cookies.get('chatMe'); // tslint:disable-next-line: no-unused-expression meStr && (this._me = JSON.parse(meStr)); } } get authToken() { return this._authToken; } get userid(): string { return this._userid; } get me() { return this._me; } }