commit
71f15b5865
@ -1,7 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'dart:io';
|
||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
|
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@ -16,6 +15,7 @@ class MyApp extends StatefulWidget {
|
|||||||
class _MyAppState extends State<MyApp> {
|
class _MyAppState extends State<MyApp> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
_initSDK();
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,21 +28,81 @@ class _MyAppState extends State<MyApp> {
|
|||||||
),
|
),
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
TextButton(onPressed: _testApi, child: Text('api')),
|
TextButton(onPressed: _login, child: Text('login')),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _testApi() {
|
void _login() {
|
||||||
// FlutterOpenimSdk.iMManager.initSDK(
|
if (OpenIM.iMManager.isInitialized)
|
||||||
// platform: platform,
|
OpenIM.iMManager.login(uid: '', token: '');
|
||||||
// ipApi: ipApi,
|
}
|
||||||
// ipWs: ipWs,
|
|
||||||
// dbPath: dbPath,
|
|
||||||
// listener: listener,
|
|
||||||
// );
|
|
||||||
|
|
||||||
|
void _initSDK() async {
|
||||||
|
// Initialize SDK
|
||||||
|
OpenIM.iMManager
|
||||||
|
..initSDK(
|
||||||
|
platform: Platform.isAndroid ? IMPlatform.android : IMPlatform.ios,
|
||||||
|
ipApi: '',
|
||||||
|
ipWs: '',
|
||||||
|
dbPath: '',
|
||||||
|
listener: OnInitSDKListener(
|
||||||
|
connecting: () {},
|
||||||
|
connectFailed: (code, error) {},
|
||||||
|
connectSuccess: () {},
|
||||||
|
kickedOffline: () {},
|
||||||
|
userSigExpired: () {},
|
||||||
|
selfInfoUpdated: (user) {},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Add message listener (remove when not in use)
|
||||||
|
..messageManager.addAdvancedMsgListener(OnAdvancedMsgListener(
|
||||||
|
recvMessageRevoked: (msgId) {},
|
||||||
|
recvC2CReadReceipt: (list) {},
|
||||||
|
recvNewMessage: (msg) {},
|
||||||
|
))
|
||||||
|
|
||||||
|
// Set up message sending progress listener
|
||||||
|
..messageManager.setMsgSendProgressListener(OnMsgSendProgressListener(
|
||||||
|
progressCallback: (msgId, progress) {},
|
||||||
|
))
|
||||||
|
|
||||||
|
// Set up friend relationship listener
|
||||||
|
..friendshipManager.setFriendshipListener(OnFriendshipListener(
|
||||||
|
blackListAdd: (u) {},
|
||||||
|
blackListDeleted: (u) {},
|
||||||
|
friendApplicationListAccept: (u) {},
|
||||||
|
friendApplicationListAdded: (u) {},
|
||||||
|
friendApplicationListDeleted: (u) {},
|
||||||
|
friendApplicationListReject: (u) {},
|
||||||
|
friendInfoChanged: (u) {},
|
||||||
|
friendListAdded: (u) {},
|
||||||
|
friendListDeleted: (u) {},
|
||||||
|
))
|
||||||
|
|
||||||
|
// Set up conversation listener
|
||||||
|
..conversationManager.setConversationListener(OnConversationListener(
|
||||||
|
conversationChanged: (list) {},
|
||||||
|
newConversation: (list) {},
|
||||||
|
totalUnreadMsgCountChanged: (count) {},
|
||||||
|
syncServerFailed: () {},
|
||||||
|
syncServerFinish: () {},
|
||||||
|
syncServerStart: () {},
|
||||||
|
))
|
||||||
|
|
||||||
|
// Set up group listener
|
||||||
|
..groupManager.setGroupListener(OnGroupListener(
|
||||||
|
applicationProcessed: (groupId, opUser, agreeOrReject, opReason) {},
|
||||||
|
groupCreated: (groupId) {},
|
||||||
|
groupInfoChanged: (groupId, info) {},
|
||||||
|
memberEnter: (groupId, list) {},
|
||||||
|
memberInvited: (groupId, opUser, list) {},
|
||||||
|
memberKicked: (groupId, opUser, list) {},
|
||||||
|
memberLeave: (groupId, info) {},
|
||||||
|
receiveJoinApplication: (groupId, info, opReason) {},
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:developer';
|
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
|
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
|
||||||
@ -15,6 +14,7 @@ class IMManager {
|
|||||||
late InitSDKListener _initSDKListener;
|
late InitSDKListener _initSDKListener;
|
||||||
late String uid;
|
late String uid;
|
||||||
late UserInfo uInfo;
|
late UserInfo uInfo;
|
||||||
|
bool isInitialized = false;
|
||||||
|
|
||||||
IMManager(this._channel) {
|
IMManager(this._channel) {
|
||||||
conversationManager = ConversationManager(_channel);
|
conversationManager = ConversationManager(_channel);
|
||||||
@ -277,17 +277,29 @@ class IMManager {
|
|||||||
required InitSDKListener listener,
|
required InitSDKListener listener,
|
||||||
}) {
|
}) {
|
||||||
_initSDKListener = listener;
|
_initSDKListener = listener;
|
||||||
return _channel.invokeMethod(
|
return _channel
|
||||||
'initSDK',
|
.invokeMethod(
|
||||||
_buildParam(
|
'initSDK',
|
||||||
{"platform": platform, "ipApi": ipApi, "ipWs": ipWs, "dbDir": dbPath},
|
_buildParam(
|
||||||
),
|
{
|
||||||
);
|
"platform": platform,
|
||||||
|
"ipApi": ipApi,
|
||||||
|
"ipWs": ipWs,
|
||||||
|
"dbDir": dbPath
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.then((value) {
|
||||||
|
isInitialized = true;
|
||||||
|
return value;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
Future<dynamic> unInitSDK() {
|
Future<dynamic> unInitSDK() {
|
||||||
return _channel.invokeMethod('unInitSDK', _buildParam({}));
|
return _channel.invokeMethod('unInitSDK', _buildParam({})).then((value) {
|
||||||
|
isInitialized = false;
|
||||||
|
return value;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// login sdk
|
/// login sdk
|
||||||
|
Loading…
x
Reference in New Issue
Block a user