Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue/PresenceType Enum #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'dart:async';
import 'dart:developer';
import 'dart:io';
import 'package:share_plus/share_plus.dart';

import 'package:flutter/material.dart';
import 'package:flutter_xmpp_example/constants.dart';
import 'package:flutter_xmpp_example/homepage.dart';
import 'package:flutter_xmpp_example/native_log_helper.dart';
import 'package:flutter_xmpp_example/utils.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:share_plus/share_plus.dart';
import 'package:xmpp_plugin/custom_element.dart';
import 'package:xmpp_plugin/ennums/xmpp_connection_state.dart';
import 'package:xmpp_plugin/error_response_event.dart';
Expand Down Expand Up @@ -70,6 +70,8 @@ class _MyAppState extends State<MyApp>
case AppLifecycleState.resumed:
log('resumed detachedCallBack()');
break;
case AppLifecycleState.hidden:
break;
}
}

Expand Down Expand Up @@ -214,7 +216,8 @@ class _MyAppState extends State<MyApp>
await flutterXmpp.getAdmins(groupName);
}

Future<void> changePresenceType(presenceType, presenceMode) async {
Future<void> changePresenceType(
String presenceType, String presenceMode) async {
await flutterXmpp.changePresenceType(presenceType, presenceMode);
}

Expand Down
2 changes: 1 addition & 1 deletion ios/xmpp_plugin.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A new Flutter project.
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.dependency 'XMPPFramework/Swift'
s.platform = :ios, '9.0'
s.platform = :ios, '11.0'

# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
Expand Down
8 changes: 1 addition & 7 deletions lib/ennums/typing_status.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
enum TypingStatus {
COMPOSING,
PAUSED,
ACTIVE,
GONE,
INACTIVE;
}
enum TypingStatus { COMPOSING, PAUSED, ACTIVE, GONE, INACTIVE }
10 changes: 5 additions & 5 deletions lib/message_event.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'ennums/presence_type.dart';

class MessageEvent {
String? customText;
Expand All @@ -10,8 +11,8 @@ class MessageEvent {
String? msgtype;
String? bubbleType;
String? mediaURL;
String? presenceType;
String? presenceMode;
PresenceType? presenceType;
PresenceMode? presenceMode;
String? chatStateType;
int? isReadSent;

Expand Down Expand Up @@ -44,11 +45,10 @@ class MessageEvent {
'msgtype': msgtype,
'bubbleType': bubbleType,
'mediaURL': mediaURL,
'presenceType': presenceType,
'presenceMode': presenceMode,
'presenceType': presenceType?.name,
'presenceMode': presenceMode?.name,
'isReadSent': isReadSent,
'chatStateType': chatStateType,

};
}

Expand Down
100 changes: 67 additions & 33 deletions lib/xmpp_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ abstract class DataChangeEvents {
class XmppConnection {
static const MethodChannel _channel = MethodChannel('flutter_xmpp/method');
static const EventChannel _eventChannel = EventChannel('flutter_xmpp/stream');
static const EventChannel _successEventChannel = EventChannel('flutter_xmpp/success_event_stream');
static const EventChannel _connectionEventChannel = EventChannel('flutter_xmpp/connection_event_stream');
static const EventChannel _errorEventChannel = EventChannel('flutter_xmpp/error_event_stream');
static const EventChannel _successEventChannel =
EventChannel('flutter_xmpp/success_event_stream');
static const EventChannel _connectionEventChannel =
EventChannel('flutter_xmpp/connection_event_stream');
static const EventChannel _errorEventChannel =
EventChannel('flutter_xmpp/error_event_stream');
static late StreamSubscription streamGetMsg;
static late StreamSubscription successEventStream;
static late StreamSubscription connectionEventStream;
Expand Down Expand Up @@ -72,7 +75,8 @@ class XmppConnection {
await _channel.invokeMethod('logout');
}

Future<String> sendMessage(String toJid, String body, String id, int time) async {
Future<String> sendMessage(
String toJid, String body, String id, int time) async {
final params = {
"to_jid": toJid,
"body": body,
Expand All @@ -84,10 +88,12 @@ class XmppConnection {
return status;
}

Future<String> sendMessageWithType(String toJid,
String body,
String id,
int time,) async {
Future<String> sendMessageWithType(
String toJid,
String body,
String id,
int time,
) async {
final params = {
"to_jid": toJid,
"body": body,
Expand All @@ -99,30 +105,35 @@ class XmppConnection {
return status;
}

Future<String> sendGroupMessage(String toJid, String body, String id, int time) async {
Future<String> sendGroupMessage(
String toJid, String body, String id, int time) async {
final params = {
"to_jid": toJid,
"body": body,
"id": id,
"time": time.toString(),
};
printLogForMethodCall('send_group_message', params);
final String status = await _channel.invokeMethod('send_group_message', params);
final String status =
await _channel.invokeMethod('send_group_message', params);
return status;
}

Future<String> sendGroupMessageWithType(String toJid,
String body,
String id,
int time,) async {
Future<String> sendGroupMessageWithType(
String toJid,
String body,
String id,
int time,
) async {
final params = {
"to_jid": toJid,
"body": body,
"id": id,
"time": time.toString(),
};
printLogForMethodCall('send_group_message', params);
final String status = await _channel.invokeMethod('send_group_message', params);
final String status =
await _channel.invokeMethod('send_group_message', params);
return status;
}

Expand Down Expand Up @@ -156,22 +167,28 @@ class XmppConnection {
},
);

connectionEventStream = _connectionEventChannel.receiveBroadcastStream().listen((connectionData) {
ConnectionEvent connectionEvent = ConnectionEvent.fromJson(connectionData);
connectionEventStream = _connectionEventChannel
.receiveBroadcastStream()
.listen((connectionData) {
ConnectionEvent connectionEvent =
ConnectionEvent.fromJson(connectionData);
dataChangelist.forEach((element) {
element.onConnectionEvents(connectionEvent);
});
}, onError: _onError);

successEventStream = _successEventChannel.receiveBroadcastStream().listen((successData) {
SuccessResponseEvent eventModel = SuccessResponseEvent.fromJson(successData);
successEventStream =
_successEventChannel.receiveBroadcastStream().listen((successData) {
SuccessResponseEvent eventModel =
SuccessResponseEvent.fromJson(successData);
print("success event ${eventModel.toSuccessResponseData()}");
dataChangelist.forEach((element) {
element.onSuccessEvent(eventModel);
});
}, onError: _onError);

errorEventStream = _errorEventChannel.receiveBroadcastStream().listen((errorData) {
errorEventStream =
_errorEventChannel.receiveBroadcastStream().listen((errorData) {
ErrorResponseEvent eventModel = ErrorResponseEvent.fromJson(errorData);
print("Error event ${eventModel.toErrorResponseData()}");
dataChangelist.forEach((element) {
Expand Down Expand Up @@ -218,7 +235,8 @@ class XmppConnection {
return await _channel.invokeMethod('join_muc_group', params);
}

Future<void> sendCustomMessage(String toJid, String body, String id, String customString, int time) async {
Future<void> sendCustomMessage(String toJid, String body, String id,
String customString, int time) async {
final params = {
"to_jid": toJid,
"body": body,
Expand All @@ -233,7 +251,8 @@ class XmppConnection {
log('call method to app from flutter methodName: $methodName: params: $params');
}

Future<void> sendCustomGroupMessage(String toJid, String body, String id, String customString, int time) async {
Future<void> sendCustomGroupMessage(String toJid, String body, String id,
String customString, int time) async {
final params = {
"to_jid": toJid,
"body": body,
Expand All @@ -244,7 +263,8 @@ class XmppConnection {
await _channel.invokeMethod('send_customgroup_message', params);
}

Future<void> sendDelieveryReceipt(String toJid, String msgId, String receiptID) async {
Future<void> sendDelieveryReceipt(
String toJid, String msgId, String receiptID) async {
final params = {"toJid": toJid, "msgId": msgId, "receiptId": receiptID};
await _channel.invokeMethod('send_delivery_receipt', params);
}
Expand All @@ -254,7 +274,8 @@ class XmppConnection {
await _channel.invokeMethod('add_members_in_group', params);
}

Future<void> addAdminsInGroup(String groupName, List<String> adminMembers) async {
Future<void> addAdminsInGroup(
String groupName, List<String> adminMembers) async {
final params = {"group_name": groupName, "members_jid": adminMembers};
await _channel.invokeMethod('add_admins_in_group', params);
}
Expand Down Expand Up @@ -293,7 +314,8 @@ class XmppConnection {

Future<int> getOnlineMemberCount(String groupName) async {
final params = {"group_name": groupName};
int memberCount = await _channel.invokeMethod('get_online_member_count', params);
int memberCount =
await _channel.invokeMethod('get_online_member_count', params);
print('checkGroups getOccupantsSize: $memberCount');
return memberCount;
}
Expand Down Expand Up @@ -332,14 +354,23 @@ class XmppConnection {
return admins;
}

Future<void> requestMamMessages(String userJid, String requestSince, String requestBefore, String limit) async {
print(" Plugin : User Jid : $userJid , Request since : $requestSince , Request Before : $requestBefore, Limit : $limit ");
final params = {"userJid": userJid, "requestBefore": requestBefore, "requestSince": requestSince, "limit": limit};
Future<void> requestMamMessages(String userJid, String requestSince,
String requestBefore, String limit) async {
print(
" Plugin : User Jid : $userJid , Request since : $requestSince , Request Before : $requestBefore, Limit : $limit ");
final params = {
"userJid": userJid,
"requestBefore": requestBefore,
"requestSince": requestSince,
"limit": limit
};
await _channel.invokeMethod('request_mam', params);
}

Future<void> changeTypingStatus(String userJid,
String typingstatus,) async {
Future<void> changeTypingStatus(
String userJid,
String typingstatus,
) async {
print(" Plugin : User Jid : $userJid , Typing Status : $typingstatus ");
final params = {
"userJid": userJid,
Expand All @@ -348,15 +379,18 @@ class XmppConnection {
await _channel.invokeMethod('change_typing_status', params);
}

Future<void> changePresenceType(String presenceType, String presenceMode) async {
print(" Plugin : presenceType : $presenceType , presenceMode : $presenceMode");
Future<void> changePresenceType(
String presenceType, String presenceMode) async {
print(
" Plugin : presenceType : $presenceType , presenceMode : $presenceMode");
final params = {"presenceType": presenceType, "presenceMode": presenceMode};
await _channel.invokeMethod('change_presence_type', params);
}

Future<XmppConnectionState> getConnectionStatus() async {
printLogForMethodCall('get_connection_status', '');
String connectionState = await _channel.invokeMethod('get_connection_status');
String connectionState =
await _channel.invokeMethod('get_connection_status');
return connectionState.toConnectionState();
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 2.3.1
homepage: https://github.com/vavadiyahiren/xmpp_plugin

environment:
sdk: '>=2.18.4 <4.0.0'
sdk: ">=2.18.4 <4.0.0"
flutter: ">=2.5.0"

dependencies:
Expand Down
Loading