opentok 2.4.0.beta.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +2 -1
- data/README.md +8 -11
- data/lib/opentok.rb +1 -1
- data/lib/opentok/archive.rb +2 -3
- data/lib/opentok/archives.rb +4 -2
- data/lib/opentok/client.rb +37 -12
- data/lib/opentok/constants.rb +1 -0
- data/lib/opentok/opentok.rb +1 -1
- data/lib/opentok/session.rb +1 -1
- data/lib/opentok/token_generator.rb +0 -9
- data/lib/opentok/version.rb +1 -1
- data/opentok.gemspec +3 -2
- data/sample/Archiving/public/js/host.js +18 -7
- data/sample/Archiving/public/js/participant.js +18 -7
- data/sample/Archiving/views/host.erb +1 -1
- data/sample/Archiving/views/participant.erb +1 -1
- data/sample/HelloWorld/public/js/helloworld.js +26 -6
- data/sample/HelloWorld/views/index.erb +1 -1
- data/spec/cassettes/OpenTok_Archives/should_create_archives.yml +3 -3
- data/spec/cassettes/OpenTok_Archives/should_create_audio_only_archives.yml +3 -3
- data/spec/cassettes/OpenTok_Archives/should_create_individual_archives.yml +3 -3
- data/spec/cassettes/OpenTok_Archives/should_create_named_archives.yml +3 -3
- data/spec/cassettes/OpenTok_Archives/should_delete_an_archive_by_id.yml +3 -3
- data/spec/cassettes/OpenTok_Archives/should_find_archives_by_id.yml +3 -3
- data/spec/cassettes/OpenTok_Archives/should_find_archives_with_unknown_properties.yml +3 -3
- data/spec/cassettes/OpenTok_Archives/should_find_expired_archives.yml +3 -3
- data/spec/cassettes/OpenTok_Archives/should_find_paused_archives_by_id.yml +3 -3
- data/spec/cassettes/OpenTok_Archives/should_stop_archives.yml +3 -3
- data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_all_archives.yml +3 -3
- data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_archives_with_an_offset.yml +4 -4
- data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_count_number_of_archives.yml +4 -4
- data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_part_of_the_archives_when_using_offset_and_count.yml +4 -4
- data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_session_archives.yml +71 -0
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions.yml +2 -2
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_default_sessions.yml +2 -2
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_relayed_media_sessions.yml +2 -2
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_relayed_media_sessions_for_invalid_media_modes.yml +2 -2
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_relayed_media_sessions_with_a_location_hint.yml +2 -2
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_routed_media_sessions.yml +2 -2
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_routed_media_sessions_with_a_location_hint.yml +2 -2
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_sessions_with_a_location_hint.yml +2 -2
- data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/with_an_addendum_to_the_user_agent_string/should_append_the_addendum_to_the_user_agent_header.yml +2 -2
- data/spec/matchers/token.rb +1 -2
- data/spec/opentok/archives_spec.rb +16 -0
- data/spec/opentok/opentok_spec.rb +5 -0
- data/spec/opentok/session_spec.rb +5 -0
- data/spec/shared/opentok_generates_tokens.rb +5 -25
- data/spec/shared/session_generates_tokens.rb +5 -0
- metadata +49 -84
- data/doc/OpenTok.html +0 -418
- data/doc/OpenTok/Archive.html +0 -1607
- data/doc/OpenTok/ArchiveList.html +0 -216
- data/doc/OpenTok/Archives.html +0 -1101
- data/doc/OpenTok/Client.html +0 -695
- data/doc/OpenTok/HashExtensions.html +0 -184
- data/doc/OpenTok/OpenTok.html +0 -1083
- data/doc/OpenTok/OpenTokArchiveError.html +0 -142
- data/doc/OpenTok/OpenTokAuthenticationError.html +0 -143
- data/doc/OpenTok/OpenTokError.html +0 -138
- data/doc/OpenTok/Session.html +0 -757
- data/doc/OpenTok/TokenGenerator.html +0 -204
- data/doc/OpenTok/TokenGenerator/ClassMethods.html +0 -187
- data/doc/README.md +0 -15
- data/doc/_index.html +0 -197
- data/doc/class_list.html +0 -58
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -57
- data/doc/css/style.css +0 -339
- data/doc/file.README.html +0 -87
- data/doc/file_list.html +0 -60
- data/doc/frames.html +0 -26
- data/doc/index.html +0 -87
- data/doc/js/app.js +0 -219
- data/doc/js/full_list.js +0 -181
- data/doc/js/jquery.js +0 -4
- data/doc/method_list.html +0 -261
- data/doc/top-level-namespace.html +0 -112
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 5a1348f9a120404e5fa6a5dd9710a7f7d44b2be8
|
|
4
|
+
data.tar.gz: 194a975415e454028ab738929df4462c5dd8213a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6870dd1f8e7dfb518fd1027f40605f1267c9d4aa740916aaf03828c87f1f019d90cc48389134a6b5a18cd3c1f5bcdd2c7a5c2fa1b010acd43b4a86a14f6192cc
|
|
7
|
+
data.tar.gz: b5f30aa15b3db675de70b97065ef8165830c89de6193af18dda0c99d3253f4e49e7025d14030c79d553eed26ea1b69d624532af07577a822d3a1e1e7a0356224
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
|
@@ -9,7 +9,8 @@ rvm:
|
|
|
9
9
|
- 2.0.0
|
|
10
10
|
- 2.1.0
|
|
11
11
|
- 2.2.0
|
|
12
|
-
-
|
|
12
|
+
- 2.3.0
|
|
13
|
+
- 2.4.0
|
|
13
14
|
notifications:
|
|
14
15
|
slack:
|
|
15
16
|
secure: agVll2R9PTPvJMcUgbvOh9eGt60zGDc8kPUwEsiQr828rCgXh/ZxD5irYDyKQg3ZsS8+f3MjFCwzU7uQALkia2pDrie9d8g8m1dt4Q5U7Qm6QecshvE0U9JwbB5Ngxaftbqyf0XEFrE7CKs7RI1BzFRpe8m+fdZgfwccX8Gb7pc=
|
data/README.md
CHANGED
|
@@ -17,7 +17,7 @@ Bundler helps manage dependencies for Ruby projects. Find more info here: <http:
|
|
|
17
17
|
Add this gem to your `Gemfile`:
|
|
18
18
|
|
|
19
19
|
```ruby
|
|
20
|
-
gem "opentok", "~> 2.4
|
|
20
|
+
gem "opentok", "~> 2.4"
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
Allow bundler to install the change.
|
|
@@ -29,7 +29,7 @@ $ bundle install
|
|
|
29
29
|
## RubyGems:
|
|
30
30
|
|
|
31
31
|
```
|
|
32
|
-
$ gem install opentok -v 2.4.0
|
|
32
|
+
$ gem install opentok -v 2.4.0
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
# Usage
|
|
@@ -75,10 +75,9 @@ session_id = session.session_id
|
|
|
75
75
|
|
|
76
76
|
Once a Session is created, you can start generating Tokens for clients to use when connecting to it.
|
|
77
77
|
You can generate a token either by calling the `opentok.generate_token(session_id, options)` method,
|
|
78
|
-
or by calling the `Session#generate_token(options)` method on the
|
|
78
|
+
or by calling the `Session#generate_token(options)` method on the instance after creating it. The
|
|
79
79
|
`options` parameter is an optional Hash used to set the role, expire time, and connection data of
|
|
80
|
-
the Token.
|
|
81
|
-
published from connections using this token can be set as well.
|
|
80
|
+
the Token.
|
|
82
81
|
|
|
83
82
|
```ruby
|
|
84
83
|
# Generate a Token from just a session_id (fetched from a database)
|
|
@@ -89,10 +88,9 @@ token = session.generate_token
|
|
|
89
88
|
|
|
90
89
|
# Set some options in a token
|
|
91
90
|
token = session.generate_token({
|
|
92
|
-
:role
|
|
93
|
-
:expire_time
|
|
94
|
-
:data
|
|
95
|
-
:initial_layout_classes => ['focus', 'inactive']
|
|
91
|
+
:role => :moderator,
|
|
92
|
+
:expire_time => Time.now.to_i+(7 * 24 * 60 * 60), # in one week
|
|
93
|
+
:data => 'name=Johnny'
|
|
96
94
|
});
|
|
97
95
|
```
|
|
98
96
|
|
|
@@ -188,8 +186,7 @@ repository and follow the Walkthroughs:
|
|
|
188
186
|
|
|
189
187
|
# Documentation
|
|
190
188
|
|
|
191
|
-
Reference documentation is available at <http://www.tokbox.com//opentok/libraries/server/ruby/reference/index.html
|
|
192
|
-
doc directory of the SDK.
|
|
189
|
+
Reference documentation is available at <http://www.tokbox.com//opentok/libraries/server/ruby/reference/index.html>.
|
|
193
190
|
|
|
194
191
|
# Requirements
|
|
195
192
|
|
data/lib/opentok.rb
CHANGED
data/lib/opentok/archive.rb
CHANGED
|
@@ -30,9 +30,8 @@ module OpenTok
|
|
|
30
30
|
# The API key associated with the archive.
|
|
31
31
|
#
|
|
32
32
|
# @attr [string] reason
|
|
33
|
-
# For archives with the status "stopped", this
|
|
34
|
-
#
|
|
35
|
-
# to "system failure".
|
|
33
|
+
# For archives with the status "stopped" or "failed", this string describes the
|
|
34
|
+
# reason the archive stopped (such as "maximum duration exceeded") or failed.
|
|
36
35
|
#
|
|
37
36
|
# @attr [string] session_id
|
|
38
37
|
# The session ID of the OpenTok session associated with this archive.
|
data/lib/opentok/archives.rb
CHANGED
|
@@ -96,11 +96,13 @@ module OpenTok
|
|
|
96
96
|
# the most recent archive. If you do not specify an offset, 0 is used.
|
|
97
97
|
# @option options [integer] :count Optional. The number of archives to be returned. The maximum
|
|
98
98
|
# number of archives returned is 1000.
|
|
99
|
+
# @option options [String] :session_id Optional. The session ID that archives belong to. This is
|
|
100
|
+
# useful when listing multiple archives for an {https://tokbox.com/developer/guides/archiving/#automatic-archives automatically archived session}
|
|
99
101
|
#
|
|
100
102
|
# @return [ArchiveList] An ArchiveList object, which is an array of Archive objects.
|
|
101
103
|
def all(options = {})
|
|
102
|
-
raise ArgumentError, "Limit is invalid" unless options[:count].nil? or (0..
|
|
103
|
-
archive_list_json = @client.list_archives(options[:offset], options[:count])
|
|
104
|
+
raise ArgumentError, "Limit is invalid" unless options[:count].nil? or (0..1000).include? options[:count]
|
|
105
|
+
archive_list_json = @client.list_archives(options[:offset], options[:count], options[:sessionId])
|
|
104
106
|
ArchiveList.new self, archive_list_json
|
|
105
107
|
end
|
|
106
108
|
|
data/lib/opentok/client.rb
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
require "opentok/constants"
|
|
1
2
|
require "opentok/exceptions"
|
|
2
3
|
require "opentok/extensions/hash"
|
|
3
4
|
|
|
4
5
|
require "active_support/inflector"
|
|
5
6
|
require "httparty"
|
|
7
|
+
require "jwt"
|
|
6
8
|
|
|
7
9
|
module OpenTok
|
|
8
10
|
# @private For internal use by the SDK.
|
|
@@ -17,15 +19,34 @@ module OpenTok
|
|
|
17
19
|
def initialize(api_key, api_secret, api_url, ua_addendum="")
|
|
18
20
|
self.class.base_uri api_url
|
|
19
21
|
self.class.headers({
|
|
20
|
-
"X-TB-PARTNER-AUTH" => "#{api_key}:#{api_secret}",
|
|
21
22
|
"User-Agent" => "OpenTok-Ruby-SDK/#{VERSION}" + (ua_addendum ? " #{ua_addendum}" : "")
|
|
22
23
|
})
|
|
23
24
|
@api_key = api_key
|
|
25
|
+
@api_secret = api_secret
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def generate_jwt(api_key, api_secret)
|
|
29
|
+
now = Time.now.to_i
|
|
30
|
+
payload = {
|
|
31
|
+
:iss => api_key,
|
|
32
|
+
:iat => now,
|
|
33
|
+
:exp => now + AUTH_EXPIRE
|
|
34
|
+
}
|
|
35
|
+
token = JWT.encode payload, api_secret, 'HS256', :ist => 'project'
|
|
36
|
+
token
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def generate_headers(extra_headers = {})
|
|
40
|
+
defaults = { "X-OPENTOK-AUTH" => generate_jwt(@api_key, @api_secret) }
|
|
41
|
+
defaults.merge extra_headers
|
|
24
42
|
end
|
|
25
43
|
|
|
26
44
|
def create_session(opts)
|
|
27
45
|
opts.extend(HashExtensions)
|
|
28
|
-
response = self.class.post("/session/create",
|
|
46
|
+
response = self.class.post("/session/create", {
|
|
47
|
+
:body => opts.camelize_keys!,
|
|
48
|
+
:headers => generate_headers
|
|
49
|
+
})
|
|
29
50
|
case response.code
|
|
30
51
|
when (200..300)
|
|
31
52
|
response
|
|
@@ -41,9 +62,9 @@ module OpenTok
|
|
|
41
62
|
def start_archive(session_id, opts)
|
|
42
63
|
opts.extend(HashExtensions)
|
|
43
64
|
body = { "sessionId" => session_id }.merge(opts.camelize_keys!)
|
|
44
|
-
response = self.class.post("/v2/
|
|
65
|
+
response = self.class.post("/v2/project/#{@api_key}/archive", {
|
|
45
66
|
:body => body.to_json,
|
|
46
|
-
:headers =>
|
|
67
|
+
:headers => generate_headers("Content-Type" => "application/json")
|
|
47
68
|
})
|
|
48
69
|
case response.code
|
|
49
70
|
when 200
|
|
@@ -64,7 +85,9 @@ module OpenTok
|
|
|
64
85
|
end
|
|
65
86
|
|
|
66
87
|
def get_archive(archive_id)
|
|
67
|
-
response = self.class.get("/v2/
|
|
88
|
+
response = self.class.get("/v2/project/#{@api_key}/archive/#{archive_id}", {
|
|
89
|
+
:headers => generate_headers
|
|
90
|
+
})
|
|
68
91
|
case response.code
|
|
69
92
|
when 200
|
|
70
93
|
response
|
|
@@ -79,12 +102,14 @@ module OpenTok
|
|
|
79
102
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
|
80
103
|
end
|
|
81
104
|
|
|
82
|
-
def list_archives(offset, count)
|
|
105
|
+
def list_archives(offset, count, sessionId)
|
|
83
106
|
query = Hash.new
|
|
84
107
|
query[:offset] = offset unless offset.nil?
|
|
85
108
|
query[:count] = count unless count.nil?
|
|
86
|
-
|
|
87
|
-
|
|
109
|
+
query[:sessionId] = sessionId unless sessionId.nil?
|
|
110
|
+
response = self.class.get("/v2/project/#{@api_key}/archive", {
|
|
111
|
+
:query => query.empty? ? nil : query,
|
|
112
|
+
:headers => generate_headers
|
|
88
113
|
})
|
|
89
114
|
case response.code
|
|
90
115
|
when 200
|
|
@@ -99,8 +124,8 @@ module OpenTok
|
|
|
99
124
|
end
|
|
100
125
|
|
|
101
126
|
def stop_archive(archive_id)
|
|
102
|
-
response = self.class.post("/v2/
|
|
103
|
-
:headers =>
|
|
127
|
+
response = self.class.post("/v2/project/#{@api_key}/archive/#{archive_id}/stop", {
|
|
128
|
+
:headers => generate_headers("Content-Type" => "application/json")
|
|
104
129
|
})
|
|
105
130
|
case response.code
|
|
106
131
|
when 200
|
|
@@ -121,8 +146,8 @@ module OpenTok
|
|
|
121
146
|
end
|
|
122
147
|
|
|
123
148
|
def delete_archive(archive_id)
|
|
124
|
-
response = self.class.delete("/v2/
|
|
125
|
-
:headers =>
|
|
149
|
+
response = self.class.delete("/v2/project/#{@api_key}/archive/#{archive_id}", {
|
|
150
|
+
:headers => generate_headers("Content-Type" => "application/json")
|
|
126
151
|
})
|
|
127
152
|
case response.code
|
|
128
153
|
when 204
|
data/lib/opentok/constants.rb
CHANGED
data/lib/opentok/opentok.rb
CHANGED
|
@@ -34,7 +34,7 @@ module OpenTok
|
|
|
34
34
|
# streams, and signal. (This is the default value if you do not specify a role.)
|
|
35
35
|
#
|
|
36
36
|
# * <code>:moderator</code> -- In addition to the privileges granted to a
|
|
37
|
-
# publisher, in clients using the OpenTok.js
|
|
37
|
+
# publisher, in clients using the OpenTok.js library, a moderator can call the
|
|
38
38
|
# <code>forceUnpublish()</code> and <code>forceDisconnect()</code> method of the
|
|
39
39
|
# Session object.
|
|
40
40
|
# @option options [integer] :expire_time The expiration time, in seconds since the UNIX epoch.
|
data/lib/opentok/session.rb
CHANGED
|
@@ -32,7 +32,7 @@ module OpenTok
|
|
|
32
32
|
# streams, and signal. (This is the default value if you do not specify a role.)
|
|
33
33
|
#
|
|
34
34
|
# * <code>:moderator</code> -- In addition to the privileges granted to a
|
|
35
|
-
# publisher, in clients using the OpenTok.js
|
|
35
|
+
# publisher, in clients using the OpenTok.js library, a moderator can call the
|
|
36
36
|
# <code>forceUnpublish()</code> and <code>forceDisconnect()</code> method of the
|
|
37
37
|
# Session object.
|
|
38
38
|
# @option options [integer] :expire_time The expiration time, in seconds since the UNIX epoch.
|
|
@@ -81,15 +81,6 @@ module OpenTok
|
|
|
81
81
|
end
|
|
82
82
|
data_params[:connection_data] = data
|
|
83
83
|
end
|
|
84
|
-
|
|
85
|
-
if opts[:initial_layout_classes]
|
|
86
|
-
if opts[:initial_layout_classes].is_a?(Array)
|
|
87
|
-
data_params[:initial_layout_class_list] = opts[:initial_layout_classes].join(' ')
|
|
88
|
-
else
|
|
89
|
-
data_params[:initial_layout_class_list] = opts[:initial_layout_classes].to_s
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
84
|
digest = OpenSSL::Digest.new('sha1')
|
|
94
85
|
data_string = Addressable::URI.form_encode data_params
|
|
95
86
|
meta_string = Addressable::URI.form_encode({
|
data/lib/opentok/version.rb
CHANGED
data/opentok.gemspec
CHANGED
|
@@ -19,13 +19,14 @@ Gem::Specification.new do |spec|
|
|
|
19
19
|
spec.add_development_dependency "bundler", "~> 1.5"
|
|
20
20
|
spec.add_development_dependency "rake", "~> 10.1.1"
|
|
21
21
|
spec.add_development_dependency "rspec", "~> 2.14.1"
|
|
22
|
-
spec.add_development_dependency "webmock", "~>
|
|
22
|
+
spec.add_development_dependency "webmock", "~> 2.3.2"
|
|
23
23
|
spec.add_development_dependency "vcr", "~> 2.8.0"
|
|
24
24
|
spec.add_development_dependency "yard", "~> 0.8.7"
|
|
25
25
|
# TODO: exclude this for compatibility with rbx
|
|
26
26
|
# spec.add_development_dependency "debugger", "~> 1.6.6"
|
|
27
27
|
|
|
28
28
|
spec.add_dependency "addressable", "~> 2.3" # 2.3.0 <= version < 3.0.0
|
|
29
|
-
spec.add_dependency "httparty", "~> 0.
|
|
29
|
+
spec.add_dependency "httparty", "~> 0.14.0"
|
|
30
30
|
spec.add_dependency "activesupport", ">= 2.0"
|
|
31
|
+
spec.add_dependency "jwt", "~> 1.5.6"
|
|
31
32
|
end
|
|
@@ -1,16 +1,27 @@
|
|
|
1
|
-
var session = OT.initSession(sessionId),
|
|
1
|
+
var session = OT.initSession(apiKey, sessionId),
|
|
2
2
|
publisher = OT.initPublisher('publisher'),
|
|
3
3
|
archiveID = null;
|
|
4
4
|
|
|
5
|
-
session.connect(
|
|
6
|
-
if(
|
|
7
|
-
|
|
5
|
+
session.connect(token, function(error, info) {
|
|
6
|
+
if (error) {
|
|
7
|
+
console.error('Failed to connect', error);
|
|
8
|
+
} else {
|
|
9
|
+
session.publish(publisher, function(error) {
|
|
10
|
+
if (error) {
|
|
11
|
+
console.error('Failed to publish', error);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
8
14
|
}
|
|
9
|
-
session.publish(publisher);
|
|
10
15
|
});
|
|
11
16
|
|
|
12
17
|
session.on('streamCreated', function(event) {
|
|
13
|
-
session.subscribe(event.stream, 'subscribers', {
|
|
18
|
+
session.subscribe(event.stream, 'subscribers', {
|
|
19
|
+
insertMode: 'append'
|
|
20
|
+
}, function(error) {
|
|
21
|
+
if (error) {
|
|
22
|
+
console.error('Failed to subscribe', error);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
14
25
|
});
|
|
15
26
|
|
|
16
27
|
session.on('archiveStarted', function(event) {
|
|
@@ -30,7 +41,7 @@ session.on('archiveStopped', function(event) {
|
|
|
30
41
|
});
|
|
31
42
|
|
|
32
43
|
$(document).ready(function() {
|
|
33
|
-
$('.start').click(function
|
|
44
|
+
$('.start').click(function(event) {
|
|
34
45
|
var options = $('.archive-options').serialize();
|
|
35
46
|
disableForm();
|
|
36
47
|
$.post('/start', options).fail(enableForm);
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
var session = OT.initSession(sessionId),
|
|
2
|
-
publisher = OT.initPublisher(
|
|
1
|
+
var session = OT.initSession(apiKey, sessionId),
|
|
2
|
+
publisher = OT.initPublisher('publisher');
|
|
3
3
|
|
|
4
|
-
session.connect(
|
|
5
|
-
if(
|
|
6
|
-
|
|
4
|
+
session.connect(token, function(error, info) {
|
|
5
|
+
if (error) {
|
|
6
|
+
console.error('Failed to connect', error);
|
|
7
|
+
} else {
|
|
8
|
+
session.publish(publisher, function(error) {
|
|
9
|
+
if (error) {
|
|
10
|
+
console.error('Failed to publish', error);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
7
13
|
}
|
|
8
|
-
session.publish(publisher);
|
|
9
14
|
});
|
|
10
15
|
|
|
11
16
|
session.on('streamCreated', function(event) {
|
|
12
|
-
session.subscribe(event.stream,
|
|
17
|
+
session.subscribe(event.stream, 'subscribers', {
|
|
18
|
+
insertMode : 'append'
|
|
19
|
+
}, function(error) {
|
|
20
|
+
if (error) {
|
|
21
|
+
console.error('Failed to subscribe', error);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
13
24
|
});
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
// Initialize an OpenTok Session object
|
|
2
|
-
var session =
|
|
2
|
+
var session = OT.initSession(apiKey, sessionId);
|
|
3
3
|
|
|
4
4
|
// Initialize a Publisher, and place it into the element with id="publisher"
|
|
5
|
-
var publisher =
|
|
5
|
+
var publisher = OT.initPublisher('publisher', {
|
|
6
|
+
insertMode: 'append',
|
|
7
|
+
width: '100%',
|
|
8
|
+
height: '100%'
|
|
9
|
+
}, function(error) {
|
|
10
|
+
if (error) {
|
|
11
|
+
console.error('Failed to initialise publisher', error);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
6
14
|
|
|
7
15
|
// Attach event handlers
|
|
8
16
|
session.on({
|
|
@@ -11,7 +19,11 @@ session.on({
|
|
|
11
19
|
sessionConnected: function(event) {
|
|
12
20
|
// Publish the publisher we initialzed earlier (this will trigger 'streamCreated' on other
|
|
13
21
|
// clients)
|
|
14
|
-
session.publish(publisher)
|
|
22
|
+
session.publish(publisher, function(error) {
|
|
23
|
+
if (error) {
|
|
24
|
+
console.error('Failed to publish', error);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
15
27
|
},
|
|
16
28
|
|
|
17
29
|
// This function runs when another client publishes a stream (eg. session.publish())
|
|
@@ -23,10 +35,18 @@ session.on({
|
|
|
23
35
|
document.getElementById('subscribers').appendChild(subContainer);
|
|
24
36
|
|
|
25
37
|
// Subscribe to the stream that caused this event, put it inside the container we just made
|
|
26
|
-
session.subscribe(event.stream, subContainer)
|
|
38
|
+
session.subscribe(event.stream, subContainer, function(error) {
|
|
39
|
+
if (error) {
|
|
40
|
+
console.error('Failed to subscribe', error);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
27
43
|
}
|
|
28
44
|
|
|
29
45
|
});
|
|
30
46
|
|
|
31
|
-
// Connect to the Session using
|
|
32
|
-
session.connect(
|
|
47
|
+
// Connect to the Session using a 'token'
|
|
48
|
+
session.connect(token, function(error) {
|
|
49
|
+
if (error) {
|
|
50
|
+
console.error('Failed to connect', error);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<title>OpenTok Hello World</title>
|
|
6
|
-
<script src="
|
|
6
|
+
<script src="https://static.opentok.com/v2/js/opentok.min.js"></script>
|
|
7
7
|
<script type="text/javascript">
|
|
8
8
|
var apiKey = '<%= api_key %>';
|
|
9
9
|
var sessionId = '<%= session_id %>';
|