123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932 |
- <template>
- <div class="chat-index">
- <!--左边选项-->
- <ul class="chat-menu">
- <li class="self">
- <UserImg :info="userInfo" class="avatar"/>
- </li>
- <li :class="{active:chatTap=='dialog'}" @click="[chatTap='dialog',chatTam='dialog']">
- <Icon type="md-text" />
- <em v-if="unreadTotal > 0" class="chat-num">{{unreadTotal > 99 ? '99+' : unreadTotal}}</em>
- </li>
- <li :class="{active:chatTap=='team'}" @click="[chatTap='team',chatTam='team']">
- <Icon type="md-person" />
- </li>
- </ul>
- <!--对话列表-->
- <ul class="chat-user" :class="{'chat-flex':chatTap=='dialog','chat-tam':chatTam=='dialog'}">
- <li class="sreach">
- <Input :placeholder="$L('搜索')" prefix="ios-search" v-model="dialogSearch"/>
- </li>
- <li ref="dialogLists" class="lists">
- <ul>
- <li v-for="(dialog, index) in dialogListsS"
- :key="index"
- :class="{active:dialog.username==dialogTarget.username}"
- :data-id="dialog.id"
- @click="openDialog(dialog)">
- <UserImg :info="dialog" class="avatar"/>
- <div class="user-msg-box">
- <div class="user-msg-title">
- <span><UserView :username="dialog.username" placement="right" @on-result="userViewResult(dialog, $event)"/></span>
- <em>{{formatCDate(dialog.lastdate)}}</em>
- </div>
- <div class="user-msg-text">{{dialog.lasttext}}</div>
- </div>
- <em v-if="dialog.unread > 0" class="user-msg-num">{{dialog.unread}}</em>
- </li>
- <li v-if="dialogNoDataText==$L('数据加载中.....')" class="chat-none"><w-loading/></li>
- <li v-else-if="dialogLists.length == 0" class="chat-none">{{dialogNoDataText}}</li>
- </ul>
- </li>
- </ul>
- <!--联系人列表-->
- <ul class="chat-team" :class="{'chat-flex':chatTap=='team','chat-tam':chatTam=='team'}">
- <li class="sreach">
- <Input :placeholder="$L('搜索')" prefix="ios-search" v-model="teamSearch"/>
- </li>
- <li class="lists">
- <ul>
- <li v-for="(lists, key) in teamLists" :key="key" v-if="teamListsS(lists).length > 0">
- <div class="team-label">{{key}}</div>
- <ul>
- <li v-for="(item, index) in teamListsS(lists)" :key="index" @click="openDialog(item, true)">
- <UserImg :info="item" class="avatar"/>
- <div class="team-username">{{item.nickname||item.username}}</div>
- </li>
- </ul>
- </li>
- <li v-if="teamNoDataText==$L('数据加载中.....')" class="chat-none"><w-loading/></li>
- <li v-else-if="Object.keys(teamLists).length == 0" class="chat-none">{{teamNoDataText}}</li>
- <li v-if="teamHasMorePages" class="chat-more" @click="getTeamLists(true)">{{$L('加载更多...')}}</li>
- </ul>
- </li>
- </ul>
- <!--对话窗口-->
- <div class="chat-message"
- :style="{display:(chatTap=='dialog'&&dialogTarget.username)?'block':'none'}"
- @drop.prevent="messagePasteDrag($event, 'drag')"
- @dragover.prevent="messageDragOver(true)"
- @dragleave.prevent="messageDragOver(false)">
- <div class="manage-title">
- <UserView :username="dialogTarget.username"/>
- <Dropdown class="manage-title-right" placement="bottom-end" trigger="click" @on-click="dialogDropdown" transfer>
- <Icon type="ios-more"/>
- <DropdownMenu slot="list">
- <DropdownItem name="delete">{{$L('删除对话')}}</DropdownItem>
- <DropdownItem name="clear">{{$L('清除聊天记录')}}</DropdownItem>
- </DropdownMenu>
- </Dropdown>
- </div>
- <ScrollerY ref="manageLists" class="manage-lists" @on-scroll="messageListsScroll">
- <div ref="manageBody" class="manage-body">
- <div v-if="messageHasMorePages" class="manage-more" @click="getDialogMessage(true)">{{$L('加载更多...')}}</div>
- <div v-if="messageNoDataText==$L('数据加载中.....')" class="manage-more"><w-loading/></div>
- <div v-else-if="messageNoDataText" class="manage-more">{{messageNoDataText}}</div>
- <chat-message v-for="(info, index) in messageLists" :key="index" :info="info"></chat-message>
- </div>
- <div class="manage-lists-message-new" v-if="messageNew > 0" @click="messageBottomGo(true)">{{$L('有%条新消息', messageNew)}}</div>
- </ScrollerY>
- <div class="manage-send" @click="clickDialog(dialogTarget.username)">
- <textarea ref="textarea" class="manage-input" maxlength="20000" v-model="messageText" :placeholder="$L('请输入要发送的消息')" @keydown="messageSend($event)" @paste="messagePasteDrag"></textarea>
- </div>
- <div class="manage-quick">
- <emoji-picker @emoji="messageInsertText" :search="messageEmojiSearch">
- <div slot="emoji-invoker" slot-scope="{ events: { click: clickEvent } }" @click.stop="clickEvent">
- <Tooltip :content="$L('表情')" placement="top">
- <Icon class="quick-item" type="ios-happy-outline" />
- </Tooltip>
- </div>
- <div slot="emoji-picker" slot-scope="{ emojis, insert, display }">
- <div class="emoji-box">
- <Input class="emoji-input" :placeholder="$L('搜索')" v-model="messageEmojiSearch" prefix="ios-search"/>
- <div>
- <div v-for="(emojiGroup, category) in emojis" :key="category">
- <h5>{{ category }}</h5>
- <div class="emojis">
- <span v-for="(emoji, emojiName) in emojiGroup" :key="emojiName" @click="insert(emoji)" :title="emojiName">{{ emoji }}</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- </emoji-picker>
- <Tooltip :content="$L('文件/图片')" placement="top">
- <Icon class="quick-item" type="ios-photos-outline" @click="$refs.messageUpload.handleClick()"/>
- <ChatLoad
- ref="messageUpload"
- class="message-upload"
- :target="dialogTarget.username"
- @on-progress="messageFile('progress', $event)"
- @on-success="messageFile('success', $event)"
- @on-error="messageFile('error', $event)"/>
- </Tooltip>
- <template v-if="systemConfig.callav=='open'">
- <Tooltip :content="$L('语音聊天')" placement="top">
- <Icon class="quick-item voicecam" type="ios-call-outline" @click="videoConnect(null, false)"/>
- </Tooltip>
- <Tooltip :content="$L('视频聊天')" placement="top">
- <Icon class="quick-item videocam" type="ios-videocam-outline" @click="videoConnect(null, true)"/>
- </Tooltip>
- </template>
- </div>
- <div v-if="dialogDragOver" class="manage-drag-over">
- <div class="manage-drag-text">{{$L('拖动到这里发送给 %', dialogTarget.nickname || dialogTarget.username)}}</div>
- </div>
- </div>
- <!--语音、视频通话-->
- <div class="chat-video" :style="{display:(videoUserName)?'block':'none',backgroundImage:'url(' + videoUserImg +')'}">
- <div v-if="videoChat" class="video-opacity">{{$L('正在视频通话...')}}</div>
- <div v-else class="video-opacity">{{$L('正在语音通话...')}}</div>
- <video ref="remoteVideo" class="video-active" autoplay></video>
- <video ref="localVideo" class="video-mini" autoplay muted="true"></video>
- <div class="video-close"><Icon type="ios-close-circle-outline" @click="videoClose(videoUserName)"/></div>
- </div>
- <!--提示音-->
- <audio class="chat-audio" ref="messageAudio" preload="none">
- <source :src="messageAudio + 'message.mp3'" type="audio/mpeg">
- <source :src="messageAudio + 'message.wav'" type="audio/wav">
- </audio>
- <audio class="chat-audio" ref="callAudio" preload="none">
- <source :src="messageAudio + 'call.mp3'" type="audio/mpeg">
- <source :src="messageAudio + 'call.wav'" type="audio/wav">
- </audio>
- </div>
- </template>
- <style lang="scss">
- .chat-notice-box {
- display: flex;
- align-items: flex-start;
- cursor: pointer;
- .chat-notice-userimg {
- width: 42px;
- height: 42px;
- font-size: 20px;
- line-height: 42px;
- border-radius: 4px;
- }
- .ivu-notice-with-desc {
- flex: 1;
- padding: 0 12px;
- }
- .chat-notice-btn-box {
- margin-top: 8px;
- margin-bottom: -4px;
- .ivu-btn {
- margin-right: 12px;
- font-size: 12px;
- min-width: 42px;
- }
- }
- .ivu-notice-desc {
- font-size: 13px;
- word-break: break-all;
- line-height: 1.3;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- overflow: hidden;
- -webkit-box-orient: vertical;
- }
- .chat-user {
- .user-msg-title {
- .user-view-inline {
- .user-view-name {
- max-width: 100%;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- }
- }
- }
- .chat-message {
- .manage-title {
- .user-view-inline {
- max-width: 70%;
- .user-view-name {
- max-width: 100%;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- }
- }
- }
- }
- </style>
- <style lang="scss" scoped>
- .chat-index {
- display: flex;
- flex-direction: row;
- align-items: flex-start;
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- .chat-none {
- height: auto;
- color: #666666;
- padding: 22px 8px;
- text-align: center;
- justify-content: center;
- margin: 0 !important;
- &:before {
- display: none;
- }
- }
- .chat-more {
- color: #666666;
- padding: 18px 0;
- text-align: center;
- cursor: pointer;
- margin: 0 !important;
- &:hover {
- color: #444444;
- }
- }
- .chat-menu {
- background-color: rgba(28, 29, 31, 0.92);
- width: 68px;
- height: 100%;
- padding-top: 20px;
- li {
- position: relative;
- padding: 12px 0;
- text-align: center;
- font-size: 28px;
- color: #919193;
- background-color: transparent;
- cursor: pointer;
- &.self {
- cursor: default;
- .avatar {
- width: 36px;
- height: 36px;
- font-size: 20px;
- border-radius: 3px;
- }
- }
- &.active {
- color: #ffffff;
- background-color: rgba(255, 255, 255, 0.06);
- }
- &:hover {
- > i {
- transform: scale(1.1);
- }
- }
- > i {
- transition: all 0.2s;
- }
- .chat-num {
- position: absolute;
- top: 50%;
- left: 50%;
- height: auto;
- line-height: normal;
- color: #ffffff;
- background-color: #ff0000;
- text-align: center;
- border-radius: 10px;
- padding: 1px 5px;
- font-size: 12px;
- transform: scale(0.9) translate(5px, -20px);
- }
- }
- }
- .chat-user {
- display: none;
- flex-direction: column;
- width: 248px;
- height: 100%;
- background-color: #ffffff;
- border-right: 1px solid #ededed;
- > li {
- position: relative;
- &.sreach {
- display: flex;
- flex-direction: row;
- align-items: center;
- height: 62px;
- margin: 0;
- padding: 0 12px;
- position: relative;
- cursor: pointer;
- &:before {
- content: "";
- position: absolute;
- left: 0;
- right: 0;
- bottom: 0;
- height: 1px;
- background-color: rgba(0, 0, 0, 0.06);
- }
- }
- &.lists {
- flex: 1;
- overflow: auto;
- transform: translateZ(0);
- > ul {
- > li {
- display: flex;
- flex-direction: row;
- align-items: center;
- height: 70px;
- padding: 0 12px;
- position: relative;
- cursor: pointer;
- &:before {
- content: "";
- position: absolute;
- left: 0;
- right: 0;
- bottom: 0;
- height: 1px;
- background-color: rgba(0, 0, 0, 0.06);
- }
- &.active {
- &:before {
- top: 0;
- height: 100%;
- }
- }
- .avatar {
- width: 42px;
- height: 42px;
- font-size: 20px;
- border-radius: 4px;
- }
- .user-msg-box {
- flex: 1;
- display: flex;
- flex-direction: column;
- padding-left: 12px;
- .user-msg-title {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- line-height: 24px;
- span {
- flex: 1;
- max-width: 130px;
- color: #333333;
- font-size: 14px;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- em {
- color: #999999;
- font-size: 12px;
- }
- }
- .user-msg-text {
- max-width: 170px;
- color: #999999;
- font-size: 12px;
- line-height: 24px;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- }
- }
- }
- }
- .user-msg-num {
- position: absolute;
- top: 6px;
- left: 44px;
- height: auto;
- line-height: normal;
- color: #ffffff;
- background-color: #ff0000;
- text-align: center;
- border-radius: 10px;
- padding: 1px 5px;
- font-size: 12px;
- transform: scale(0.9);
- border: 1px solid #ffffff;
- }
- }
- }
- .chat-team {
- display: none;
- flex-direction: column;
- width: 248px;
- height: 100%;
- background-color: #ffffff;
- border-right: 1px solid #ededed;
- > li {
- position: relative;
- &.sreach {
- display: flex;
- flex-direction: row;
- align-items: center;
- height: 62px;
- margin: 0;
- padding: 0 12px;
- position: relative;
- cursor: pointer;
- &:before {
- content: "";
- position: absolute;
- left: 0;
- right: 0;
- bottom: 0;
- height: 1px;
- background-color: rgba(0, 0, 0, 0.06);
- }
- }
- &.lists {
- flex: 1;
- overflow: auto;
- transform: translateZ(0);
- > ul {
- > li {
- margin-left: 24px;
- position: relative;
- .team-label {
- padding-left: 4px;
- margin-top: 6px;
- margin-bottom: 6px;
- height: 34px;
- line-height: 34px;
- border-bottom: 1px solid #efefef;
- }
- > ul {
- > li {
- display: flex;
- flex-direction: row;
- align-items: center;
- height: 52px;
- cursor: pointer;
- .avatar {
- width: 30px;
- height: 30px;
- font-size: 16px;
- border-radius: 3px;
- }
- .team-username {
- padding: 0 12px;
- font-size: 14px;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- }
- }
- }
- }
- }
- }
- }
- .chat-message {
- flex: 1;
- height: 100%;
- background-color: #F3F3F3;
- position: relative;
- .manage-title {
- position: absolute;
- top: 0;
- left: 0;
- z-index: 3;
- width: 100%;
- height: 62px;
- padding: 0 20px;
- line-height: 62px;
- font-size: 16px;
- font-weight: 500;
- text-align: left;
- background: #ffffff;
- border-bottom: 1px solid #ededed;
- .manage-title-right {
- position: absolute;
- top: 0;
- right: 0;
- z-index: 9;
- width: 62px;
- height: 62px;
- line-height: 62px;
- text-align: center;
- font-size: 22px;
- color: #242424;
- }
- }
- .manage-lists {
- position: absolute;
- left: 0;
- top: 62px;
- z-index: 1;
- bottom: 120px;
- width: 100%;
- overflow: auto;
- padding: 8px 0;
- background-color: #E8EBF2;
- .manage-more {
- color: #666666;
- padding: 8px 0;
- text-align: center;
- cursor: pointer;
- &:hover {
- color: #444444;
- }
- }
- .manage-lists-message-new {
- position: fixed;
- bottom: 130px;
- right: 20px;
- color: #ffffff;
- background-color: rgba(0, 0, 0, 0.6);
- padding: 6px 12px;
- border-radius: 16px;
- font-size: 12px;
- cursor: pointer;
- }
- }
- .manage-send {
- position: absolute;
- left: 0;
- bottom: 0;
- z-index: 2;
- display: flex;
- width: 100%;
- height: 120px;
- background-color: #ffffff;
- border-top: 1px solid #e4e4e4;
- .manage-input,.manage-input:focus {
- flex: 1;
- -webkit-appearance: none;
- font-size: 14px;
- box-sizing: border-box;
- padding: 0;
- margin: 38px 10px 6px;
- border: 0;
- line-height: 20px;
- box-shadow: none;
- resize:none;
- outline: 0;
- }
- .manage-join,
- .manage-spin {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background: #ffffff;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- }
- .manage-quick {
- position: absolute;
- z-index: 2;
- left: 0;
- right: 0;
- bottom: 79px;
- padding: 8px 0;
- display: flex;
- align-items: center;
- height: 40px;
- .quick-item {
- color: #444444;
- font-size: 24px;
- margin: 0 7px;
- &.voicecam {
- font-size: 26px;
- height: 24px;
- line-height: 24px;
- }
- &.videocam {
- color: #666666;
- font-size: 30px;
- height: 24px;
- line-height: 24px;
- }
- }
- .emoji-box {
- position: absolute;
- left: 0;
- bottom: 40px;
- max-height: 320px;
- width: 100%;
- overflow: auto;
- background-color: #ffffff;
- padding: 12px;
- border-bottom: 1px solid #efefef;
- .emoji-input {
- margin: 6px 0;
- }
- h5 {
- padding: 0;
- margin: 8px 0 0 0;
- color: #b1b1b1;
- text-transform: uppercase;
- font-size: 14px;
- cursor: default;
- font-weight: normal;
- }
- .emojis {
- display: flex;
- flex-wrap: wrap;
- justify-content: space-between;
- &:after {
- content: "";
- flex: auto;
- }
- span {
- padding: 2px 4px;
- cursor: pointer;
- font-size: 22px;
- &:hover {
- background: #ececec;
- cursor: pointer;
- }
- }
- }
- }
- .message-upload {
- display: none;
- width: 0;
- height: 0;
- overflow: hidden;
- }
- }
- .manage-drag-over {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 3;
- background-color: rgba(255, 255, 255, 0.78);
- display: flex;
- align-items: center;
- justify-content: center;
- &:before {
- content: "";
- position: absolute;
- top: 16px;
- left: 16px;
- right: 16px;
- bottom: 16px;
- border: 2px dashed #7b7b7b;
- border-radius: 12px;
- }
- .manage-drag-text {
- padding: 12px;
- font-size: 18px;
- color: #666666;
- }
- }
- @media screen and (max-width: 768px) {
- .manage-lists {
- bottom: 96px;
- .manage-lists-message-new {
- bottom: 106px;
- }
- }
- .manage-send {
- height: 96px;
- }
- .manage-quick {
- bottom: 54px;
- .quick-item {
- font-size: 24px;
- margin-right: 8px;
- }
- }
- }
- }
- .chat-video {
- position: fixed;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background-color: #000000;
- background-size: cover;
- background-position: center center;
- background-repeat: no-repeat;
- z-index: 9;
- &:before {
- content: "";
- position: absolute;
- left: -10%;
- right: -10%;
- top: -10%;
- bottom: -10%;
- background: inherit;
- filter: blur(25px);
- z-index: 1;
- }
- &:after {
- content: "";
- position: absolute;
- left: -10%;
- right: -10%;
- top: -10%;
- bottom: -10%;
- background: rgba(0, 0, 0, 0.82);
- z-index: 2;
- }
- .video-opacity {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- font-size: 26px;
- color: #aaaaaa;
- padding: 24px;
- z-index: 3;
- animation:opacity 2s infinite alternate ;
- @keyframes opacity {
- 0% {
- opacity: 0.1;
- }
- 100% {
- opacity: 1;
- }
- }
- }
- .video-mini,
- .video-active {
- position: absolute;
- max-width: 640px;
- max-height: 100%;
- object-fit: cover;
- transition: opacity 1s;
- }
- .video-active {
- top: 0;
- left: 50%;
- width: 100%;
- height: 100%;
- transform: rotateY(180deg) translateX(50%);
- z-index: 4;
- }
- .video-mini {
- top: 0;
- right: 0;
- width: 260px;
- height: 180px;
- transform: scale(-1, 1);
- z-index: 5;
- }
- .video-close {
- position: absolute;
- max-width: 720px;
- bottom: 18px;
- left: 50%;
- width: 100%;
- transform: translateX(-50%);
- display: flex;
- align-items: center;
- justify-content: center;
- z-index: 6;
- > i {
- font-weight: 600;
- font-size: 46px;
- color: #ffffff;
- cursor: pointer;
- &:hover {
- color: #ff0000;
- }
- }
- }
- }
- .chat-audio {
- width: 0;
- height: 0;
- display: none;
- }
- .chat-flex {
- display: flex;
- }
- @media (max-width: 768px) {
- .chat-menu {
- width: 50px;
- li {
- padding: 6px 0;
- margin: 6px 0;
- font-size: 24px;
- &.self {
- .avatar {
- width: 32px;
- height: 32px;
- font-size: 18px;
- }
- }
- }
- }
- .chat-user,
- .chat-team {
- display: none;
- position: absolute;
- left: 50px;
- right: 0;
- z-index: 2;
- width: auto;
- > li {
- &.sreach {
- height: 54px;
- }
- }
- &.chat-tam {
- display: flex;
- }
- }
- .chat-message {
- .manage-title {
- height: 54px;
- line-height: 54px;
- .manage-title-right {
- width: 54px;
- height: 54px;
- line-height: 54px;
- }
- }
- .manage-lists {
- top: 54px;
- }
- }
- }
- }
- </style>
- <script>
- import EmojiPicker from 'vue-emoji-picker'
- import DrawerTabsContainer from "../DrawerTabsContainer";
- import ScrollerY from "../../../_components/ScrollerY";
- import ChatMessage from "./Message";
- import ImgUpload from "../ImgUpload";
- import ChatLoad from "./Upload";
- export default {
- name: 'ChatIndex',
- components: {ChatLoad, ImgUpload, ChatMessage, EmojiPicker, ScrollerY, DrawerTabsContainer},
- props: {
- value: {
- default: 0
- },
- openWindow: {
- type: Boolean,
- default: false
- },
- },
- data () {
- return {
- loadIng: 0,
- openAlready: false,
- userInfo: {},
- chatTap: 'dialog',
- chatTam: 'dialog',
- messageAudio: window.location.origin + '/audio/',
- dialogSearch: '',
- dialogTarget: {},
- dialogLists: [],
- dialogNoDataText: '',
- dialogDragOver: false,
- teamSearch: '',
- teamReady: false,
- teamLists: {},
- teamNoDataText: '',
- teamCurrentPage: 1,
- teamHasMorePages: false,
- autoBottom: true,
- messageNew: 0,
- messageText: '',
- messageLists: [],
- messageNoDataText: '',
- messageEmojiSearch: '',
- messageCurrentPage: 1,
- messageHasMorePages: false,
- unreadTotal: 0,
- videoUserName: '', //视频对话用户名
- videoUserImg: '', //视频对话用户头像
- videoStartTime: 0, //视频开始时间
- videoInitiator: false, //是否发起人
- videoChat: false, //是否视频通话(否则音频通话)
- videoRtc: null, //视频Rtc
- videoLocalStream: null, //视频流
- systemConfig: $A.jsonParse($A.storage("systemSetting"), {
- callav: '',
- }),
- }
- },
- created() {
- this.dialogNoDataText = this.$L("数据加载中.....");
- this.teamNoDataText = this.$L("数据加载中.....");
- this.messageNoDataText = this.$L("数据加载中.....");
- },
- mounted() {
- let resCall = () => {
- if ($A.getToken() === false) {
- return;
- }
- $A.WSOB.sendTo('unread', (res) => {
- if (res.status === 1) {
- this.unreadTotal = $A.runNum(res.message);
- } else {
- this.unreadTotal = 0;
- }
- });
- this.getDialogLists();
- this.messageBottomAuto();
- };
- this.userInfo = $A.getUserInfo((res, isLogin) => {
- if (this.userInfo.id != res.id) {
- this.userInfo = res;
- resCall();
- } else {
- this.userInfo = res;
- }
- }, false);
- resCall();
- this.getSetting();
- //
- window.onChatOpenUserName = (username) => {
- this.$emit("on-open-notice", username);
- this.clickDialog(username, true);
- }
- //
- if (this.openWindow) {
- $A.WSOB.connection();
- if (!this.openAlready) {
- this.openAlready = true;
- this.getDialogLists();
- }
- }
- //
- $A.WSOB.setOnMsgListener("chat/index", (msgDetail) => {
- if (msgDetail.username == $A.getUserName()) {
- return;
- }
- switch (msgDetail.messageType) {
- case 'open':
- if (this.openWindow) {
- this.getDialogLists();
- this.getDialogMessage();
- } else {
- this.openAlready = false;
- this.dialogTarget = {};
- }
- break;
- case 'info':
- if (msgDetail.body.type == 'video') {
- this.videoMessage(msgDetail)
- }
- break;
- case 'user':
- let body = msgDetail.body;
- if (['taskA'].indexOf(body.type) !== -1) {
- return;
- }
- let lasttext = $A.WSOB.getMsgDesc(body);
- this.unreadTotal += 1;
- this.addDialog({
- username: body.username,
- userimg: body.userimg,
- lasttext: lasttext,
- lastdate: body.indate,
- unread: body.unread
- });
- if (msgDetail.username == this.dialogTarget.username) {
- this.addMessageData(body, true);
- }
- if (!this.openWindow) {
- this.$Notice.close('chat-notice');
- this.$Notice.open({
- name: 'chat-notice',
- duration: 0,
- render: h => {
- return h('div', {
- class: 'chat-notice-box',
- on: {
- click: () => {
- this.$Notice.close('chat-notice');
- this.$emit("on-open-notice", body.username);
- this.clickDialog(body.username);
- }
- }
- }, [
- h('UserImg', {class: 'chat-notice-userimg', props: {info: body}}),
- h('div', {class: 'ivu-notice-with-desc'}, [
- h('div', {class: 'ivu-notice-title'}, [
- h('UserView', {props: {username: body.username}})
- ]),
- h('div', {class: 'ivu-notice-desc'}, lasttext)
- ])
- ])
- }
- });
- }
- try {
- this.$refs.messageAudio.play();
- } catch (e) {
- }
- break;
- }
- });
- $A.WSOB.setOnSpecialListener("chat/index", (simpleMsg) => {
- this.addDialog({
- username: simpleMsg.target,
- lasttext: $A.WSOB.getMsgDesc(simpleMsg.body),
- lastdate: simpleMsg.body.indate
- });
- if (simpleMsg.target == this.dialogTarget.username) {
- this.addMessageData(simpleMsg.body, true);
- }
- });
- },
- watch: {
- chatTap(val) {
- if (val === 'team' && this.teamReady == false) {
- this.teamReady = true;
- this.getTeamLists();
- } else if (val === 'dialog') {
- this.autoBottom = true;
- this.$nextTick(() => {
- this.messageBottomGo();
- });
- }
- },
- openWindow(val) {
- if (val) {
- $A.WSOB.connection();
- if (!this.openAlready) {
- this.openAlready = true;
- this.getDialogLists();
- }
- }
- //
- let tmpRand = $A.randomString(8);
- this.__openWindowRand = tmpRand;
- setTimeout(() => {
- if (this.__openWindowRand !== tmpRand) {
- return;
- }
- $A.WSOB.sendTo('unread', (res) => {
- if (res.status === 1) {
- this.unreadTotal = $A.runNum(res.message);
- } else {
- this.unreadTotal = 0;
- }
- });
- }, 500);
- },
- unreadTotal(val) {
- if (val < 0) {
- this.unreadTotal = 0;
- return;
- }
- this.$emit('input', val);
- },
- dialogTarget: {
- handler: function () {
- let username = this.dialogTarget.username;
- if (username === this.__dialogTargetUsername) {
- return;
- }
- this.__dialogTargetUsername = username;
- this.getDialogMessage();
- },
- deep: true
- }
- },
- computed: {
- dialogListsS() {
- return this.dialogLists.filter(item => {
- return (item.username + "").indexOf(this.dialogSearch) > -1 || (item.lasttext + "").indexOf(this.dialogSearch) > -1 || (item.nickname + "").indexOf(this.dialogSearch) > -1
- });
- },
- teamListsS() {
- return function (lists) {
- return lists.filter(item => {
- return (item.username + "").indexOf(this.teamSearch) > -1 || (item.nickname + "").indexOf(this.teamSearch) > -1
- });
- }
- }
- },
- methods: {
- getSetting() {
- $A.apiAjax({
- url: 'system/setting',
- error: () => {
- $A.storage("systemSetting", {});
- },
- success: (res) => {
- if (res.ret === 1) {
- this.systemConfig = res.data;
- this.systemConfig.callav = this.systemConfig.callav || 'open';
- $A.storage("systemSetting", this.systemConfig);
- } else {
- $A.storage("systemSetting", {});
- }
- }
- });
- },
- formatCDate(v) {
- let string = '';
- if ($A.runNum(v) > 0) {
- if ($A.formatDate('Ymd') === $A.formatDate('Ymd', v)) {
- string = $A.formatDate('H:i', v)
- } else if ($A.formatDate('Y') === $A.formatDate('Y', v)) {
- string = $A.formatDate('m-d', v)
- } else {
- string = $A.formatDate('Y-m-d', v)
- }
- }
- return string || '';
- },
- getDialogLists() {
- if (!this.openAlready) {
- return;
- }
- this.loadIng++;
- this.dialogNoDataText = this.$L("数据加载中.....");
- $A.apiAjax({
- url: 'chat/dialog/lists',
- complete: () => {
- this.loadIng--;
- },
- error: () => {
- this.dialogNoDataText = this.$L("数据加载失败!");
- },
- success: (res) => {
- if (res.ret === 1) {
- this.dialogLists = res.data;
- this.dialogNoDataText = this.$L("没有相关的数据");
- this.scrollToActive();
- } else {
- this.dialogLists = [];
- this.dialogNoDataText = res.msg
- }
- }
- });
- },
- getDialogMessage(isNextPage = false) {
- let username = this.dialogTarget.username;
- if (!username) {
- return;
- }
- //
- if (isNextPage === true) {
- if (!this.messageHasMorePages) {
- return;
- }
- this.messageCurrentPage+= 1;
- } else {
- this.messageCurrentPage = 1;
- this.autoBottom = true;
- this.messageNew = 0;
- this.messageLists = [];
- }
- this.messageHasMorePages = false;
- //
- this.loadIng++;
- this.messageNoDataText = this.$L("数据加载中.....");
- $A.apiAjax({
- url: 'chat/message/lists',
- data: {
- username: username,
- page: this.messageCurrentPage,
- pagesize: 30
- },
- complete: () => {
- this.loadIng--;
- },
- error: () => {
- this.messageNoDataText = this.$L("数据加载失败!");
- },
- success: (res) => {
- if (username != this.dialogTarget.username) {
- return;
- }
- if (res.ret === 1) {
- let tempId = "notice_" + $A.randomString(6);
- let tempLists = res.data.lists;
- if (isNextPage) {
- this.addMessageData({
- id: tempId,
- type: 'notice',
- notice: this.$L('历史消息'),
- }, false, isNextPage);
- } else {
- tempLists = tempLists.reverse();
- }
- tempLists.forEach((item) => {
- this.addMessageData(Object.assign(item.message, {
- id: item.id,
- username: item.username,
- userimg: item.userimg,
- indate: item.indate,
- }), false, isNextPage);
- });
- if (isNextPage) {
- this.$nextTick(() => {
- let tempObj = $A('div[data-id="' + tempId + '"]');
- if (tempObj.length > 0) {
- this.$refs.manageLists.scrollTo(tempObj.offset().top - tempObj.height() - 24, false);
- }
- });
- }
- this.messageNoDataText = '';
- this.messageHasMorePages = res.data.hasMorePages;
- } else {
- this.messageNoDataText = res.msg
- this.messageHasMorePages = false;
- }
- }
- });
- },
- getTeamLists(isNextPage = false) {
- if (isNextPage === true) {
- if (!this.teamHasMorePages) {
- return;
- }
- this.teamCurrentPage+= 1;
- } else {
- this.teamCurrentPage = 1;
- }
- this.teamHasMorePages = false;
- //
- this.loadIng++;
- this.teamNoDataText = this.$L("数据加载中.....");
- $A.apiAjax({
- url: 'users/team/lists',
- data: {
- sorts: {
- key: 'az',
- order: 'asc'
- },
- page: this.teamCurrentPage,
- pagesize: 100,
- },
- complete: () => {
- this.loadIng--;
- },
- error: () => {
- this.teamNoDataText = this.$L("数据加载失败!");
- },
- success: (res) => {
- if (res.ret === 1) {
- res.data.lists.forEach((item) => {
- if (typeof this.teamLists[item.az] === "undefined") {
- this.$set(this.teamLists, item.az, []);
- }
- this.teamLists[item.az].push(item);
- });
- this.teamNoDataText = this.$L("没有相关的数据");
- this.teamHasMorePages = res.data.hasMorePages;
- //
- if (this.teamHasMorePages && res.data.currentPage < 5) {
- this.getTeamLists(true);
- }
- } else {
- this.teamLists = {};
- this.teamNoDataText = res.msg
- this.teamHasMorePages = false;
- }
- }
- });
- },
- addDialog(data) {
- if (!data.username) {
- return;
- }
- let lists = this.dialogLists.filter((item) => {return item.username == data.username});
- let unread = 0;
- if (lists.length > 0) {
- if (typeof data.userimg === "undefined") {
- data.userimg = lists[0].userimg;
- }
- unread = $A.runNum(lists[0].unread);
- this.dialogLists = this.dialogLists.filter((item) => {return item.username != data.username});
- }
- if (typeof data.unread === "undefined") {
- data.unread = unread;
- }
- this.dialogLists.unshift(data);
- },
- openDialog(user, autoAddDialog = false) {
- if (autoAddDialog === true) {
- let lists = this.dialogLists.filter((item) => {return item.username == user.username});
- if (lists.length === 0) {
- this.addDialog(user);
- }
- }
- this.chatTap = 'dialog';
- this.chatTam = '';
- this.dialogTarget = user;
- if (typeof user.unread === "number" && user.unread > 0) {
- this.unreadTotal -= user.unread;
- this.$set(user, 'unread', 0);
- $A.WSOB.sendTo('read', user.username);
- }
- if (autoAddDialog === true) {
- this.scrollToActive();
- }
- },
- scrollToActive() {
- //自动滚到焦点
- this.$nextTick(() => {
- let dialogObj = $A(this.$refs.dialogLists);
- let activeObj = dialogObj.find("li.active");
- if (activeObj.length > 0) {
- let offsetTop = activeObj.offset().top;
- if (offsetTop < 0) {
- dialogObj.stop().scrollTop(activeObj[0].offsetTop - 50)
- } else if (offsetTop > dialogObj.height()) {
- dialogObj.stop().scrollTop(activeObj[0].offsetTop + 50 + activeObj.height() - dialogObj.height())
- }
- }
- });
- },
- clickDialog(username, autoPush = false) {
- let lists = this.dialogLists.filter((item) => {return item.username == username});
- if (lists.length > 0) {
- this.openDialog(lists[0]);
- if (autoPush === true) {
- this.scrollToActive();
- }
- } else if (autoPush === true) {
- $A.apiAjax({
- url: 'users/team/lists',
- data: {
- username: username,
- },
- success: (res) => {
- if (res.ret === 1 && $A.isPlainObject(res.data)) {
- this.$nextTick(() => {
- typeof this.dialogTarget.username === "undefined" && this.openDialog(res.data, true)
- });
- }
- }
- });
- }
- },
- dialogDropdown(type) {
- switch (type) {
- case 'clear':
- case 'delete':
- this.$Modal.confirm({
- title: this.$L('确认操作'),
- content: type === 'delete' ? this.$L('你确定要删除此对话吗?') : this.$L('你确定要清除聊天记录吗?'),
- loading: true,
- onOk: () => {
- let username = this.dialogTarget.username;
- $A.apiAjax({
- url: 'chat/dialog/clear',
- data: {
- username: username,
- delete: type === 'delete' ? 1 : 0
- },
- error: () => {
- this.$Modal.remove();
- alert(this.$L('网络繁忙,请稍后再试!'));
- },
- success: (res) => {
- this.$Modal.remove();
- if (res.ret === 1) {
- if (type === 'delete') {
- this.dialogLists = this.dialogLists.filter((item) => {return item.username != username});
- this.dialogTarget = {};
- } else {
- this.$set(this.dialogTarget, 'lasttext', '');
- this.getDialogMessage();
- }
- }
- setTimeout(() => {
- if (res.ret === 1) {
- this.$Message.success(res.msg);
- } else {
- this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
- }
- }, 350);
- }
- });
- }
- });
- break;
- }
- },
- messageListsScroll(res) {
- if (res.directionreal === 'up') {
- if (res.scrollE < 10) {
- this.autoBottom = true;
- }
- } else if (res.directionreal === 'down') {
- this.autoBottom = false;
- }
- },
- messageBottomAuto() {
- let randString = $A.randomString(8);
- window.__messageBottomAuto = randString;
- setTimeout(() => {
- if (randString === window.__messageBottomAuto) {
- window.__messageBottomAuto = null;
- if (this.autoBottom) {
- this.messageBottomGo();
- }
- this.messageBottomAuto();
- }
- }, 1000);
- },
- messageBottomGo(animation = false) {
- this.$nextTick(() => {
- this.messageNew = 0;
- if (typeof this.$refs.manageLists !== "undefined") {
- this.$refs.manageLists.scrollTo(this.$refs.manageBody.clientHeight, animation);
- this.autoBottom = true;
- }
- });
- },
- messageInsertText(emoji) {
- this.messageText+= emoji;
- },
- messageInsertFile(item) {
- if (typeof item === 'object' && typeof item.url === "string") {
- let data = {
- type: ['jpg', 'jpeg', 'png', 'gif'].indexOf(item.ext) !== -1 ? 'image' : 'file',
- filename: item.name,
- filesize: item.size,
- filethumb: item.thumb,
- username: this.userInfo.username,
- userimg: this.userInfo.userimg,
- indate: Math.round(new Date().getTime() / 1000),
- url: item.url,
- width: $A.getObject(item, 'response.data.width'),
- height: $A.getObject(item, 'response.data.height'),
- replaceId: item.tempId,
- };
- $A.WSOB.sendTo('user', this.dialogTarget.username, data, (res) => {
- this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
- });
- //
- this.addDialog(Object.assign(this.dialogTarget, {
- lasttext: this.$L(data.type == 'image' ? '[图片]' : '[文件]'),
- lastdate: data.indate
- }));
- this.openDialog(this.dialogTarget);
- this.addMessageData(data, true);
- }
- },
- addMessageData(data, animation = false, isUnshift = false) {
- data.self = data.username === this.userInfo.username;
- let sikp = false;
- if (data.id || data.replaceId) {
- this.messageLists.some((item, index) => {
- if (item.id == data.id || item.id == data.replaceId) {
- data.nickname = data.nickname || item.nickname;
- this.messageLists.splice(index, 1, data);
- return sikp = true;
- }
- });
- if (sikp) {
- return;
- }
- }
- if (isUnshift) {
- this.messageLists.unshift(data);
- } else {
- this.messageLists.push(data);
- if (this.autoBottom) {
- this.messageBottomGo(animation);
- } else {
- this.messageNew++;
- }
- }
- },
- messageSend(e) {
- if (e.keyCode == 13) {
- if (e.shiftKey) {
- return;
- }
- e.preventDefault();
- this.messageSubmit();
- }
- },
- messageDragOver(show) {
- let random = (this.__dialogDragOver = $A.randomString(8));
- if (!show) {
- setTimeout(() => {
- if (random === this.__dialogDragOver) {
- this.dialogDragOver = show;
- }
- }, 150);
- } else {
- this.dialogDragOver = show;
- }
- },
- messagePasteDrag(e, type) {
- this.dialogDragOver = false;
- const files = type === 'drag' ? e.dataTransfer.files : e.clipboardData.files;
- const postFiles = Array.prototype.slice.call(files);
- if (postFiles.length > 0) {
- e.preventDefault();
- postFiles.forEach((file) => {
- this.$refs.messageUpload.upload(file);
- });
- }
- },
- messageFile(type, file) {
- switch (type) {
- case 'progress':
- this.addMessageData({
- id: file.tempId,
- type: 'image',
- username: this.userInfo.username,
- userimg: this.userInfo.userimg,
- indate: Math.round(new Date().getTime() / 1000),
- url: 'loading',
- }, true);
- break;
- case 'error':
- this.messageLists.some((item, index) => {
- if (item.id == file.tempId) {
- this.messageLists.splice(index, 1);
- return true;
- }
- });
- break;
- case 'success':
- this.messageInsertFile(file);
- break;
- }
- },
- messageSubmit() {
- let dialogUser = this.dialogLists.filter((item) => { return item.username == this.dialogTarget.username });
- if (dialogUser.length > 0) {
- let user = dialogUser[0];
- if (typeof user.unread === "number" && user.unread > 0) {
- this.unreadTotal -= user.unread;
- this.$set(user, 'unread', 0);
- $A.WSOB.sendTo('read', user.username);
- }
- }
- //
- this.autoBottom = true;
- let text = this.messageText.trim();
- if ($A.count(text) > 0) {
- let data = {
- type: 'text',
- username: this.userInfo.username,
- userimg: this.userInfo.userimg,
- indate: Math.round(new Date().getTime() / 1000),
- text: text
- };
- $A.WSOB.sendTo('user', this.dialogTarget.username, data, (res) => {
- this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
- });
- //
- this.addDialog(Object.assign(this.dialogTarget, {
- lasttext: text,
- lastdate: data.indate
- }));
- this.openDialog(this.dialogTarget);
- this.addMessageData(data, true);
- }
- this.$nextTick(() => {
- this.messageText = "";
- });
- },
- userViewResult(user, data) {
- this.$set(user, 'nickname', data.nickname);
- this.$set(user, 'userimg', data.userimg);
- },
- videoConnect(username, videoChat) {
- if (!$A.leftExists(window.location.protocol, "https")) {
- this.$Modal.warning({title: this.$L('温馨提示'), content: this.$L('浏览器阻止音视频访问不是https的网站,所以尝试安装SSL!')});
- return;
- }
- this.videoChat = videoChat;
- navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
- try {
- navigator.mediaDevices.getUserMedia({
- audio: true,
- video: this.videoChat
- }).then((stream) => {
- this.videoLocalStream = stream;
- this.$refs.localVideo.srcObject = stream;
- this.$refs.localVideo.removeEventListener('loadedmetadata', this.videoListener);
- //
- if (username === null) {
- // 发起者
- this.videoUserName = this.dialogTarget.username;
- this.videoUserImg = this.dialogTarget.userimg;
- this.videoStartTime = 0;
- this.videoInitiator = true;
- this.$refs.localVideo.addEventListener('loadedmetadata', this.videoListener);
- } else {
- // 接受者
- this.videoIcecandidate(this.videoLocalStream, username);
- this.videoRtc.createOffer({
- offerToReceiveAudio: true,
- offerToReceiveVideo: this.videoChat
- }).then((desc) => {
- this.videoRtc.setLocalDescription(desc).then(() => {
- $A.WSOB.sendTo('info', username, {
- 'type': 'video',
- 'subtype': 'offer',
- 'data': this.videoRtc.localDescription
- });
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- this.videoClose(username, this.$L('对方:') + e);
- });
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- this.videoClose(username, this.$L('对方:') + e);
- });
- }
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- username && this.videoClose(username, this.$L('对方:') + e);
- });
- } catch (e) {
- this.$Modal.warning({title: this.$L('温馨提示'), content: this.$L('当前浏览器不支持音视频通话!')});
- username && this.videoClose(username, this.$L('对方:') + this.$L('浏览器不支持音视频通话!'));
- }
- },
- videoListener() {
- $A.WSOB.sendTo('info', this.videoUserName, {
- 'type': 'video',
- 'subtype': 'call',
- 'username': this.userInfo.username,
- 'userimg': this.userInfo.userimg,
- 'video': this.videoChat,
- }, (res) => {
- if (res.status !== 1) {
- this.videoClose(this.videoUserName, this.$L('呼叫失败!'));
- }
- });
- },
- videoIcecandidate(localStream, username) {
- this.videoRtc = new RTCPeerConnection({"iceServers":[{"urls":["turn:business.swoole.com:3478?transport=udp","turn:business.swoole.com:3478?transport=tcp"],"username":"ceshi","credential":"ceshi"}]});
- this.videoRtc.onicecandidate = (event) => {
- if (event.candidate) {
- $A.WSOB.sendTo('info', username, {
- 'type': 'video',
- 'subtype': 'candidate',
- 'data': event.candidate
- });
- }
- };
- try {
- this.videoRtc.addStream(localStream);
- } catch (e) {
- let tracks = localStream.getTracks();
- for (let i = 0; i < tracks.length; i++) {
- this.videoRtc.addTrack(tracks[i], localStream);
- }
- }
- this.videoRtc.onaddstream = (e) => {
- this.$refs.remoteVideo.srcObject = e.stream;
- };
- },
- videoClose(username, reason) {
- if (username && reason !== false) {
- $A.WSOB.sendTo('info', username, {
- 'type': 'video',
- 'subtype': 'close',
- 'reason': reason,
- });
- }
- if (this.videoInitiator) {
- this.videoInitiator = false;
- if (this.videoStartTime > 0) {
- let second = Math.round(new Date().getTime() / 1000) - this.videoStartTime;
- if (second >= 2) {
- $A.WSOB.sendTo('user', this.videoUserName, {
- type: this.videoChat ? 'video' : 'voice',
- username: this.userInfo.username,
- userimg: this.userInfo.userimg,
- indate: Math.round(new Date().getTime() / 1000),
- text: this.videoChat ? '视频通话' : '语音通话',
- other: {
- second: second
- }
- }, 'special');
- }
- }
- }
- if (username == this.videoUserName) {
- this.videoUserName = '';
- this.videoUserImg = '';
- this.videoStartTime = 0;
- if (this.videoLocalStream !== null) {
- this.videoLocalStream.getTracks().forEach((track) => {
- track.stop();
- });
- this.videoLocalStream = null;
- }
- this.$refs.localVideo.srcObject = null;
- this.$refs.remoteVideo.srcObject = null;
- }
- },
- videoMessage(msgDetail) {
- let body = msgDetail.body;
- let username = msgDetail.username;
- if (['offer', 'candidate', 'answer'].indexOf(body.subtype) !== -1) {
- if (!this.videoLocalStream) {
- this.videoClose(username);
- return;
- }
- }
- //
- switch (body.subtype) {
- case 'call':
- let callIng = true;
- let callAudio = this.$refs.callAudio;
- if (callAudio.getAttribute("data-listener") !== 'yes') {
- callAudio.setAttribute("data-listener", "yes");
- callAudio.addEventListener('ended', () => {
- if (callIng) {
- $A.WSOB.sendTo('info', username, {
- 'type': 'video',
- 'subtype': 'judge',
- });
- callAudio.play();
- }
- }, false);
- }
- callAudio.currentTime = 0;
- callAudio.play();
- //
- this.$Notice.close('chat-call');
- this.$Notice.open({
- name: 'chat-call',
- duration: 0,
- onClose: () => {
- callIng = false;
- callAudio.pause();
- this.videoClose(username, this.$L('对方:拒绝接听'));
- },
- render: h => {
- return h('div', {
- class: 'chat-notice-box',
- }, [
- h('UserImg', {class: 'chat-notice-userimg', props: {info: body}}),
- h('div', {class: 'ivu-notice-with-desc'}, [
- h('div', {class: 'ivu-notice-title'}, [
- h('UserView', {props: {username: username}})
- ]),
- h('div', {class: 'ivu-notice-desc'}, this.$L(body.video ? "邀请视频通话..." : "邀请语音通话...")),
- h('div', {class: 'chat-notice-btn-box'}, [
- h('Button', {
- props: {type: 'success', size: 'small'},
- on: {
- click: () => {
- callIng = false;
- callAudio.pause();
- this.$Notice.close('chat-call');
- this.$emit("on-open-notice", username);
- this.clickDialog(username);
- this.videoConnect(username, body.video);
- this.videoUserName = username;
- this.videoUserImg = body.userimg;
- this.videoStartTime = 0;
- this.videoInitiator = false;
- }
- }
- }, this.$L("接受")),
- h('Button', {
- props: {type: 'error', size: 'small'},
- on: {
- click: () => {
- callIng = false;
- callAudio.pause();
- this.$Notice.close('chat-call');
- this.videoClose(username, this.$L('对方:拒绝接听'));
- }
- }
- }, this.$L("拒绝")),
- ])
- ])
- ])
- }
- });
- break;
- case 'judge':
- if (username != this.videoUserName) {
- $A.WSOB.sendTo('info', username, {
- 'type': 'video',
- 'subtype': 'close',
- });
- }
- break;
- case 'close':
- this.$refs.callAudio.pause();
- this.$Notice.close('chat-call');
- this.videoClose(username, false);
- body.reason && this.$Message.warning(body.reason);
- break;
- case 'offer':
- this.videoIcecandidate(this.videoLocalStream, username);
- this.videoRtc.setRemoteDescription(new RTCSessionDescription(body.data)).then(() => {
- if (this.videoStartTime === 0) {
- this.videoRtc.createAnswer().then((desc) => {
- this.videoRtc.setLocalDescription(desc).then(() => {
- $A.WSOB.sendTo('info', username, {
- 'type': 'video',
- 'subtype': 'answer',
- 'data': this.videoRtc.localDescription
- });
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- });
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- });
- this.videoStartTime = Math.round(new Date().getTime() / 1000);
- }
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- });
- break;
- case 'answer':
- if (this.videoRtc) {
- this.videoRtc.setRemoteDescription(new RTCSessionDescription(body.data)).then(() => {
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- });
- }
- break;
- case 'candidate':
- if (this.videoRtc) {
- this.videoRtc.addIceCandidate(new RTCIceCandidate(body.data)).then(() => {
- }).catch((e) => {
- this.$Modal.warning({title: this.$L('温馨提示'), content: e});
- });
- }
- break;
- }
- }
- }
- }
- </script>
|