Skip to content

Commit 29374a1

Browse files
committed
Update Diffusion Examples to 6.6.0-preview.1
1 parent 1afd4f2 commit 29374a1

File tree

73 files changed

+6632
-457
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+6632
-457
lines changed

android/pubsub/app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apply plugin: 'com.android.application'
33
android {
44
compileSdkVersion 27
55
defaultConfig {
6+
multiDexEnabled true
67
applicationId "com.pushtechnology.examples"
78
minSdkVersion 19
89
targetSdkVersion 27
@@ -17,11 +18,14 @@ android {
1718
}
1819

1920
compileOptions {
21+
coreLibraryDesugaringEnabled true
2022
sourceCompatibility JavaVersion.VERSION_1_8
2123
targetCompatibility JavaVersion.VERSION_1_8
2224
}
2325
}
2426

2527
dependencies {
28+
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.9'
29+
implementation 'org.slf4j:slf4j-api:1.7.21'
2630
implementation fileTree(dir: 'libs', include: ['*.jar'])
2731
}

android/pubsub/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.2.1'
10+
classpath 'com.android.tools.build:gradle:4.0.0'
1111

1212

1313
// NOTE: Do not place your application dependencies here; they belong
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Diffusion Client Library for iOS, tvOS and OS X / macOS - Examples
2+
//
3+
// Copyright (C) 2020 Push Technology Ltd.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#import "ClientControlCloseSessionExample.h"
17+
18+
@import Diffusion;
19+
20+
@implementation ClientControlCloseSessionExample {
21+
PTDiffusionSession* _normalSession;
22+
PTDiffusionSession* _controlSession;
23+
NSError *_error;
24+
}
25+
26+
-(void)startWithURL:(NSURL*)url {
27+
28+
/*
29+
* We'll run this example in a another thread other than main.
30+
* This allows to run operations in a synchronous way which is easier to read.
31+
*/
32+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
33+
34+
// Creating normal session
35+
self->_normalSession = [self synchronousOpenSessionWithURL:url principal:@"client" andPassword:@"password"];
36+
if (!self->_normalSession) {
37+
NSLog(@"Failed to open normal session: [%@]", self->_error);
38+
return;
39+
}
40+
NSLog(@"Created normal session [%@]", self->_normalSession.sessionId);
41+
42+
43+
// Creating control session
44+
self->_controlSession = [self synchronousOpenSessionWithURL:url principal:@"control" andPassword:@"password"];
45+
if (!self->_controlSession) {
46+
NSLog(@"Failed to open control session: [%@]", self->_error);
47+
return;
48+
}
49+
NSLog(@"Created control session [%@]", self->_controlSession.sessionId);
50+
51+
52+
// Adding session state listener for normal session
53+
NSNotificationCenter *const nc = [NSNotificationCenter defaultCenter];
54+
[nc addObserver:self
55+
selector:@selector(onSessionStateChangeNotification:)
56+
name:PTDiffusionSessionStateDidChangeNotification
57+
object:self->_normalSession];
58+
59+
60+
// Closing normal session
61+
[self->_controlSession.clientControl closeClientWithSessionId:self->_normalSession.sessionId
62+
completionHandler:^(NSError * _Nullable error)
63+
{
64+
if (error != nil) {
65+
NSLog(@"An error occured while closing client: [%@]", error);
66+
}
67+
else {
68+
NSLog(@"Client has been closed.");
69+
}
70+
}];
71+
});
72+
}
73+
74+
75+
-(PTDiffusionSession *)synchronousOpenSessionWithURL:(NSURL *)url
76+
principal:(NSString *)principal
77+
andPassword:(NSString *)password {
78+
79+
PTDiffusionCredentials *const credentials = [[PTDiffusionCredentials alloc] initWithPassword:password];
80+
81+
PTDiffusionSessionConfiguration *const sessionConfiguration =
82+
[[PTDiffusionSessionConfiguration alloc] initWithPrincipal:principal
83+
credentials:credentials];
84+
85+
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
86+
87+
__block PTDiffusionSession *newSession;
88+
[PTDiffusionSession openWithURL:url
89+
configuration:sessionConfiguration
90+
completionHandler:^(PTDiffusionSession * _Nullable session, NSError * _Nullable error)
91+
{
92+
newSession = session;
93+
self->_error = error;
94+
dispatch_semaphore_signal(sema);
95+
}];
96+
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
97+
return newSession;
98+
}
99+
100+
101+
-(void)onSessionStateChangeNotification:(NSNotification *const)notification {
102+
PTDiffusionSessionStateChange *const stateChange = notification.userInfo[PTDiffusionSessionStateChangeUserInfoKey];
103+
PTDiffusionSession *const session = (PTDiffusionSession *) notification.object;
104+
if (stateChange.state.isClosed && stateChange.state.error != nil) {
105+
NSLog(@"Session [%@] has been closed: [%@]", session.sessionId, stateChange.state.error);
106+
}
107+
}
108+
109+
@end
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// Diffusion Client Library for iOS, tvOS and OS X / macOS - Examples
2+
//
3+
// Copyright (C) 2020 Push Technology Ltd.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#import "ClientControlCloseSessionFilterExample.h"
17+
18+
@import Diffusion;
19+
20+
@implementation ClientControlCloseSessionFilterExample {
21+
PTDiffusionSession* _normalSession1;
22+
PTDiffusionSession* _normalSession2;
23+
PTDiffusionSession* _controlSession;
24+
NSError *_error;
25+
}
26+
27+
-(void)startWithURL:(NSURL*)url {
28+
29+
/*
30+
* We'll run this example in a another thread other than main.
31+
* This allows to run operations in a synchronous way which is easier to read.
32+
*/
33+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
34+
35+
// Creating normal session 1
36+
self->_normalSession1 = [self synchronousOpenSessionWithURL:url principal:@"client" andPassword:@"password"];
37+
if (!self->_normalSession1) {
38+
NSLog(@"Failed to open normal session 1: [%@]", self->_error);
39+
return;
40+
}
41+
NSLog(@"Created normal session 1 [%@]", self->_normalSession1.sessionId);
42+
43+
44+
// Creating normal session 2
45+
self->_normalSession2 = [self synchronousOpenSessionWithURL:url principal:@"client" andPassword:@"password"];
46+
if (!self->_normalSession2) {
47+
NSLog(@"Failed to open normal session 2: [%@]", self->_error);
48+
return;
49+
}
50+
NSLog(@"Created normal session 2 [%@]", self->_normalSession2.sessionId);
51+
52+
53+
// Creating control session
54+
self->_controlSession = [self synchronousOpenSessionWithURL:url principal:@"control" andPassword:@"password"];
55+
if (!self->_controlSession) {
56+
NSLog(@"Failed to open control session: [%@]", self->_error);
57+
return;
58+
}
59+
NSLog(@"Created control session [%@]", self->_controlSession.sessionId);
60+
61+
62+
// Adding session state listener for normal session 1
63+
NSNotificationCenter *const nc = [NSNotificationCenter defaultCenter];
64+
[nc addObserver:self
65+
selector:@selector(onSessionStateChangeNotification:)
66+
name:PTDiffusionSessionStateDidChangeNotification
67+
object:self->_normalSession1];
68+
69+
70+
// Setting country of normal session 1 to UK
71+
NSDictionary *sessionPropertiesNormalSession1 = @{PTDiffusionSession.countryPropertyKey : @"UK"};
72+
[self synchronousSetSessionProperties:sessionPropertiesNormalSession1
73+
forSession:self->_normalSession1
74+
usingControlSession:self->_controlSession];
75+
76+
77+
// Setting country of normal session 2 to US
78+
NSDictionary *sessionPropertiesNormalSession2 = @{PTDiffusionSession.countryPropertyKey : @"US"};
79+
[self synchronousSetSessionProperties:sessionPropertiesNormalSession2
80+
forSession:self->_normalSession2
81+
usingControlSession:self->_controlSession];
82+
83+
84+
// Closing sessions that have UK as their country
85+
NSString *sessionFilter = [NSString stringWithFormat:@"%@ EQ 'UK'", PTDiffusionSession.countryPropertyKey];
86+
[self->_controlSession.clientControl closeClientWithFilter:sessionFilter
87+
completionHandler:^(NSInteger closedSessions, NSError * _Nullable error)
88+
{
89+
if (error != nil) {
90+
NSLog(@"An error occured while closing clients using session filter: [%@]", error);
91+
}
92+
else {
93+
NSLog(@"Total clients closed: %ld", (long) closedSessions);
94+
}
95+
}];
96+
97+
});
98+
}
99+
100+
101+
-(PTDiffusionSession *)synchronousOpenSessionWithURL:(NSURL *)url
102+
principal:(NSString *)principal
103+
andPassword:(NSString *)password {
104+
105+
PTDiffusionCredentials *const credentials = [[PTDiffusionCredentials alloc] initWithPassword:password];
106+
107+
PTDiffusionSessionConfiguration *const sessionConfiguration =
108+
[[PTDiffusionSessionConfiguration alloc] initWithPrincipal:principal
109+
credentials:credentials];
110+
111+
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
112+
113+
__block PTDiffusionSession *newSession;
114+
[PTDiffusionSession openWithURL:url
115+
configuration:sessionConfiguration
116+
completionHandler:^(PTDiffusionSession * _Nullable session, NSError * _Nullable error)
117+
{
118+
newSession = session;
119+
self->_error = error;
120+
dispatch_semaphore_signal(sema);
121+
}];
122+
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
123+
return newSession;
124+
}
125+
126+
127+
-(void)synchronousSetSessionProperties:(NSDictionary *)properties
128+
forSession:(PTDiffusionSession *)session
129+
usingControlSession:(PTDiffusionSession *)controlSession {
130+
131+
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
132+
[controlSession.clientControl setSessionProperties:properties
133+
forSession:session.sessionId
134+
completionHandler:^(PTDiffusionSetSessionPropertiesResult * _Nullable result, NSError * _Nullable error)
135+
{
136+
self->_error = error;
137+
dispatch_semaphore_signal(sema);
138+
}];
139+
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
140+
}
141+
142+
143+
-(void)onSessionStateChangeNotification:(NSNotification *const)notification {
144+
PTDiffusionSessionStateChange *const stateChange = notification.userInfo[PTDiffusionSessionStateChangeUserInfoKey];
145+
PTDiffusionSession *const session = (PTDiffusionSession *) notification.object;
146+
if (stateChange.state.isClosed && stateChange.state.error != nil) {
147+
NSLog(@"Session [%@] has been closed: [%@]", session.sessionId, stateChange.state.error);
148+
}
149+
}
150+
151+
@end
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Diffusion Client Library for iOS, tvOS and OS X / macOS - Examples
2+
//
3+
// Copyright (C) 2020 Push Technology Ltd.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#import "ClientControlGetSessionPropertiesExample.h"
17+
18+
@import Diffusion;
19+
20+
@implementation ClientControlGetSessionPropertiesExample {
21+
PTDiffusionSession* _normalSession;
22+
PTDiffusionSession* _controlSession;
23+
NSError *_error;
24+
}
25+
26+
-(void)startWithURL:(NSURL*)url {
27+
28+
/*
29+
* We'll run this example in a another thread other than main.
30+
* This allows to run operations in a synchronous way which is easier to read.
31+
*/
32+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
33+
34+
// Creating normal session
35+
self->_normalSession = [self synchronousOpenSessionWithURL:url principal:@"client" andPassword:@"password"];
36+
if (!self->_normalSession) {
37+
NSLog(@"Failed to open normal session: [%@]", self->_error);
38+
return;
39+
}
40+
NSLog(@"Created normal session [%@]", self->_normalSession.sessionId);
41+
42+
43+
// Creating control session
44+
self->_controlSession = [self synchronousOpenSessionWithURL:url principal:@"control" andPassword:@"password"];
45+
if (!self->_controlSession) {
46+
NSLog(@"Failed to open control session: [%@]", self->_error);
47+
return;
48+
}
49+
NSLog(@"Created control session [%@]", self->_controlSession.sessionId);
50+
51+
52+
// Requesting session properties of normal session
53+
NSArray *requestedSessionProperties = @[PTDiffusionSession.allUserProperties, PTDiffusionSession.allFixedProperties];
54+
[self->_controlSession.clientControl getSessionProperties:requestedSessionProperties
55+
forSession:self->_normalSession.sessionId
56+
completionHandler:^(PTDiffusionGetSessionPropertiesResult * _Nullable result, NSError * _Nullable error)
57+
{
58+
if (error != nil) {
59+
NSLog(@"An error has occurred while requesting the session properties: [%@]", error);
60+
return;
61+
}
62+
63+
NSLog(@"Returned session properties:");
64+
for (NSString *property in result.properties.allKeys)
65+
{
66+
NSLog(@" - %@: [%@]", property, result.properties[property]);
67+
}
68+
}];
69+
});
70+
}
71+
72+
73+
-(PTDiffusionSession *)synchronousOpenSessionWithURL:(NSURL *)url
74+
principal:(NSString *)principal
75+
andPassword:(NSString *)password {
76+
77+
PTDiffusionCredentials *const credentials = [[PTDiffusionCredentials alloc] initWithPassword:password];
78+
79+
PTDiffusionSessionConfiguration *const sessionConfiguration =
80+
[[PTDiffusionSessionConfiguration alloc] initWithPrincipal:principal
81+
credentials:credentials];
82+
83+
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
84+
85+
__block PTDiffusionSession *newSession;
86+
[PTDiffusionSession openWithURL:url
87+
configuration:sessionConfiguration
88+
completionHandler:^(PTDiffusionSession * _Nullable session, NSError * _Nullable error)
89+
{
90+
newSession = session;
91+
self->_error = error;
92+
dispatch_semaphore_signal(sema);
93+
}];
94+
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
95+
return newSession;
96+
}
97+
98+
99+
@end

0 commit comments

Comments
 (0)