Skip to content

Commit a46d335

Browse files
authored
feat: Add publisheronly role (#252)
* Bump dependencies * Bump version: v4.13.2 → v4.14.0 * Add publisheronly role
1 parent bbf3bb3 commit a46d335

File tree

6 files changed

+50
-29
lines changed

6 files changed

+50
-29
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[bumpversion]
22
commit = True
33
tag = False
4-
current_version = v4.13.2
4+
current_version = v4.14.0
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
66
serialize =
77
{major}.{minor}.{patch}-{release}{build}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ When you use Maven as your build tool, you can manage dependencies in the `pom.x
4545
<dependency>
4646
<groupId>com.tokbox</groupId>
4747
<artifactId>opentok-server-sdk</artifactId>
48-
<version>4.13.2</version>
48+
<version>4.14.0</version>
4949
</dependency>
5050
```
5151

@@ -55,7 +55,7 @@ When you use Gradle as your build tool, you can manage dependencies in the `buil
5555

5656
```groovy
5757
dependencies {
58-
compile group: 'com.tokbox', name: 'opentok-server-sdk', version: '4.13.2'
58+
compile group: 'com.tokbox', name: 'opentok-server-sdk', version: '4.14.0'
5959
}
6060
```
6161

build.gradle

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111

1212
group = 'com.tokbox'
1313
archivesBaseName = 'opentok-server-sdk'
14-
version = '4.13.2'
14+
version = '4.14.0'
1515
sourceCompatibility = "1.8"
1616
targetCompatibility = "1.8"
1717

@@ -23,18 +23,18 @@ repositories {
2323

2424
dependencies {
2525
testImplementation 'junit:junit:4.13.2'
26-
testImplementation 'com.github.tomakehurst:wiremock-jre8:2.35.1'
26+
testImplementation 'com.github.tomakehurst:wiremock-jre8:2.35.2'
2727
testImplementation 'commons-fileupload:commons-fileupload:1.5'
28-
testImplementation 'net.minidev:json-smart:2.4.11'
29-
testImplementation 'com.google.guava:guava:32.0.1-jre'
28+
testImplementation 'net.minidev:json-smart:2.5.1'
29+
testImplementation 'com.google.guava:guava:32.1.3-jre'
3030

3131
implementation 'commons-lang:commons-lang:2.6'
32-
implementation 'commons-codec:commons-codec:1.16.0'
33-
implementation 'io.netty:netty-codec-http:4.1.104.Final'
34-
implementation 'io.netty:netty-handler:4.1.104.Final'
32+
implementation 'commons-codec:commons-codec:1.16.1'
33+
implementation 'io.netty:netty-codec-http:4.1.109.Final'
34+
implementation 'io.netty:netty-handler:4.1.109.Final'
3535
implementation 'org.asynchttpclient:async-http-client:2.12.3'
36-
implementation 'com.fasterxml.jackson.core:jackson-databind:2.16.1'
37-
implementation 'org.bitbucket.b_c:jose4j:0.9.4'
36+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0'
37+
implementation 'org.bitbucket.b_c:jose4j:0.9.6'
3838
}
3939

4040
task sourcesJar(type: Jar) {

src/main/java/com/opentok/Role.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,38 @@
66
* Licensed under The MIT License (MIT). See LICENSE file for more information.
77
*/
88
package com.opentok;
9+
910
/**
1011
* Defines values for the role parameter of the {@link TokenOptions.Builder#role(Role role)} method.
1112
*/
1213
public enum Role {
1314
/**
14-
* A subscriber can only subscribe to streams.
15+
* A subscriber can only subscribe to streams.
1516
*/
1617
SUBSCRIBER,
18+
1719
/**
1820
* A publisher can publish streams, subscribe to streams, and signal. (This is the default
1921
* value if you do not set a role by calling the {@link TokenOptions.Builder#role(Role role)}
2022
* method.
2123
*/
2224
PUBLISHER,
25+
2326
/**
2427
* In addition to the privileges granted to a publisher, a moderator can perform
2528
* moderation functions, such as forcing clients to disconnect, to stop publishing streams,
2629
* or to mute audio in published streams. See the
2730
* <a href="https://tokbox.com/developer/guides/moderation/">Moderation developer guide</a>.
2831
*/
29-
MODERATOR;
32+
MODERATOR,
33+
34+
/**
35+
* Publish only privilege.
36+
*/
37+
PUBLISHER_ONLY;
3038

3139
@Override
3240
public String toString() {
33-
return super.toString().toLowerCase();
41+
return name().toLowerCase().replace("_", "");
3442
}
3543
}

src/main/java/com/opentok/constants/Version.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
package com.opentok.constants;
99

1010
public class Version {
11-
public static final String VERSION = "4.13.2";
11+
public static final String VERSION = "4.14.0";
1212
}

src/test/java/com/opentok/test/OpenTokTest.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -503,30 +503,43 @@ public void testTokenLayoutClass() throws
503503
}
504504

505505
@Test
506-
public void testTokenRoles() throws
507-
OpenTokException, UnsupportedEncodingException, NoSuchAlgorithmException,
508-
SignatureException, InvalidKeyException {
506+
public void testRoleStringValues() {
507+
for (Role role : Role.values()) {
508+
String roleStr = null;
509+
switch (role) {
510+
case MODERATOR: roleStr = "moderator"; break;
511+
case PUBLISHER: roleStr = "publisher"; break;
512+
case SUBSCRIBER: roleStr = "subscriber"; break;
513+
case PUBLISHER_ONLY: roleStr = "publisheronly"; break;
514+
}
515+
assertEquals(roleStr, role.toString());
516+
}
517+
}
518+
519+
@Test
520+
public void testTokenRoles() throws Exception {
509521

510522
int apiKey = 123456;
511523
String apiSecret = "1234567890abcdef1234567890abcdef1234567890";
512524
OpenTok opentok = new OpenTok(apiKey, apiSecret);
513525
String sessionId = "1_MX4xMjM0NTZ-flNhdCBNYXIgMTUgMTQ6NDI6MjMgUERUIDIwMTR-MC40OTAxMzAyNX4";
514-
Role role = Role.SUBSCRIBER;
515526

516-
String defaultToken = opentok.generateToken(sessionId);
517-
String roleToken = sdk.generateToken(sessionId, new TokenOptions.Builder()
518-
.role(role)
519-
.build());
527+
for (Role role : Role.values()) {
528+
String roleToken = sdk.generateToken(sessionId,
529+
new TokenOptions.Builder().role(role).build()
530+
);
531+
532+
assertNotNull(roleToken);
533+
assertTrue(Helpers.verifyTokenSignature(roleToken, apiSecret));
534+
Map<String, String> roleTokenData = Helpers.decodeToken(roleToken);
535+
assertEquals(role.toString(), roleTokenData.get("role"));
536+
}
520537

538+
String defaultToken = opentok.generateToken(sessionId);
521539
assertNotNull(defaultToken);
522-
assertNotNull(roleToken);
523540
assertTrue(Helpers.verifyTokenSignature(defaultToken, apiSecret));
524-
assertTrue(Helpers.verifyTokenSignature(roleToken, apiSecret));
525-
526541
Map<String, String> defaultTokenData = Helpers.decodeToken(defaultToken);
527542
assertEquals("publisher", defaultTokenData.get("role"));
528-
Map<String, String> roleTokenData = Helpers.decodeToken(roleToken);
529-
assertEquals(role.toString(), roleTokenData.get("role"));
530543
}
531544

532545
@Test

0 commit comments

Comments
 (0)