Skip to content

Commit

Permalink
feat: Add publisheronly role (#252)
Browse files Browse the repository at this point in the history
* Bump dependencies

* Bump version: v4.13.2 → v4.14.0

* Add publisheronly role
  • Loading branch information
SMadani authored Apr 18, 2024
1 parent bbf3bb3 commit a46d335
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[bumpversion]
commit = True
tag = False
current_version = v4.13.2
current_version = v4.14.0
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
serialize =
{major}.{minor}.{patch}-{release}{build}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ When you use Maven as your build tool, you can manage dependencies in the `pom.x
<dependency>
<groupId>com.tokbox</groupId>
<artifactId>opentok-server-sdk</artifactId>
<version>4.13.2</version>
<version>4.14.0</version>
</dependency>
```

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

```groovy
dependencies {
compile group: 'com.tokbox', name: 'opentok-server-sdk', version: '4.13.2'
compile group: 'com.tokbox', name: 'opentok-server-sdk', version: '4.14.0'
}
```

Expand Down
18 changes: 9 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {

group = 'com.tokbox'
archivesBaseName = 'opentok-server-sdk'
version = '4.13.2'
version = '4.14.0'
sourceCompatibility = "1.8"
targetCompatibility = "1.8"

Expand All @@ -23,18 +23,18 @@ repositories {

dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'com.github.tomakehurst:wiremock-jre8:2.35.1'
testImplementation 'com.github.tomakehurst:wiremock-jre8:2.35.2'
testImplementation 'commons-fileupload:commons-fileupload:1.5'
testImplementation 'net.minidev:json-smart:2.4.11'
testImplementation 'com.google.guava:guava:32.0.1-jre'
testImplementation 'net.minidev:json-smart:2.5.1'
testImplementation 'com.google.guava:guava:32.1.3-jre'

implementation 'commons-lang:commons-lang:2.6'
implementation 'commons-codec:commons-codec:1.16.0'
implementation 'io.netty:netty-codec-http:4.1.104.Final'
implementation 'io.netty:netty-handler:4.1.104.Final'
implementation 'commons-codec:commons-codec:1.16.1'
implementation 'io.netty:netty-codec-http:4.1.109.Final'
implementation 'io.netty:netty-handler:4.1.109.Final'
implementation 'org.asynchttpclient:async-http-client:2.12.3'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.16.1'
implementation 'org.bitbucket.b_c:jose4j:0.9.4'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0'
implementation 'org.bitbucket.b_c:jose4j:0.9.6'
}

task sourcesJar(type: Jar) {
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/opentok/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,38 @@
* Licensed under The MIT License (MIT). See LICENSE file for more information.
*/
package com.opentok;

/**
* Defines values for the role parameter of the {@link TokenOptions.Builder#role(Role role)} method.
*/
public enum Role {
/**
* A subscriber can only subscribe to streams.
* A subscriber can only subscribe to streams.
*/
SUBSCRIBER,

/**
* A publisher can publish streams, subscribe to streams, and signal. (This is the default
* value if you do not set a role by calling the {@link TokenOptions.Builder#role(Role role)}
* method.
*/
PUBLISHER,

/**
* In addition to the privileges granted to a publisher, a moderator can perform
* moderation functions, such as forcing clients to disconnect, to stop publishing streams,
* or to mute audio in published streams. See the
* <a href="https://tokbox.com/developer/guides/moderation/">Moderation developer guide</a>.
*/
MODERATOR;
MODERATOR,

/**
* Publish only privilege.
*/
PUBLISHER_ONLY;

@Override
public String toString() {
return super.toString().toLowerCase();
return name().toLowerCase().replace("_", "");
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/opentok/constants/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
package com.opentok.constants;

public class Version {
public static final String VERSION = "4.13.2";
public static final String VERSION = "4.14.0";
}
39 changes: 26 additions & 13 deletions src/test/java/com/opentok/test/OpenTokTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,30 +503,43 @@ public void testTokenLayoutClass() throws
}

@Test
public void testTokenRoles() throws
OpenTokException, UnsupportedEncodingException, NoSuchAlgorithmException,
SignatureException, InvalidKeyException {
public void testRoleStringValues() {
for (Role role : Role.values()) {
String roleStr = null;
switch (role) {
case MODERATOR: roleStr = "moderator"; break;
case PUBLISHER: roleStr = "publisher"; break;
case SUBSCRIBER: roleStr = "subscriber"; break;
case PUBLISHER_ONLY: roleStr = "publisheronly"; break;
}
assertEquals(roleStr, role.toString());
}
}

@Test
public void testTokenRoles() throws Exception {

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

String defaultToken = opentok.generateToken(sessionId);
String roleToken = sdk.generateToken(sessionId, new TokenOptions.Builder()
.role(role)
.build());
for (Role role : Role.values()) {
String roleToken = sdk.generateToken(sessionId,
new TokenOptions.Builder().role(role).build()
);

assertNotNull(roleToken);
assertTrue(Helpers.verifyTokenSignature(roleToken, apiSecret));
Map<String, String> roleTokenData = Helpers.decodeToken(roleToken);
assertEquals(role.toString(), roleTokenData.get("role"));
}

String defaultToken = opentok.generateToken(sessionId);
assertNotNull(defaultToken);
assertNotNull(roleToken);
assertTrue(Helpers.verifyTokenSignature(defaultToken, apiSecret));
assertTrue(Helpers.verifyTokenSignature(roleToken, apiSecret));

Map<String, String> defaultTokenData = Helpers.decodeToken(defaultToken);
assertEquals("publisher", defaultTokenData.get("role"));
Map<String, String> roleTokenData = Helpers.decodeToken(roleToken);
assertEquals(role.toString(), roleTokenData.get("role"));
}

@Test
Expand Down

0 comments on commit a46d335

Please sign in to comment.