import { Promise } from 'es6-promise' ; import { TALKER_CONTENT_TYPE } from './constants' ; import Talker from './index' ; abstract class Message { protected readonly type : string = TALKER_CONTENT_TYPE ; constructor ( protected readonly talker , public readonly namespace , public readonly data , public readonly responseToId = null ) { } } export interface JSONableMessage { readonly namespace ? : string ; readonly data ? : Stringifyable ; readonly id ? : number ; readonly responseToId ? : number ; readonly type : string ; readonly handshake ? : boolean ; readonly handshakeConfirmation ? : boolean ; } export interface Stringifyable { [ index ] : string | number | Stringifyable | Stringifyable [ ] | boolean | null | undefined ; } export class OutgoingMessage extends Message { public readonly id : number = this . talker . nextId ( ) ; param talker param namespace param data param responseToId constructor ( protected readonly talker , public readonly namespace , public readonly data , public readonly responseToId = null ) { super ( talker , namespace , data , responseToId ) ; } toJSON ( ) { const { id , responseToId , namespace , data , type } = this ; return { id , responseToId : responseToId || undefined , namespace , data , type , } ; } } export class IncomingMessage extends Message { constructor ( protected readonly talker , public readonly namespace = '' , public readonly data = { } , public readonly id = 0 ) { super ( talker , namespace , data ) ; } /**
     * Please note that this response message will use the same timeout as Talker#send.
     */ respond ( data ) { return this . talker . send ( this . namespace , data , this . id ) ; } }