From 0e0ca81046206740797439a0db678727d0f2a9ab Mon Sep 17 00:00:00 2001 From: Lucas Huang Date: Mon, 3 Jul 2017 15:16:02 -0700 Subject: [PATCH 1/8] Update CONTRIBUTING.md --- CONTRIBUTING.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0bde654f..7da34d99 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,6 @@ # Contributing Guidelines -For anyone looking to get involved to this project, we are glad to hear from you. Here are a few types of contributions -that we would be interested in hearing about. +If you're interested in contributing to this project, here are a few ways to do so: * Bug fixes - If you find a bug, please first report it using Github Issues. @@ -9,16 +8,15 @@ that we would be interested in hearing about. - If you'd like to submit a fix for a bug, send a Pull Request from your own fork and mention the Issue number. + Include a test that isolates the bug and verifies that it was fixed. * New Features - - If you'd like to accomplish something in the library that it doesn't already do, describe the problem in a new + - If you'd like to add a feature to the library that doesn't already exist, feel free to describe the feature in a new Github Issue. - Issues that have been identified as a feature request will be labelled `enhancement`. - If you'd like to implement the new feature, please wait for feedback from the project maintainers before spending too much time writing the code. In some cases, `enhancement`s may not align well with the project objectives at the time. * Tests, Documentation, Miscellaneous - - If you think the test coverage could be improved, the documentation could be clearer, you've got an alternative - implementation of something that may have more advantages, or any other change we would still be glad hear about - it. + - If you think the test coverage could be improved, the documentation could be clearer, or you have an alternative + implementation of something that may have more advantages, we would love to hear it. - If its a trivial change, go ahead and send a Pull Request with the changes you have in mind - If not, open a Github Issue to discuss the idea first. @@ -44,4 +42,4 @@ continue to add more commits to the branch you have sent the Pull Request from. ## Developer Guidelines -See DEVELOPING.md for guidelines for developing this project. \ No newline at end of file +See DEVELOPING.md for guidelines for developing this project. From 7ee3c882a973940dc1b3cea2eb9f2b2a299244e5 Mon Sep 17 00:00:00 2001 From: Aiham Hammami Date: Tue, 4 Jul 2017 14:45:34 +1000 Subject: [PATCH 2/8] Begin development on v2.5.0-Alpha1 --- OpenTok/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenTok/Properties/AssemblyInfo.cs b/OpenTok/Properties/AssemblyInfo.cs index 7d0fb0b9..6ce7a037 100644 --- a/OpenTok/Properties/AssemblyInfo.cs +++ b/OpenTok/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.4.*")] -[assembly: AssemblyInformationalVersion("2.4.3")] +[assembly: AssemblyVersion("2.5.*")] +[assembly: AssemblyInformationalVersion("2.5.0-Alpha1")] From 2a4bd9ccc1cc9ca35a890206feeb6a754642bf65 Mon Sep 17 00:00:00 2001 From: Aiham Hammami Date: Tue, 4 Jul 2017 14:49:57 +1000 Subject: [PATCH 3/8] Update DEVELOPING guide referencing dev branch --- DEVELOPING.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/DEVELOPING.md b/DEVELOPING.md index 68452897..7087b009 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -37,7 +37,7 @@ You can now either click the Run All command or use the keyboard shortcut (Ctrl+ In order to create a release, the following should be completed in order. 1. Build the solution using the Release confgiuration. Ensure all the tests are passing and that there is enough test coverage. -1. Make sure you are on the `master` branch of the repository, with all changes merged/commited already. +1. Make sure you are on the `dev` branch of the repository, with all changes merged/commited already. 1. Update the version number in the source code and the README. See [Versioning](#versioning) for information about selecting an appropriate version number. Files to change: - OpenTok\Properties\AssemblyInfo.cs (AssemblyInformationalVersion contains full semver, AssemblyVersion only @@ -53,7 +53,7 @@ In order to create a release, the following should be completed in order. 1. Change the version number for future development by incrementing the patch number and adding "-Alpha1" in each file except the README. Then stage the remaining files and commit with the message "Begin development on next version". -1. Push the changes to the source repository: `git push origin master; git push --tags origin` +1. Push the changes to the source repository: `git push origin dev; git push --tags origin` 1. Compress the contents of the `OpenTok\bin\Release\` directory, name it using the following template: `OpenTokSDK_x.y.z.zip` Upload the zip as an attached file in the latest GitHub Release. Add release notes with a description of changes and fixes. @@ -70,11 +70,12 @@ Using a "." in the prerelease tag is not allowed in the .NET platform. ### Branches -* `master` - the main development branch. +* `dev` - the main development branch. +* `master` - reflects the latest stable release. * `feat.foo` - feature branches. these are used for longer running tasks that cannot be accomplished in one commit. - once merged into master, these branches should be deleted. -* `vx.x.x` - if development for a future version/milestone has begun while master is working towards a sooner - release, this is the naming scheme for that branch. once merged into master, these branches should be deleted. + once merged into dev, these branches should be deleted. +* `vx.x.x` - if development for a future version/milestone has begun while dev is working towards a sooner + release, this is the naming scheme for that branch. once merged into dev, these branches should be deleted. ### Tags From b177ff29031b9bc68883e1e2d9ef1a5a50d55b49 Mon Sep 17 00:00:00 2001 From: Aiham Hammami Date: Thu, 10 Aug 2017 13:17:38 +1000 Subject: [PATCH 4/8] Refactor CurrentTime() out of GenerateJwt() in HttpClient --- OpenTok/Util/HttpClient.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/OpenTok/Util/HttpClient.cs b/OpenTok/Util/HttpClient.cs index ab956d0c..e3f18fce 100644 --- a/OpenTok/Util/HttpClient.cs +++ b/OpenTok/Util/HttpClient.cs @@ -28,6 +28,9 @@ public class HttpClient private int apiKey; private string apiSecret; private string server; + private readonly DateTime unixEpoch = new DateTime( + 1970, 1, 1, 0, 0, 0, DateTimeKind.Utc + ); public HttpClient() { @@ -183,21 +186,25 @@ private string ProcessParameters(Dictionary parameters) return data.Substring(0, data.Length - 1); } - private string GenerateJwt(int key, string secret, int expiryPeriod = 300) + private int CurrentTime() { IDateTimeProvider provider = new UtcDateTimeProvider(); var now = provider.GetNow(); - var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); int secondsSinceEpoch = (int) Math.Round((now - unixEpoch).TotalSeconds); + return secondsSinceEpoch; + } - int expiry = secondsSinceEpoch + expiryPeriod; + private string GenerateJwt(int key, string secret, int expiryPeriod = 300) + { + int now = CurrentTime(); + int expiry = now + expiryPeriod; var payload = new Dictionary { { "iss", Convert.ToString(key) }, { "ist", "project" }, - { "iat", secondsSinceEpoch }, + { "iat", now }, { "exp", expiry } }; From 71e6da1dfe3d6950feb73fd2c37d5280dcdc6d3f Mon Sep 17 00:00:00 2001 From: Aiham Hammami Date: Thu, 10 Aug 2017 13:18:23 +1000 Subject: [PATCH 5/8] Add Debug property to OpenTok class --- OpenTok/OpenTok.cs | 16 ++++++++++++++++ OpenTok/Util/HttpClient.cs | 1 + 2 files changed, 17 insertions(+) diff --git a/OpenTok/OpenTok.cs b/OpenTok/OpenTok.cs index ebaf3af3..d3d5b39e 100644 --- a/OpenTok/OpenTok.cs +++ b/OpenTok/OpenTok.cs @@ -30,6 +30,20 @@ public class OpenTok /** For internal use. */ public HttpClient Client { private get; set; } + /** + * Enables writing request/response details to console. + * Don't use in a production environment. + */ + private bool _debug; + public bool Debug { + get { return _debug; } + set + { + _debug = value; + Client.debug = _debug; + } + } + /** * Creates an OpenTok object. * @@ -44,6 +58,7 @@ public OpenTok(int apiKey, string apiSecret) this.ApiSecret = apiSecret; this.OpenTokServer = "https://api.opentok.com"; Client = new HttpClient(apiKey, apiSecret, this.OpenTokServer); + this.Debug = false; } /** @@ -55,6 +70,7 @@ public OpenTok(int apiKey, string apiSecret, string apiUrl) this.ApiSecret = apiSecret; this.OpenTokServer = apiUrl; Client = new HttpClient(apiKey, apiSecret, this.OpenTokServer); + this.Debug = false; } /** diff --git a/OpenTok/Util/HttpClient.cs b/OpenTok/Util/HttpClient.cs index e3f18fce..eea4efa6 100644 --- a/OpenTok/Util/HttpClient.cs +++ b/OpenTok/Util/HttpClient.cs @@ -28,6 +28,7 @@ public class HttpClient private int apiKey; private string apiSecret; private string server; + public bool debug = false; private readonly DateTime unixEpoch = new DateTime( 1970, 1, 1, 0, 0, 0, DateTimeKind.Utc ); From 69a7bee00bd92c4ae33f89609df22df34703abd8 Mon Sep 17 00:00:00 2001 From: Aiham Hammami Date: Thu, 10 Aug 2017 13:18:57 +1000 Subject: [PATCH 6/8] Add DebugLog and DebugLogHeaders methods to HttpClient --- OpenTok/Util/HttpClient.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/OpenTok/Util/HttpClient.cs b/OpenTok/Util/HttpClient.cs index eea4efa6..18995246 100644 --- a/OpenTok/Util/HttpClient.cs +++ b/OpenTok/Util/HttpClient.cs @@ -225,5 +225,29 @@ private string GenerateJwt(int key, string secret, int expiryPeriod = 300) { "X-TB-VERSION", "1" }, }; } + + private void DebugLog(string message) + { + if (this.debug) + { + var now = Convert.ToString(CurrentTime()); + Console.WriteLine("[{0}] {1}", now, message); + } + } + + private void DebugLogHeaders(WebHeaderCollection headers, string label) + { + if (this.debug) + { + for(int i = 0; i < headers.Count; ++i) + { + string header = headers.GetKey(i); + foreach(string value in headers.GetValues(i)) + { + DebugLog(label + " Header: " + header + " = " + value); + } + } + } + } } } From 75e946ee9ccad83591e78ee65f39860d05791d57 Mon Sep 17 00:00:00 2001 From: Aiham Hammami Date: Thu, 10 Aug 2017 13:19:17 +1000 Subject: [PATCH 7/8] Log request and response details to console when in debug mode --- OpenTok/Util/HttpClient.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/OpenTok/Util/HttpClient.cs b/OpenTok/Util/HttpClient.cs index 18995246..31fc5f2f 100644 --- a/OpenTok/Util/HttpClient.cs +++ b/OpenTok/Util/HttpClient.cs @@ -75,16 +75,26 @@ public virtual string Delete(string url, Dictionary headers, Dic string data = GetRequestPostData(bodyData, specificHeaders); var headers = GetRequestHeaders(specificHeaders); HttpWebRequest request = CreateRequest(url, headers, data); + + DebugLog("Request Method: " + request.Method); + DebugLog("Request URI: " + request.RequestUri); + DebugLogHeaders(request.Headers, "Request"); + HttpWebResponse response; try { if (!String.IsNullOrEmpty(data)) { + DebugLog("Request Body: " + data); SendData(request, data); } using (response = (HttpWebResponse) request.GetResponse()) { + DebugLog("Response Status Code: " + response.StatusCode); + DebugLog("Response Status Description: " + response.StatusDescription); + DebugLogHeaders(response.Headers, "Response"); + switch (response.StatusCode) { case HttpStatusCode.OK: @@ -102,6 +112,22 @@ public virtual string Delete(string url, Dictionary headers, Dic } catch (WebException e) { + DebugLog("WebException Status: " + e.Status + ", Message: " + e.Message); + + response = (HttpWebResponse)e.Response; + + DebugLog("Response Status Code: " + response.StatusCode); + DebugLog("Response Status Description: " + response.StatusDescription); + DebugLogHeaders(response.Headers, "Response"); + + if (this.debug) + { + using (var stream = new StreamReader(response.GetResponseStream())) + { + DebugLog("Response Body: " + stream.ReadToEnd()); + } + } + throw new OpenTokWebException("Error with request submission", e); } From 2375042a4c1a3c9c8dcdafae9969e83a4ba2ebb2 Mon Sep 17 00:00:00 2001 From: Aiham Hammami Date: Thu, 10 Aug 2017 14:11:21 +1000 Subject: [PATCH 8/8] Set version to 2.4.4 --- OpenTok/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenTok/Properties/AssemblyInfo.cs b/OpenTok/Properties/AssemblyInfo.cs index 6ce7a037..5f09235d 100644 --- a/OpenTok/Properties/AssemblyInfo.cs +++ b/OpenTok/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.5.*")] -[assembly: AssemblyInformationalVersion("2.5.0-Alpha1")] +[assembly: AssemblyVersion("2.4.*")] +[assembly: AssemblyInformationalVersion("2.4.4")]