@@ -54,12 +54,18 @@ import {
54
54
import { LocalOptions } from '@xkit-yx/im-store-v2/dist/types/types'
55
55
import V2NIM , { V2NIMConst } from 'nim-web-sdk-ng'
56
56
import { V2NIMAIUser } from 'nim-web-sdk-ng/dist/v2/NIM_BROWSER_SDK/V2NIMAIService'
57
- import { RenderP2pCustomMessageOptions } from '@xkit-yx/im-kit-ui/src/chat/components/ChatP2pMessageList'
57
+ import {
58
+ NIMInitializeOptions ,
59
+ NIMOtherOptions ,
60
+ } from 'nim-web-sdk-ng/dist/v2/NIM_BROWSER_SDK/NIMInterface'
61
+ import { RenderP2pCustomMessageOptions } from '@xkit-yx/im-kit-ui/es/chat/components/ChatP2pMessageList'
58
62
59
63
interface IMContainerProps {
60
64
appkey : string //传入您的App Key
61
65
account : string // 传入您的云信IM账号
62
66
token : string // 传入您的Token
67
+ initOptions ?: NIMInitializeOptions
68
+ otherOptions ?: NIMOtherOptions
63
69
onLogout ?: ( ) => void
64
70
changeLanguage ?: ( value : 'zh' | 'en' ) => void
65
71
}
@@ -319,7 +325,6 @@ const IMApp: React.FC<IMAppProps> = observer((props) => {
319
325
[ nim . V2NIMConversationIdUtil , nim . V2NIMMessageCreator , store . msgStore ]
320
326
)
321
327
322
-
323
328
const renderContent = useCallback ( ( ) => {
324
329
return (
325
330
< >
@@ -341,7 +346,7 @@ const IMApp: React.FC<IMAppProps> = observer((props) => {
341
346
className = { classNames ( 'chat-icon' , {
342
347
active : model === 'chat' ,
343
348
} ) }
344
- onClick = { goChat }
349
+ onClick = { ( ) => setModel ( 'chat' ) }
345
350
>
346
351
< i className = "iconfont" > </ i >
347
352
< div className = "icon-label" > { t ( 'session' ) } </ div >
@@ -430,11 +435,10 @@ const IMApp: React.FC<IMAppProps> = observer((props) => {
430
435
teamMsgReceiptVisible ,
431
436
renderP2pCustomMessage ,
432
437
store . sysMsgStore ,
433
- store . msgStore ,
434
- nim . V2NIMMessageCreator ,
435
- nim . V2NIMConversationIdUtil ,
436
438
needMention ,
437
439
teamManagerVisible ,
440
+ afterAcceptApplyFriend ,
441
+ goChat ,
438
442
] )
439
443
440
444
return (
@@ -456,7 +460,7 @@ const IMApp: React.FC<IMAppProps> = observer((props) => {
456
460
} )
457
461
458
462
const IMAppContainer : React . FC < IMContainerProps > = ( props ) => {
459
- const { appkey, account, token, onLogout } = props
463
+ const { appkey, account, token, initOptions , otherOptions , onLogout } = props
460
464
// 国际化语言类型
461
465
const [ curLanguage , setCurLanguage ] = useState < 'zh' | 'en' > ( 'zh' )
462
466
// 添加好友是否需要验证
@@ -566,26 +570,41 @@ const IMAppContainer: React.FC<IMContainerProps> = (props) => {
566
570
} , [ ] )
567
571
568
572
const nim = useMemo ( ( ) => {
569
- const nim = V2NIM . getInstance ( {
570
- appkey,
571
- account,
572
- token,
573
- debugLevel : 'debug' ,
574
- apiVersion : 'v2' ,
575
- } )
573
+ console . log (
574
+ 'V2NIM.getInstance: ' ,
575
+ {
576
+ appkey,
577
+ debugLevel : 'debug' ,
578
+ apiVersion : 'v2' ,
579
+ ...initOptions ,
580
+ } ,
581
+ otherOptions
582
+ )
583
+ const nim = V2NIM . getInstance (
584
+ {
585
+ appkey,
586
+ debugLevel : 'debug' ,
587
+ apiVersion : 'v2' ,
588
+ ...initOptions ,
589
+ } ,
590
+ otherOptions
591
+ )
576
592
577
593
return nim
578
- } , [ account , token , appkey ] )
594
+ } , [ appkey , initOptions , otherOptions ] )
579
595
580
596
useEffect ( ( ) => {
581
- nim . V2NIMLoginService . login ( account , token , {
582
- retryCount : 5 ,
583
- } )
584
-
585
- return ( ) => {
586
- nim . V2NIMLoginService . logout ( )
597
+ if ( account && token ) {
598
+ nim . V2NIMLoginService . login ( account , token , {
599
+ retryCount : 5 ,
600
+ } )
587
601
}
588
- } , [ nim , account , token ] )
602
+ } , [ account , token , nim . V2NIMLoginService ] )
603
+
604
+ const handleLogout = useCallback ( async ( ) => {
605
+ await nim . V2NIMLoginService . logout ( )
606
+ onLogout ?.( )
607
+ } , [ onLogout , nim . V2NIMLoginService ] )
589
608
590
609
return (
591
610
< ConfigProvider locale = { curLanguage === 'zh' ? zhCN : enUS } >
@@ -598,7 +617,7 @@ const IMAppContainer: React.FC<IMContainerProps> = (props) => {
598
617
singleton = { true }
599
618
>
600
619
< IMApp
601
- onLogout = { onLogout }
620
+ onLogout = { handleLogout }
602
621
appkey = { appkey }
603
622
account = { account }
604
623
locale = { curLanguage }
0 commit comments