Skip to content

Commit

Permalink
Merge pull request #96 from fsufyan/new-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Gehorsam authored Mar 20, 2024
2 parents f595a5a + 0b8121d commit 5266238
Show file tree
Hide file tree
Showing 165 changed files with 232 additions and 397 deletions.
33 changes: 0 additions & 33 deletions lib/nakama.dart

This file was deleted.

1 change: 0 additions & 1 deletion lib/satori/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions lib/src/api/api.dart

This file was deleted.

9 changes: 0 additions & 9 deletions lib/src/api/rtapi.dart

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
56 changes: 0 additions & 56 deletions README.md → nakama/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,62 +116,6 @@ Remember to close the connection after disposing of the app widget:
NakamaWebsocketClient.instance.close();
```

# Satori

Satori is a liveops server for games that powers actionable analytics, A/B testing and remote configuration. Use the Satori Dart Client to communicate with Satori from within your Dart game.

Full documentation is online - https://heroiclabs.com/docs/satori/client-libraries/dart/index.html

## Getting Started

To integrating Satori within your Dart app through Nakama package you need to import Satori using a prefix to avoid conflict with Nakama types:

```dart
import 'package:nakama/satori/lib/satori.dart' as satori;
```

and then you can access satori client using `satori.` prefix.

Now to start using Satori, create a client object that accepts the API key you were given as a Satori customer.

```dart
final client = getSatoriClient(
host: '127.0.0.1',
port: 7450,
ssl: false,
apiKey: 'apikey',
);
```

Then authenticate with the server to obtain your session.

```dart
// Authenticate with the Satori server.
try {
final session = await _satoriClient.authenticate(id: 'your-id');
print('Authenticated successfully: $session');
} catch (error) {
print('Authentication failed $error');
}
```

Using the client you can get any experiments or feature flags the user belongs to.

```dart
final experiments = await _satoriClient.getExperiments(session: session, names: ['experiment1', 'Experiment2']);
final flag = await _satoriClient.getFlag(session: session, name: 'FlagName');
```

You can also send arbitrary events to the server:

```dart
final event = Event(
name: 'gameLaunched',
value: jsonEncode({'gameId': 'id-1234'}),
);
await _satoriClient.event(session: session, event: event);
```

## Documentation

**Dart/Flutter SDK Docs:**
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
31 changes: 31 additions & 0 deletions nakama/lib/nakama.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
library nakama;

export 'package:fixnum/fixnum.dart' show Int64;

// Enums
export 'src/enum/channel_type.dart';
export 'src/enum/friendship_state.dart';
export 'src/enum/group_membership_states.dart';
export 'src/enum/leaderboard_operator.dart';
export 'src/enum/storage_permission.dart';
// Public models
export 'src/models/account.dart';
export 'src/models/chat.dart';
export 'src/models/friends.dart';
export 'src/models/group.dart';
export 'src/models/leaderboard.dart';
export 'src/models/match.dart';
export 'src/models/matchmaker.dart';
export 'src/models/notification.dart';
export 'src/models/party.dart';
export 'src/models/rpc.dart';
export 'src/models/session.dart';
export 'src/models/status.dart';
export 'src/models/storage.dart';
export 'src/models/tournament.dart';
// Clients
export 'src/nakama_client/nakama_api_client.dart';
export 'src/nakama_client/nakama_client.dart';
export 'src/nakama_client/nakama_grpc_client.dart';
export 'src/nakama_client/stub/nakama_client_stub.dart' if (dart.library.io) './src/nakama_client/stub/grpc_client.dart' if (dart.library.js) './src/nakama_client/stub/api_client.dart';
export 'src/nakama_websocket_client.dart';
9 changes: 9 additions & 0 deletions nakama/lib/src/api/api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
library api;

// In64 used in protobuf
export 'package:fixnum/fixnum.dart' show Int64;

export 'proto/api/api.pb.dart';
export 'proto/google/protobuf/empty.pb.dart';
export 'proto/google/protobuf/timestamp.pb.dart';
export 'proto/google/protobuf/wrappers.pb.dart';
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions nakama/lib/src/api/rtapi.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
library api;

// In64 used in protobuf
export 'package:fixnum/fixnum.dart' show Int64;

export 'proto/google/protobuf/empty.pb.dart';
export 'proto/google/protobuf/timestamp.pb.dart';
export 'proto/google/protobuf/wrappers.pb.dart';
export 'proto/rtapi/realtime.pb.dart';
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@ class Account with _$Account {
required User user,
}) = _Account;

factory Account.fromJson(Map<String, Object?> json) =>
_$AccountFromJson(json);
factory Account.fromJson(Map<String, Object?> json) => _$AccountFromJson(json);

factory Account.fromDto(api.Account dto) => Account(
wallet: dto.wallet,
email: dto.email,
devices:
dto.devices.map((e) => Device.fromDto(e)).toList(growable: false),
devices: dto.devices.map((e) => Device.fromDto(e)).toList(growable: false),
customId: dto.customId,
verifyTime:
dto.verifyTime.hasNanos() ? dto.verifyTime.toDateTime() : null,
disableTime:
dto.disableTime.hasNanos() ? dto.disableTime.toDateTime() : null,
verifyTime: dto.verifyTime.hasNanos() ? dto.verifyTime.toDateTime() : null,
disableTime: dto.disableTime.hasNanos() ? dto.disableTime.toDateTime() : null,
user: User.fromDto(dto.user),
);
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:nakama/src/api/api.dart' as api;

part 'channel_message.g.dart';
part 'channel_message.freezed.dart';
part 'channel_message.g.dart';

@freezed
class ChannelMessage with _$ChannelMessage {
Expand All @@ -24,8 +24,7 @@ class ChannelMessage with _$ChannelMessage {
required String userIdTwo,
}) = _ChannelMessage;

factory ChannelMessage.fromJson(Map<String, Object?> json) =>
_$ChannelMessageFromJson(json);
factory ChannelMessage.fromJson(Map<String, Object?> json) => _$ChannelMessageFromJson(json);

factory ChannelMessage.fromDto(api.ChannelMessage dto) => ChannelMessage(
channelId: dto.channelId,
Expand Down Expand Up @@ -55,14 +54,10 @@ class ChannelMessageList with _$ChannelMessageList {
required String cacheableCursor,
}) = _ChannelMessageList;

factory ChannelMessageList.fromJson(Map<String, Object?> json) =>
_$ChannelMessageListFromJson(json);
factory ChannelMessageList.fromJson(Map<String, Object?> json) => _$ChannelMessageListFromJson(json);

factory ChannelMessageList.fromDto(api.ChannelMessageList dto) =>
ChannelMessageList(
messages: dto.messages
.map((e) => ChannelMessage.fromDto(e))
.toList(growable: false),
factory ChannelMessageList.fromDto(api.ChannelMessageList dto) => ChannelMessageList(
messages: dto.messages.map((e) => ChannelMessage.fromDto(e)).toList(growable: false),
nextCursor: dto.nextCursor,
prevCursor: dto.prevCursor,
cacheableCursor: dto.cacheableCursor,
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 2 additions & 5 deletions lib/src/models/chat.dart → nakama/lib/src/models/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ class Channel with _$Channel {

factory Channel.fromDto(rtpb.Channel dto) => Channel(
id: dto.id,
presences: dto.presences
.map((e) => UserPresence.fromDto(e))
.toList(growable: false),
presences: dto.presences.map((e) => UserPresence.fromDto(e)).toList(growable: false),
self: UserPresence.fromDto(dto.self),
roomName: dto.roomName,
groupId: dto.groupId,
Expand Down Expand Up @@ -89,8 +87,7 @@ class ChannelMessageAck with _$ChannelMessageAck {
required String userIdTwo,
}) = _ChannelMessageAck;

factory ChannelMessageAck.fromDto(rtpb.ChannelMessageAck dto) =>
ChannelMessageAck(
factory ChannelMessageAck.fromDto(rtpb.ChannelMessageAck dto) => ChannelMessageAck(
channelId: dto.channelId,
messageId: dto.messageId,
code: dto.code.value,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class FriendsList with _$FriendsList {
required List<Friend> friends,
}) = _FriendsList;

factory FriendsList.fromJson(Map<String, Object?> json) =>
_$FriendsListFromJson(json);
factory FriendsList.fromJson(Map<String, Object?> json) => _$FriendsListFromJson(json);

factory FriendsList.fromDto(api.FriendList dto) => FriendsList(
cursor: dto.cursor,
Expand Down
File renamed without changes.
File renamed without changes.
23 changes: 7 additions & 16 deletions lib/src/models/group.dart → nakama/lib/src/models/group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class GroupList with _$GroupList {
required List<Group> groups,
}) = _GroupList;

factory GroupList.fromJson(Map<String, Object?> json) =>
_$GroupListFromJson(json);
factory GroupList.fromJson(Map<String, Object?> json) => _$GroupListFromJson(json);

factory GroupList.fromDto(api.GroupList dto) => GroupList(
cursor: dto.cursor,
Expand All @@ -70,14 +69,11 @@ class UserGroupList with _$UserGroupList {
required List<UserGroup> userGroups,
}) = _UserGroupList;

factory UserGroupList.fromJson(Map<String, Object?> json) =>
_$UserGroupListFromJson(json);
factory UserGroupList.fromJson(Map<String, Object?> json) => _$UserGroupListFromJson(json);

factory UserGroupList.fromDto(api.UserGroupList dto) => UserGroupList(
cursor: dto.cursor,
userGroups: dto.userGroups
.map((e) => UserGroup.fromDto(e))
.toList(growable: false),
userGroups: dto.userGroups.map((e) => UserGroup.fromDto(e)).toList(growable: false),
);
}

Expand All @@ -90,8 +86,7 @@ class UserGroup with _$UserGroup {
required Group group,
}) = _UserGroup;

factory UserGroup.fromJson(Map<String, Object?> json) =>
_$UserGroupFromJson(json);
factory UserGroup.fromJson(Map<String, Object?> json) => _$UserGroupFromJson(json);

factory UserGroup.fromDto(api.UserGroupList_UserGroup dto) => UserGroup(
group: Group.fromDto(dto.group),
Expand All @@ -108,14 +103,11 @@ class GroupUserList with _$GroupUserList {
required List<GroupUser> groupUsers,
}) = _GroupUserList;

factory GroupUserList.fromJson(Map<String, Object?> json) =>
_$GroupUserListFromJson(json);
factory GroupUserList.fromJson(Map<String, Object?> json) => _$GroupUserListFromJson(json);

factory GroupUserList.fromDto(api.GroupUserList dto) => GroupUserList(
cursor: dto.cursor,
groupUsers: dto.groupUsers
.map((e) => GroupUser.fromDto(e))
.toList(growable: false),
groupUsers: dto.groupUsers.map((e) => GroupUser.fromDto(e)).toList(growable: false),
);
}

Expand All @@ -128,8 +120,7 @@ class GroupUser with _$GroupUser {
required User user,
}) = _GroupUser;

factory GroupUser.fromJson(Map<String, Object?> json) =>
_$GroupUserFromJson(json);
factory GroupUser.fromJson(Map<String, Object?> json) => _$GroupUserFromJson(json);

factory GroupUser.fromDto(api.GroupUserList_GroupUser dto) => GroupUser(
state: GroupMembershipState.values[dto.state.value],
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ class LeaderboardRecordList with _$LeaderboardRecordList {
String? prevCursor,
}) = _LeaderboardRecordList;

factory LeaderboardRecordList.fromJson(Map<String, Object?> json) =>
_$LeaderboardRecordListFromJson(json);
factory LeaderboardRecordList.fromJson(Map<String, Object?> json) => _$LeaderboardRecordListFromJson(json);

factory LeaderboardRecordList.fromDto(api.LeaderboardRecordList dto) =>
LeaderboardRecordList(
records:
dto.ownerRecords.map((e) => LeaderboardRecord.fromDto(e)).toList(),
ownerRecords:
dto.ownerRecords.map((e) => LeaderboardRecord.fromDto(e)).toList(),
factory LeaderboardRecordList.fromDto(api.LeaderboardRecordList dto) => LeaderboardRecordList(
records: dto.ownerRecords.map((e) => LeaderboardRecord.fromDto(e)).toList(),
ownerRecords: dto.ownerRecords.map((e) => LeaderboardRecord.fromDto(e)).toList(),
nextCursor: dto.nextCursor,
prevCursor: dto.prevCursor,
);
Expand All @@ -52,24 +48,19 @@ class LeaderboardRecord with _$LeaderboardRecord {
@Default(0) int maxNumScore,
}) = _LeaderboardRecord;

factory LeaderboardRecord.fromJson(Map<String, Object?> json) =>
_$LeaderboardRecordFromJson(json);
factory LeaderboardRecord.fromJson(Map<String, Object?> json) => _$LeaderboardRecordFromJson(json);

factory LeaderboardRecord.fromDto(api.LeaderboardRecord dto) =>
LeaderboardRecord(
factory LeaderboardRecord.fromDto(api.LeaderboardRecord dto) => LeaderboardRecord(
leaderboardId: dto.leaderboardId,
ownerId: dto.ownerId,
username: dto.username.value,
score: dto.score.toInt(),
subscore: dto.subscore.toInt(),
numScore: dto.numScore.toInt(),
metadata: dto.metadata,
createTime:
dto.createTime.hasNanos() ? dto.createTime.toDateTime() : null,
updateTime:
dto.updateTime.hasNanos() ? dto.updateTime.toDateTime() : null,
expiryTime:
dto.expiryTime.hasNanos() ? dto.expiryTime.toDateTime() : null,
createTime: dto.createTime.hasNanos() ? dto.createTime.toDateTime() : null,
updateTime: dto.updateTime.hasNanos() ? dto.updateTime.toDateTime() : null,
expiryTime: dto.expiryTime.hasNanos() ? dto.expiryTime.toDateTime() : null,
rank: dto.rank.toInt(),
maxNumScore: dto.maxNumScore.toInt(),
);
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 5266238

Please sign in to comment.